From 7f63028be06605e4b13b862a010c2b7bbded348b Mon Sep 17 00:00:00 2001 From: Evenprime Date: Tue, 7 Feb 2012 16:25:45 +0100 Subject: [PATCH] Make "permlist" command faster, "reload" command limited by additional permission --- plugin.yml | 10 ++- pom.xml | 2 +- .../co/evenprime/bukkit/nocheat/NoCheat.java | 6 +- .../nocheat/command/CommandHandler.java | 76 ++++++++++--------- .../bukkit/nocheat/config/Permissions.java | 1 + 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/plugin.yml b/plugin.yml index 3042a4b1..b3981b80 100644 --- a/plugin.yml +++ b/plugin.yml @@ -13,9 +13,9 @@ commands: description: NoCheat command(s) permission: nocheat.admin.commands usage: | - / permlist player [permission] - to list the NoCheat relevant permissions of the player, optionally only those starting with [permission] - / reload - to reload NoCheats configuration file(s), without reloading the plugin itself - / playerinfo playername - show the collected data NoCheat collected about a player + / permlist player [permission]: list NoCheat permissions of player, optionally only if beginning with [permission] + / playerinfo player: show the collected data NoCheat collected about a player + / reload: fast reload of NoCheats configuration file(s) - needs additional permissions permissions: nocheat: @@ -27,7 +27,9 @@ permissions: nocheat.admin.chatlog: description: Player can see NoCheats log messages in the ingame chat nocheat.admin.commands: - description: allow use of the "nocheat" commands + description: allow use of the "nocheat" commands (may be given to players to allow them to check statistics) + nocheat.admin.reload: + description: allow access to the special "nocheat reload" command (only intended for the actual server administrator) nocheat.checks: description: Allow the player to bypass all checks children: diff --git a/pom.xml b/pom.xml index 9255f7ee..e2a3d0d2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cc.co.evenprime.bukkit NoCheat - 3.1.1 + 3.1.2 jar NoCheat diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index 111db31a..718e8043 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -41,6 +41,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask; public class NoCheat extends JavaPlugin implements Listener { private ConfigurationManager conf; + private CommandHandler commandHandler; private PlayerManager players; private List eventManagers; @@ -69,6 +70,8 @@ public class NoCheat extends JavaPlugin implements Listener { // Just to be sure nothing gets left out getServer().getScheduler().cancelTasks(this); + commandHandler = null; + System.out.println("[NoCheat] version [" + pdfFile.getVersion() + "] is disabled."); } @@ -77,6 +80,7 @@ public class NoCheat extends JavaPlugin implements Listener { // Then set up in memory per player data storage this.players = new PlayerManager(this); + this.commandHandler = new CommandHandler(this); // Then read the configuration files this.conf = new ConfigurationManager(this, this.getDataFolder()); @@ -128,7 +132,7 @@ public class NoCheat extends JavaPlugin implements Listener { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - boolean result = CommandHandler.handleCommand(this, sender, command, label, args); + boolean result = commandHandler.handleCommand(this, sender, command, label, args); return result; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java b/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java index b0e84bfd..e0cdadcd 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java +++ b/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java @@ -11,12 +11,40 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import cc.co.evenprime.bukkit.nocheat.NoCheat; +import cc.co.evenprime.bukkit.nocheat.config.Permissions; public class CommandHandler { - private CommandHandler() {} + private final List perms; + + public CommandHandler(NoCheat plugin) { + // Make a copy to allow sorting + perms = new LinkedList(plugin.getDescription().getPermissions()); - public static boolean handleCommand(NoCheat plugin, CommandSender sender, Command command, String label, String[] args) { + Collections.sort(perms, new Comparator() { + + public int compare(Permission o1, Permission o2) { + + String name1 = o1.getName(); + String name2 = o2.getName(); + + if(name1.equals(name2)) + return 0; + + if(name1.startsWith(name2)) { + return 1; + } + + if(name2.startsWith(name1)) { + return -1; + } + + return name1.compareTo(name2); + } + }); + } + + public boolean handleCommand(NoCheat plugin, CommandSender sender, Command command, String label, String[] args) { boolean result = false; // Not our command @@ -39,7 +67,7 @@ public class CommandHandler { return result; } - private static boolean handlePlayerInfoCommand(NoCheat plugin, CommandSender sender, String[] args) { + private boolean handlePlayerInfoCommand(NoCheat plugin, CommandSender sender, String[] args) { Map map = plugin.getPlayerData(args[1]); String filter = ""; @@ -57,7 +85,7 @@ public class CommandHandler { return true; } - private static boolean handlePermlistCommand(NoCheat plugin, CommandSender sender, String[] args) { + private boolean handlePermlistCommand(NoCheat plugin, CommandSender sender, String[] args) { // Get the player by name Player player = plugin.getServer().getPlayerExact(args[1]); @@ -72,32 +100,6 @@ public class CommandHandler { prefix = args[2]; } - // Make a copy to allow sorting - List perms = new LinkedList(plugin.getDescription().getPermissions()); - - Collections.sort(perms, new Comparator() { - - public int compare(Permission o1, Permission o2) { - - String name1 = o1.getName(); - String name2 = o2.getName(); - - if(name1.equals(name2)) - return 0; - - if(name1.startsWith(name2)) { - return 1; - } - - if(name2.startsWith(name1)) { - return -1; - } - - return name1.compareTo(name2); - } - - }); - sender.sendMessage("Player " + player.getName() + " has the permission(s):"); for(Permission permission : perms) { @@ -108,11 +110,17 @@ public class CommandHandler { return true; } - private static boolean handleReloadCommand(NoCheat plugin, CommandSender sender) { + private boolean handleReloadCommand(NoCheat plugin, CommandSender sender) { - sender.sendMessage("[NoCheat] Reloading configuration"); - plugin.reloadConfiguration(); - sender.sendMessage("[NoCheat] Configuration reloaded"); + // Players need a special permission for this + if(!(sender instanceof Player) || sender.hasPermission(Permissions.ADMIN_RELOAD)) { + sender.sendMessage("[NoCheat] Reloading configuration"); + plugin.reloadConfiguration(); + sender.sendMessage("[NoCheat] Configuration reloaded"); + } + else { + sender.sendMessage("You lack the "+Permissions.ADMIN_RELOAD+ " permission to use 'reload'"); + } return true; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java b/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java index e9851dd2..06a41556 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java @@ -39,6 +39,7 @@ public class Permissions { public final static String ADMIN_CHATLOG = ADMIN + ".chatlog"; public static final String ADMIN_COMMANDS = ADMIN + ".commands"; + public static final String ADMIN_RELOAD = ADMIN + ".reload"; public static final String INVENTORY = CHECKS + ".inventory"; public static final String INVENTORY_DROP = INVENTORY + ".drop";