From 4ebf7bdf51985e11d7675aa95fdd0635bbfc93fb Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 18 Apr 2014 19:50:48 +1200 Subject: [PATCH] Read desc Added new permission system. This should allow people to use * better --- .../utilities/BaseDisguiseCommand.java | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index e5de12a4..b164c3a0 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -12,9 +12,13 @@ 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.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Monster; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.potion.PotionEffectType; @@ -27,27 +31,51 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { } protected ArrayList getAllowedDisguises(CommandSender sender, String permissionNode) { - ArrayList names = new ArrayList(); - ArrayList forbiddenDisguises = new ArrayList(); + HashSet singleAllowed = new HashSet(); + HashSet singleForbidden = new HashSet(); + HashSet globalForbidden = new HashSet(); + HashSet globalAllowed = new HashSet(); for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String perm = permission.getPermission().toLowerCase(); if (perm.startsWith(permissionNode)) { perm = perm.substring(permissionNode.length()); + String disguiseType = perm.split("\\.")[0]; + HashSet perms; for (DisguiseType type : DisguiseType.values()) { if (type.getEntityType() == null) { continue; } + Class entityClass = type.getEntityType().getEntityClass(); String name = type.name().toLowerCase(); - if (perm.split("\\.")[0].equals("*") && permission.getValue()) { - if (!names.contains(name)) - names.add(name); - } else if (perm.split("\\.")[0].equals(name)) { - if (permission.getValue()) { - if (!names.contains(name)) - names.add(name); - } else { - forbiddenDisguises.add(name); + if (!perm.equalsIgnoreCase(name)) { + perms = (permission.getValue() ? globalAllowed : globalForbidden); + } else { + perms = (permission.getValue() ? singleAllowed : singleForbidden); + } + if (perm.equals("mob")) { + if (type.isMob()) { + perms.add(name); } + } else if (perm.equals("animal") || perm.equals("animals")) { + if (Animals.class.isAssignableFrom(entityClass)) { + perms.add(name); + } + } else if (perm.equals("monster") || perm.equals("monsters")) { + if (Monster.class.isAssignableFrom(entityClass)) { + perms.add(name); + } + } else if (perm.equals("misc")) { + if (type.isMisc()) { + perms.add(name); + } + } else if (perm.equals("ageable")) { + if (Ageable.class.isAssignableFrom(entityClass)) { + perms.add(name); + } + } else if (disguiseType.equals("*")) { + perms.add(name); + } else if (disguiseType.equals(name)) { + perms.add(name); } } } @@ -57,16 +85,19 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { if (type.getEntityType() == null) { continue; } - if (!names.contains(type.name().toLowerCase())) { + if (!globalAllowed.contains(type.name().toLowerCase())) { if (sender.hasPermission(permissionNode + "*") || sender.hasPermission(permissionNode + type.name().toLowerCase())) { - names.add(type.name().toLowerCase()); + globalAllowed.add(type.name().toLowerCase()); } } } - names.removeAll(forbiddenDisguises); - Collections.sort(names, String.CASE_INSENSITIVE_ORDER); - return names; + globalAllowed.removeAll(globalForbidden); + globalAllowed.removeAll(singleForbidden); + singleAllowed.addAll(globalAllowed); + ArrayList disguiseTypes = new ArrayList(singleAllowed); + Collections.sort(disguiseTypes, String.CASE_INSENSITIVE_ORDER); + return disguiseTypes; } protected boolean isDouble(String string) {