Search in sources :

Example 1 with BanList

use of cn.nukkit.permission.BanList in project Nukkit by Nukkit.

the class BanListCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    BanList list;
    boolean ips = false;
    if (args.length > 0) {
        switch(args[0].toLowerCase()) {
            case "ips":
                list = sender.getServer().getIPBans();
                ips = true;
                break;
            case "players":
                list = sender.getServer().getNameBans();
                break;
            default:
                sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
                return false;
        }
    } else {
        list = sender.getServer().getNameBans();
    }
    StringBuilder builder = new StringBuilder();
    Iterator<BanEntry> itr = list.getEntires().values().iterator();
    while (itr.hasNext()) {
        builder.append(itr.next().getName());
        if (itr.hasNext()) {
            builder.append(", ");
        }
    }
    if (ips) {
        sender.sendMessage(new TranslationContainer("commands.banlist.ips", String.valueOf(list.getEntires().size())));
    } else {
        sender.sendMessage(new TranslationContainer("commands.banlist.players", String.valueOf(list.getEntires().size())));
    }
    sender.sendMessage(builder.toString());
    return true;
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer) BanEntry(cn.nukkit.permission.BanEntry) BanList(cn.nukkit.permission.BanList)

Aggregations

TranslationContainer (cn.nukkit.lang.TranslationContainer)1 BanEntry (cn.nukkit.permission.BanEntry)1 BanList (cn.nukkit.permission.BanList)1