From 3895ff029f9f6dd3fcfe97fe68cfc8646a143c88 Mon Sep 17 00:00:00 2001 From: Evenprime Date: Mon, 26 Sep 2011 20:07:59 +0200 Subject: [PATCH] Add command "/nocheat permlist" to display the effective permissions of a certain player. --- plugin.yml | 11 ++++- .../co/evenprime/bukkit/nocheat/NoCheat.java | 42 ++++++++++++++++++- .../evenprime/bukkit/nocheat/Permissions.java | 8 ++-- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/plugin.yml b/plugin.yml index 9569e8f4..04caffa0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,14 @@ name: NoCheat author: Evenprime main: cc.co.evenprime.bukkit.nocheat.NoCheat -version: 2.07a +version: 2.08 + +commands: + nocheat: + description: NoCheat command(s) + permission: nocheat.admin.permlist + usage: | + / permlist player [permission] to list the NoCheat relevant permissions of the player, optionally only those starting with [permission] permissions: nocheat: @@ -14,6 +21,8 @@ permissions: children: nocheat.admin.chatlog: description: Show log messages in the players chat + nocheat.admin.permlist: + description: allow use of the "nocheat permlist" command nocheat.checks: description: Allow the player to bypass all checks children: diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index 8272ada7..c2d91785 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -1,9 +1,15 @@ package cc.co.evenprime.bukkit.nocheat; +import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; @@ -71,9 +77,8 @@ public class NoCheat extends JavaPlugin { // First set up logging this.log = new LogManager(this); - log.logToConsole(LogLevel.LOW, "[NoCheat] This version is for CB #1185. It may break at any time and for any other version."); - + this.data = new DataManager(); this.action = new ActionManager(log); @@ -186,4 +191,37 @@ public class NoCheat extends JavaPlugin { } } } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if(command.getName().equalsIgnoreCase("nocheat") && args.length > 0) { + if(args[0].equalsIgnoreCase("permlist") && args.length >= 2) { + // permlist command was used CORRECTLY + // Get the player names + Player player = this.getServer().getPlayerExact(args[1]); + if(player == null) { + sender.sendMessage("Unknown player: " + args[1]); + return true; + } else { + String prefix = ""; + if(args.length == 3) { + prefix = args[2]; + } + // Make a copy to allow sorting + List perms = new LinkedList(this.getDescription().getPermissions()); + Collections.reverse(perms); + + sender.sendMessage("Player " + player.getName() + " has the permission(s):"); + for(Permission permission : perms) { + if(permission.getName().startsWith(prefix)) { + sender.sendMessage(permission.getName() + ": " + player.hasPermission(permission)); + } + } + return true; + } + } + } + return false; + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/Permissions.java b/src/cc/co/evenprime/bukkit/nocheat/Permissions.java index 6a29421b..2d279da8 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/Permissions.java +++ b/src/cc/co/evenprime/bukkit/nocheat/Permissions.java @@ -8,9 +8,9 @@ package cc.co.evenprime.bukkit.nocheat; */ public class Permissions { - private final static String NOCHEAT = "nocheat"; - private final static String ADMIN = NOCHEAT + ".admin"; - private final static String CHECKS = NOCHEAT + ".checks"; + private final static String NOCHEAT = "nocheat"; + private final static String ADMIN = NOCHEAT + ".admin"; + private final static String CHECKS = NOCHEAT + ".checks"; public final static String MOVE = CHECKS + ".moving"; public final static String MOVE_RUNFLY = MOVE + ".runfly"; @@ -34,7 +34,7 @@ public class Permissions { public final static String CHAT = CHECKS + ".chat"; public final static String CHAT_SPAM = CHAT + ".spam"; - + public final static String ADMIN_CHATLOG = ADMIN + ".chatlog"; private Permissions() {}