From a5d8c8ee39960f50a55fbf815a7c2256cb811428 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 20 Aug 2014 22:30:33 +1200 Subject: [PATCH] Support 'false' for disguise option permissions --- .../utilities/BaseDisguiseCommand.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index 2260387a..9f25a587 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -11,6 +11,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import me.libraryaddict.disguise.disguisetypes.MobDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandExecutor; @@ -38,7 +39,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { return getPermissions(sender, "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + "."); } - protected ArrayList getDisguisePermission(CommandSender sender, DisguiseType type) { + protected HashMap getDisguisePermission(CommandSender sender, DisguiseType type) { switch (type) { case PLAYER: case FALLING_BLOCK: @@ -46,7 +47,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { case SPLASH_POTION: case FISHING_HOOK: case DROPPED_ITEM: - ArrayList returns = new ArrayList(); + HashMap returns = new HashMap(); String beginning = "libsdisguises.options." + getClass().getSimpleName().toLowerCase().replace("command", "") + "."; for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String lowerPerm = permission.getPermission().toLowerCase(); @@ -55,7 +56,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { if (split.length > 1) { if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) { for (int i = 1; i < split.length; i++) { - returns.add(split[i]); + returns.put(split[i], permission.getValue()); } } } @@ -63,7 +64,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { } return returns; default: - return new ArrayList(); + return new HashMap(); } } @@ -310,13 +311,15 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { throw new Exception(ChatColor.RED + "You are forbidden to use this disguise."); } optionPermissions = map.get(disguiseType); - ArrayList disguiseOptions = this.getDisguisePermission(sender, disguiseType); + HashMap disguiseOptions = this.getDisguisePermission(sender, disguiseType); if (disguiseType.isPlayer()) {// If he is doing a player disguise if (args.length == 1) { // He needs to give the player name throw new Exception(ChatColor.RED + "Error! You need to give a player name!"); } else { - if (!disguiseOptions.isEmpty() && !disguiseOptions.contains(args[1].toLowerCase())) { + if (!disguiseOptions.isEmpty() + && (!disguiseOptions.containsKey(args[1].toLowerCase()) || !disguiseOptions + .get(args[1].toLowerCase()))) { throw new Exception(ChatColor.RED + "Error! You don't have permission to use that name!"); } // Construct the player disguise @@ -397,13 +400,13 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { if (!disguiseOptions.isEmpty() && miscId != -1) { String toCheck = "" + miscId; if (miscData == 0 || miscData == -1) { - if (!disguiseOptions.contains(toCheck)) { + if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { toCheck += ":0"; } } else { toCheck += ":" + miscData; } - if (!disguiseOptions.contains(toCheck)) { + if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { throw new Exception(ChatColor.RED + "Error! You do not have permission to use the parameter " + toCheck + " on the " + disguiseType.toReadable() + " disguise!"); }