From b42cf5cc43d46f55516f1bc144880c442b2e3272 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 5 Oct 2018 12:04:30 +1300 Subject: [PATCH] Cleaned up disguise permissions parsing and allowed negating parameters through negated permissions instead of "-" parameters. #307 --- .../disguise/DisguiseListener.java | 2 +- .../commands/DisguiseBaseCommand.java | 13 +- .../commands/DisguiseCloneCommand.java | 2 +- .../disguise/commands/DisguiseCommand.java | 2 +- .../commands/DisguiseEntityCommand.java | 2 +- .../commands/DisguiseHelpCommand.java | 2 +- .../commands/DisguiseModifyCommand.java | 2 +- .../commands/DisguiseModifyEntityCommand.java | 2 +- .../commands/DisguiseModifyPlayerCommand.java | 2 +- .../commands/DisguiseModifyRadiusCommand.java | 2 +- .../commands/DisguisePlayerCommand.java | 2 +- .../commands/DisguiseRadiusCommand.java | 2 +- .../utilities/parser/DisguiseParser.java | 315 +++++++----------- .../utilities/parser/DisguisePerm.java | 88 +++++ .../utilities/parser/ParamInfoManager.java | 2 +- 15 files changed, 230 insertions(+), 210 deletions(-) create mode 100644 src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePerm.java diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java index 131b3886..387ae3a1 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java @@ -18,7 +18,7 @@ import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.UpdateChecker; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index a63b3c43..a59e0596 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -1,19 +1,14 @@ package me.libraryaddict.disguise.commands; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; - +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; - -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; +import java.util.*; + /** * @author libraryaddict */ diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java index ba2e786f..bfe441eb 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsMsg; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java index d63f1a1b..5c8f4458 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -8,7 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index e7df516b..844052b8 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -7,7 +7,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index 9d05da45..f8cf9ccf 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java index f9b4ebb5..02e12ace 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java @@ -6,7 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java index 7a4855be..7a8b70da 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java @@ -4,7 +4,7 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java index 37613764..9d805937 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java @@ -5,7 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java index 2de53c70..1c59da89 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java @@ -7,7 +7,7 @@ import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index e4d727f9..c599cc97 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -8,7 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 22c53627..e9e1a885 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -10,7 +10,7 @@ import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java index 529112d1..3fc8bfd3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -6,99 +6,28 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import org.apache.commons.lang3.tuple.Pair; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; -import org.bukkit.entity.*; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; public class DisguiseParser { - public static class DisguisePerm { - private DisguiseType disguiseType; - private String permName; - - public DisguisePerm(DisguiseType disguiseType) { - this.disguiseType = disguiseType; - } - - public DisguisePerm(DisguiseType disguiseType, String disguisePerm) { - this.disguiseType = disguiseType; - permName = disguisePerm; - } - - public Class getEntityClass() { - return getType().getEntityClass(); - } - - public EntityType getEntityType() { - return getType().getEntityType(); - } - - public DisguiseType getType() { - return disguiseType; - } - - public Class getWatcherClass() { - return getType().getWatcherClass(); - } - - public boolean isMisc() { - return getType().isMisc(); - } - - public boolean isMob() { - return getType().isMob(); - } - - public boolean isPlayer() { - return getType().isPlayer(); - } - - public boolean isUnknown() { - return getType().isUnknown(); - } - - public String toReadable() { - return permName == null ? getType().toReadable() : permName; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((disguiseType == null) ? 0 : disguiseType.hashCode()); - result = prime * result + ((permName == null) ? 0 : permName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - - if (obj == null) - return false; - - if (!(obj instanceof DisguisePerm)) - return false; - - DisguisePerm other = (DisguisePerm) obj; - - if (disguiseType != other.disguiseType) - return false; - - return Objects.equals(permName, other.permName); - } - } - private static void doCheck(CommandSender sender, HashMap, Boolean> optionPermissions, ArrayList usedOptions) throws DisguiseParseException { @@ -172,9 +101,8 @@ public class DisguiseParser { return perms; } - private static HashMap, Boolean> getOptions(String perm) { + private static Pair, Boolean> getOptions(String perm, boolean permitted) { ArrayList list = new ArrayList<>(); - boolean isRemove = true; String[] split = perm.split("\\."); for (int i = 1; i < split.length; i++) { @@ -183,7 +111,7 @@ public class DisguiseParser { if (value) { option = option.substring(1); - isRemove = false; + permitted = false; } if (option.equals("baby")) { @@ -193,10 +121,7 @@ public class DisguiseParser { list.add(option); } - HashMap, Boolean> options = new HashMap<>(); - options.put(list, isRemove); - - return options; + return Pair.of(list, permitted); } /** @@ -224,129 +149,141 @@ public class DisguiseParser { perms.put(permissionNode + "*.*", true); } - for (String perm : perms.keySet()) { - if (perms.get(perm)) { - perm = perm.substring(permissionNode.length()); + // The first passthrough + // This sets what permissions they can use where a negated permission is refering to the parameters + for (Entry entry : perms.entrySet()) { + String perm = entry.getKey().substring(permissionNode.length()); + String[] split = perm.split("\\."); - String disguiseType = perm.split("\\.")[0]; - DisguisePerm dPerm = DisguiseParser.getDisguisePerm(disguiseType); + String disguiseType = split[0]; - if (dPerm != null) { - HashMap, Boolean> list; + // Permission was negated, wasn't refering to parameters + if (!entry.getValue() && split.length == 1) { + continue; + } - if (singleDisguises.containsKey(dPerm)) { - list = singleDisguises.get(dPerm); - } else { - list = new HashMap<>(); - singleDisguises.put(dPerm, list); + DisguisePerm dPerm = DisguiseParser.getDisguisePerm(disguiseType); + + if (dPerm != null) { + HashMap, Boolean> list; + + if (singleDisguises.containsKey(dPerm)) { + list = singleDisguises.get(dPerm); + } else { + list = new HashMap<>(); + singleDisguises.put(dPerm, list); + } + + Pair, Boolean> options = getOptions(perm, entry.getValue()); + + list.put(options.getKey(), options.getValue()); + } else { + for (DisguisePerm type : getDisguisePerms()) { + Pair, Boolean> options = null; + Class entityClass = type.getEntityClass(); + + if (disguiseType.equals("mob")) { + if (type.isMob()) { + options = getOptions(perm, entry.getValue()); + } + } else if (disguiseType.equals("animal") || disguiseType.equals("animals")) { + if (Animals.class.isAssignableFrom(entityClass)) { + options = getOptions(perm, entry.getValue()); + } + } else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) { + if (Monster.class.isAssignableFrom(entityClass)) { + options = getOptions(perm, entry.getValue()); + } + } else if (disguiseType.equals("misc")) { + if (type.isMisc()) { + options = getOptions(perm, entry.getValue()); + } + } else if (disguiseType.equals("ageable")) { + if (Ageable.class.isAssignableFrom(entityClass)) { + options = getOptions(perm, entry.getValue()); + } + } else if (disguiseType.equals("*")) { + options = getOptions(perm, entry.getValue()); } - HashMap, Boolean> map1 = getOptions(perm); - list.put(map1.keySet().iterator().next(), map1.values().iterator().next()); - } else { - for (DisguisePerm type : getDisguisePerms()) { - HashMap, Boolean> options = null; - Class entityClass = type.getEntityClass(); + if (options != null) { + HashMap, Boolean> list = rangeDisguises + .computeIfAbsent(type, k -> new HashMap<>()); - if (disguiseType.equals("mob")) { - if (type.isMob()) { - options = getOptions(perm); - } - } else if (disguiseType.equals("animal") || disguiseType.equals("animals")) { - if (Animals.class.isAssignableFrom(entityClass)) { - options = getOptions(perm); - } - } else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) { - if (Monster.class.isAssignableFrom(entityClass)) { - options = getOptions(perm); - } - } else if (disguiseType.equals("misc")) { - if (type.isMisc()) { - options = getOptions(perm); - } - } else if (disguiseType.equals("ageable")) { - if (Ageable.class.isAssignableFrom(entityClass)) { - options = getOptions(perm); - } - } else if (disguiseType.equals("*")) { - options = getOptions(perm); - } - - if (options != null) { - HashMap, Boolean> list; - - if (rangeDisguises.containsKey(type)) { - list = rangeDisguises.get(type); - } else { - list = new HashMap<>(); - rangeDisguises.put(type, list); - } - - HashMap, Boolean> map1 = getOptions(perm); - - list.put(map1.keySet().iterator().next(), map1.values().iterator().next()); - } + list.put(new ArrayList<>(options.getKey()), options.getValue()); } } } } + // Find disguises to negate, only removes does not add for (String perm : perms.keySet()) { - if (!perms.get(perm)) { - perm = perm.substring(permissionNode.length()); + // If not negated, continue + if (perms.get(perm)) { + continue; + } - String disguiseType = perm.split("\\.")[0]; - DisguisePerm dType = DisguiseParser.getDisguisePerm(disguiseType); + perm = perm.substring(permissionNode.length()); - if (dType != null) { - singleDisguises.remove(dType); - rangeDisguises.remove(dType); - } else { - for (DisguisePerm type : getDisguisePerms()) { - boolean foundHim = false; - Class entityClass = type.getEntityClass(); + String[] split = perm.split("\\."); - switch (disguiseType) { - case "mob": - if (type.isMob()) { - foundHim = true; - } + // Permission has parameters, which means the parameters were negated not the disguise + if (split.length > 1) { + continue; + } - break; - case "animal": - case "animals": - if (Animals.class.isAssignableFrom(entityClass)) { - foundHim = true; - } + String disguiseType = split[0]; - break; - case "monster": - case "monsters": - if (Monster.class.isAssignableFrom(entityClass)) { - foundHim = true; - } + DisguisePerm dType = DisguiseParser.getDisguisePerm(disguiseType); - break; - case "misc": - if (type.isMisc()) { - foundHim = true; - } + if (dType != null) { + singleDisguises.remove(dType); + rangeDisguises.remove(dType); + } else { + for (DisguisePerm type : getDisguisePerms()) { + boolean foundDisguiseType = false; + Class entityClass = type.getEntityClass(); - break; - case "ageable": - if (Ageable.class.isAssignableFrom(entityClass)) { - foundHim = true; - } + switch (disguiseType) { + case "mob": + if (type.isMob()) { + foundDisguiseType = true; + } - break; - case "*": - foundHim = true; - break; - } + break; + case "animal": + case "animals": + if (Animals.class.isAssignableFrom(entityClass)) { + foundDisguiseType = true; + } - if (foundHim) { - rangeDisguises.remove(type); - } + break; + case "monster": + case "monsters": + if (Monster.class.isAssignableFrom(entityClass)) { + foundDisguiseType = true; + } + + break; + case "misc": + if (type.isMisc()) { + foundDisguiseType = true; + } + + break; + case "ageable": + if (Ageable.class.isAssignableFrom(entityClass)) { + foundDisguiseType = true; + } + + break; + case "*": + foundDisguiseType = true; + break; + } + + if (foundDisguiseType) { + rangeDisguises.remove(type); } } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePerm.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePerm.java new file mode 100644 index 00000000..fa5d7585 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePerm.java @@ -0,0 +1,88 @@ +package me.libraryaddict.disguise.utilities.parser; + +import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import org.bukkit.entity.EntityType; + +import java.util.Objects; + +/** + * Created by libraryaddict on 5/10/2018. + */ +public class DisguisePerm { + private DisguiseType disguiseType; + private String permName; + + public DisguisePerm(DisguiseType disguiseType) { + this.disguiseType = disguiseType; + } + + public DisguisePerm(DisguiseType disguiseType, String disguisePerm) { + this.disguiseType = disguiseType; + permName = disguisePerm; + } + + public Class getEntityClass() { + return getType().getEntityClass(); + } + + public EntityType getEntityType() { + return getType().getEntityType(); + } + + public DisguiseType getType() { + return disguiseType; + } + + public Class getWatcherClass() { + return getType().getWatcherClass(); + } + + public boolean isMisc() { + return getType().isMisc(); + } + + public boolean isMob() { + return getType().isMob(); + } + + public boolean isPlayer() { + return getType().isPlayer(); + } + + public boolean isUnknown() { + return getType().isUnknown(); + } + + public String toReadable() { + return permName == null ? getType().toReadable() : permName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((disguiseType == null) ? 0 : disguiseType.hashCode()); + result = prime * result + ((permName == null) ? 0 : permName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + + if (obj == null) + return false; + + if (!(obj instanceof DisguisePerm)) + return false; + + DisguisePerm other = (DisguisePerm) obj; + + if (disguiseType != other.disguiseType) + return false; + + return Objects.equals(permName, other.permName); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/ParamInfoManager.java index 24effcac..061769b3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/ParamInfoManager.java @@ -4,7 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes; import org.bukkit.ChatColor;