当前位置: 首页>>代码示例>>Java>>正文


Java BanList.addBan方法代码示例

本文整理汇总了Java中org.bukkit.BanList.addBan方法的典型用法代码示例。如果您正苦于以下问题:Java BanList.addBan方法的具体用法?Java BanList.addBan怎么用?Java BanList.addBan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.BanList的用法示例。


在下文中一共展示了BanList.addBan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: commandUse

import org.bukkit.BanList; //导入方法依赖的package包/类
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (args.length == 0) {
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You must enter a player to ban.");
        return true;
    }
    UUID uuid = Utils.getID(args[0]);
    if (uuid == null) {
        uuid = Utils.getOfflineID(args[0]);
        if (uuid == null || !Bukkit.getOfflinePlayer(uuid).hasPlayedBefore()) {
            sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "That player does not exist or has not joined the server. If the player is offline, please use the full and most recent name.");
            return true;
        }
    }
    OfflinePlayer target = Bukkit.getOfflinePlayer(uuid);
    String name = Necessities.getConsole().getName().replaceAll(":", "");
    if (sender instanceof Player) {
        Player p = (Player) sender;
        if (target.getPlayer() != null && target.getPlayer().hasPermission("Necessities.antiBan")) {
            p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You may not ban someone who has Necessities.antiBan.");
            return true;
        }
        name = p.getName();
    }
    String reason = "";
    if (args.length > 1) {
        StringBuilder reasonBuilder = new StringBuilder();
        for (int i = 1; i < args.length; i++)
            reasonBuilder.append(args[i]).append(' ');
        reason = ChatColor.translateAlternateColorCodes('&', reasonBuilder.toString().trim());
    }
    BanList bans = Bukkit.getBanList(BanList.Type.NAME);
    String theirName = target.getName();
    if (target.getPlayer() != null)
        target.getPlayer().kickPlayer(reason);
    bans.addBan(theirName, reason, null, name);
    Bukkit.broadcastMessage(var.getMessages() + name + " banned " + var.getObj() + theirName + var.getMessages() + (reason.equals("") ? "." : " for " + var.getObj() + reason + var.getMessages() + '.'));
    return true;
}
 
开发者ID:pupnewfster,项目名称:Necessities,代码行数:40,代码来源:CmdBan.java

示例2: commandUse

import org.bukkit.BanList; //导入方法依赖的package包/类
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (args.length <= 1) {
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You must enter a player to ban and a duration in minutes.");
        return true;
    }
    UUID uuid = Utils.getID(args[0]);
    if (uuid == null) {
        uuid = Utils.getOfflineID(args[0]);
        if (uuid == null || !Bukkit.getOfflinePlayer(uuid).hasPlayedBefore()) {
            sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "That player does not exist or has not joined the server. If the player is offline, please use the full and most recent name.");
            return true;
        }
    }
    OfflinePlayer target = Bukkit.getOfflinePlayer(uuid);
    String name = Necessities.getConsole().getName().replaceAll(":", "");
    if (sender instanceof Player) {
        Player p = (Player) sender;
        if (target.getPlayer() != null && target.getPlayer().hasPermission("Necessities.antiBan")) {
            p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You may not ban someone who has Necessities.antiBan.");
            return true;
        }
        name = p.getName();
    }
    int minutes;
    try {
        minutes = Integer.parseInt(args[1]);
    } catch (Exception e) {
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Invalid time, please enter a time in minutes.");
        return true;
    }
    if (minutes < 0) {
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Invalid time, please enter a time in minutes.");
        return true;
    }
    if (minutes > 20160) {
        minutes = 20160;
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Maximum time is 20,160 minutes or 2 weeks. The time has been lowered to this number.");
    }
    String reason = "";
    if (args.length > 2) {
        StringBuilder reasonBuilder = new StringBuilder();
        for (int i = 2; i < args.length; i++)
            reasonBuilder.append(args[i]).append(' ');
        reason = ChatColor.translateAlternateColorCodes('&', reasonBuilder.toString().trim());
    }
    BanList bans = Bukkit.getBanList(BanList.Type.NAME);
    String theirName = target.getName();
    if (target.getPlayer() != null)
        target.getPlayer().kickPlayer(reason);
    Date date = new Date(System.currentTimeMillis() + minutes * 60 * 1000);
    bans.addBan(theirName, reason, date, name);
    Bukkit.broadcastMessage(var.getMessages() + name + " banned " + var.getObj() + theirName + var.getMessages() + " for " + var.getObj() + minutes + var.getMessages() + ' ' + plural(minutes) +
            (reason.equals("") ? "." : " for the reason " + var.getObj() + reason + var.getMessages() + '.'));
    return true;
}
 
开发者ID:pupnewfster,项目名称:Necessities,代码行数:57,代码来源:CmdTempban.java


注:本文中的org.bukkit.BanList.addBan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。