From 0f0b0b820fdff42094af7ea7888584cfc03a1f47 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 1 Dec 2016 06:56:11 +1300 Subject: [PATCH] Added ability to disable setInvisible on disguise commands --- config.yml | 3 ++ .../disguise/DisguiseConfig.java | 42 ++++++++++++------- .../commands/DisguiseBaseCommand.java | 22 ++-------- .../disguise/commands/DisguiseCommand.java | 2 +- .../commands/DisguiseEntityCommand.java | 2 +- .../commands/DisguisePlayerCommand.java | 2 +- .../commands/DisguiseRadiusCommand.java | 2 +- .../disguise/utilities/DisguiseParser.java | 29 ++++++++----- 8 files changed, 54 insertions(+), 50 deletions(-) diff --git a/config.yml b/config.yml index b3faa32f..5a624696 100644 --- a/config.yml +++ b/config.yml @@ -104,6 +104,9 @@ HideDisguisedPlayersFromTab: false # Always show player disguises in tab? The names will continue to appear in tab until the disguise is removed. ShowPlayerDisguisesInTab: false +# Don't like players able to set themselves invisible when using the disguise commands? Toggle this to true and no one can use setInvisible! Plugins can still use this however. +DisableInvisibility: false + # This will help performance, especially with CPU # Due to safety reasons, self disguises can never have their packets disabled. PacketsEnabled: diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index 3c6bab7c..1c9521e7 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -22,6 +22,8 @@ public class DisguiseConfig { private static boolean collectEnabled; private static boolean colorizeSheep; private static boolean colorizeWolf; + private static HashMap customDisguises = new HashMap(); + private static boolean disableInvisibility; private static String disguiseBlownMessage; private static int disguiseCloneExpire; private static int disguiseEntityExpire; @@ -54,7 +56,21 @@ public class DisguiseConfig { private static String updateNotificationPermission; private static boolean viewSelfDisguise; private static boolean witherSkullEnabled; - private static HashMap customDisguises = new HashMap(); + + public static Entry getCustomDisguise(String disguise) { + for (Entry entry : customDisguises.entrySet()) { + if (!entry.getKey().equalsIgnoreCase(disguise) && !entry.getKey().replaceAll("_", "").equalsIgnoreCase(disguise)) + continue; + + return entry; + } + + return null; + } + + public static HashMap getCustomDisguises() { + return customDisguises; + } public static String getDisguiseBlownMessage() { return disguiseBlownMessage; @@ -119,6 +135,7 @@ public class DisguiseConfig { setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true)); setHideDisguisedPlayers(config.getBoolean("HideDisguisedPlayersFromTab")); setShowDisguisedPlayersInTab(config.getBoolean("ShowPlayerDisguisesInTab")); + setDisabledInvisibility(config.getBoolean("DisableInvisibility")); customDisguises.clear(); @@ -168,21 +185,6 @@ public class DisguiseConfig { + (customDisguises.size() == 1 ? "" : "s")); } - public static HashMap getCustomDisguises() { - return customDisguises; - } - - public static Entry getCustomDisguise(String disguise) { - for (Entry entry : customDisguises.entrySet()) { - if (!entry.getKey().equalsIgnoreCase(disguise) && !entry.getKey().replaceAll("_", "").equalsIgnoreCase(disguise)) - continue; - - return entry; - } - - return null; - } - public static boolean isAnimationPacketsEnabled() { return animationEnabled; } @@ -195,6 +197,10 @@ public class DisguiseConfig { return collectEnabled; } + public static boolean isDisabledInvisibility() { + return disableInvisibility; + } + public static boolean isDisguiseBlownOnAttack() { return blowDisguisesOnAttack; } @@ -354,6 +360,10 @@ public class DisguiseConfig { } } + public static void setDisabledInvisibility(boolean disableInvis) { + disableInvisibility = disableInvis; + } + public static void setDisguiseBlownMessage(String newMessage) { disguiseBlownMessage = newMessage; } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 22d8b043..c37323a7 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -97,25 +97,9 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { } } - public boolean passesCheck(HashMap, Boolean> theirPermissions, ArrayList usedOptions) { - boolean hasPermission = false; - - for (ArrayList list : theirPermissions.keySet()) { - boolean myPerms = true; - - for (String option : usedOptions) { - if (!(theirPermissions.get(list) && list.contains("*")) - && (list.contains(option) != theirPermissions.get(list))) { - myPerms = false; - break; - } - } - - if (myPerms) { - hasPermission = true; - } - } - return hasPermission; + public boolean passesCheck(CommandSender sender, HashMap, Boolean> theirPermissions, + ArrayList usedOptions) { + return DisguiseParser.passesCheck(sender, theirPermissions, usedOptions); } protected abstract void sendCommandUsage(CommandSender sender, diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index e79167ee..998738dc 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -114,7 +114,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter } } - if (passesCheck(perms.get(disguiseType), usedOptions)) { + if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { boolean addMethods = true; if (args.length > 1) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index b70ffe74..d06d5267 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -98,7 +98,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom } } - if (passesCheck(perms.get(disguiseType), usedOptions)) { + if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { boolean addMethods = true; if (args.length > 1) { diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 7a288b7f..10718ee6 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -150,7 +150,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom } } - if (passesCheck(perms.get(disguiseType), usedOptions)) { + if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { boolean addMethods = true; if (args.length > 2) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 1f903d1c..95e195fc 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -261,7 +261,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } } - if (passesCheck(perms.get(disguiseType), usedOptions)) { + if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { boolean addMethods = true; if (args.length > 1 + starting) { diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index cb29af09..f4208033 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -148,12 +148,12 @@ public class DisguiseParser { return value; } - private static void doCheck(HashMap, Boolean> optionPermissions, ArrayList usedOptions) - throws DisguiseParseException { + private static void doCheck(CommandSender sender, HashMap, Boolean> optionPermissions, + ArrayList usedOptions) throws DisguiseParseException { - if (!passesCheck(optionPermissions, usedOptions)) { - throw new DisguiseParseException(ChatColor.RED + "You do not have the permission to use the option " - + usedOptions.get(usedOptions.size() - 1)); + if (!passesCheck(sender, optionPermissions, usedOptions)) { + throw new DisguiseParseException( + ChatColor.RED + "You do not have permission to use the option " + usedOptions.get(usedOptions.size() - 1)); } } @@ -569,7 +569,7 @@ public class DisguiseParser { if (args.length > 1) { if (args[1].equalsIgnoreCase("baby") || args[1].equalsIgnoreCase("adult")) { usedOptions.add("setbaby"); - doCheck(optionPermissions, usedOptions); + doCheck(sender, optionPermissions, usedOptions); adult = args[1].equalsIgnoreCase("adult"); toSkip++; @@ -668,17 +668,17 @@ public class DisguiseParser { if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK) { usedOptions.add("setblock"); - doCheck(optionPermissions, usedOptions); + doCheck(sender, optionPermissions, usedOptions); } else if (disguisePerm.getType() == DisguiseType.PAINTING) { usedOptions.add("setpainting"); - doCheck(optionPermissions, usedOptions); + doCheck(sender, optionPermissions, usedOptions); } else if (disguisePerm.getType() == DisguiseType.SPLASH_POTION) { usedOptions.add("setpotionid"); - doCheck(optionPermissions, usedOptions); + doCheck(sender, optionPermissions, usedOptions); } } // Construct the disguise @@ -961,7 +961,7 @@ public class DisguiseParser { usedOptions.add(methodName.toLowerCase()); } - doCheck(optionPermissions, usedOptions); + doCheck(sender, optionPermissions, usedOptions); if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) { methodToUse.invoke(disguise.getWatcher(), value); @@ -1020,13 +1020,19 @@ public class DisguiseParser { } } - private static boolean passesCheck(HashMap, Boolean> theirPermissions, ArrayList usedOptions) { + public static boolean passesCheck(CommandSender sender, HashMap, Boolean> theirPermissions, + ArrayList usedOptions) { boolean hasPermission = false; for (ArrayList list : theirPermissions.keySet()) { boolean myPerms = true; for (String option : usedOptions) { + if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase("setInvisible") + && DisguiseConfig.isDisabledInvisibility()) { + myPerms = false; + } + if (!(theirPermissions.get(list) && list.contains("*")) && (list.contains(option) != theirPermissions.get(list))) { myPerms = false; @@ -1038,6 +1044,7 @@ public class DisguiseParser { hasPermission = true; } } + return hasPermission; } }