Added ability to disable setInvisible on disguise commands

This commit is contained in:
libraryaddict 2016-12-01 06:56:11 +13:00
parent 24f88338c8
commit 0f0b0b820f
8 changed files with 54 additions and 50 deletions

View File

@ -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:

View File

@ -22,6 +22,8 @@ public class DisguiseConfig {
private static boolean collectEnabled;
private static boolean colorizeSheep;
private static boolean colorizeWolf;
private static HashMap<String, Disguise> customDisguises = new HashMap<String, Disguise>();
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<String, Disguise> customDisguises = new HashMap<String, Disguise>();
public static Entry<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> entry : customDisguises.entrySet()) {
if (!entry.getKey().equalsIgnoreCase(disguise) && !entry.getKey().replaceAll("_", "").equalsIgnoreCase(disguise))
continue;
return entry;
}
return null;
}
public static HashMap<String, Disguise> 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<String, Disguise> getCustomDisguises() {
return customDisguises;
}
public static Entry<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> 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;
}

View File

@ -97,25 +97,9 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
}
}
public boolean passesCheck(HashMap<ArrayList<String>, Boolean> theirPermissions, ArrayList<String> usedOptions) {
boolean hasPermission = false;
for (ArrayList<String> 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<ArrayList<String>, Boolean> theirPermissions,
ArrayList<String> usedOptions) {
return DisguiseParser.passesCheck(sender, theirPermissions, usedOptions);
}
protected abstract void sendCommandUsage(CommandSender sender,

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -148,12 +148,12 @@ public class DisguiseParser {
return value;
}
private static void doCheck(HashMap<ArrayList<String>, Boolean> optionPermissions, ArrayList<String> usedOptions)
throws DisguiseParseException {
private static void doCheck(CommandSender sender, HashMap<ArrayList<String>, Boolean> optionPermissions,
ArrayList<String> 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<ArrayList<String>, Boolean> theirPermissions, ArrayList<String> usedOptions) {
public static boolean passesCheck(CommandSender sender, HashMap<ArrayList<String>, Boolean> theirPermissions,
ArrayList<String> usedOptions) {
boolean hasPermission = false;
for (ArrayList<String> 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;
}
}