From 2ff7b7ab3f9b8a46842fcc7840a1e4033f3a13bc Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 16 May 2019 18:07:53 +1200 Subject: [PATCH] Revert custom disguise api for MM compatibility --- .../libraryaddict/disguise/DisguiseAPI.java | 2 +- .../disguise/DisguiseConfig.java | 39 ++++++++++++++----- .../utilities/parser/DisguiseParser.java | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java index cee5d620..3787f88e 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java @@ -27,7 +27,7 @@ public class DisguiseAPI { private static int selfDisguiseId = ReflectionManager.getNewEntityId(true); public static String getCustomDisguise(String disguiseName) { - Map.Entry entry = DisguiseConfig.getCustomDisguise(disguiseName); + Map.Entry entry = DisguiseConfig.getRawCustomDisguise(disguiseName); if (entry == null) return null; diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index c3edf1ad..1eb6da06 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -130,29 +130,48 @@ public class DisguiseConfig { explicitDisguisePermissions = explictDisguisePermission; } - public static Entry getParsedCustomDisguise( - String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { - Entry entry = getCustomDisguise(disguise); + public static Entry getCustomDisguise(String disguise) { + Entry entry = getRawCustomDisguise(disguise); - return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(entry.getValue())); + if (entry == null) { + return null; + } + + try { + return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(entry.getValue())); + } + catch (IllegalAccessException | InvocationTargetException | DisguiseParseException e) { + DisguiseUtilities.getLogger().warning("Error when attempting to grab the custom disguise " + disguise); + e.printStackTrace(); + } + + return null; } - public static Entry getParsedCustomDisguise(Entity target, + public static Entry getCustomDisguise(Entity target, String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { - Entry entry = getCustomDisguise(disguise); + Entry entry = getRawCustomDisguise(disguise); + + if (entry == null) { + return null; + } return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(Bukkit.getConsoleSender(), target, entry.getValue())); } - public static Entry getParsedCustomDisguise(CommandSender invoker, Entity target, + public static Entry getCustomDisguise(CommandSender invoker, Entity target, String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { - Entry entry = getCustomDisguise(disguise); + Entry entry = getRawCustomDisguise(disguise); + + if (entry == null) { + return null; + } return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(invoker, target, entry.getValue())); } - public static Entry getCustomDisguise(String disguise) { + public static Entry getRawCustomDisguise(String disguise) { for (Entry entry : customDisguises.entrySet()) { String name = entry.getKey().toReadable(); @@ -383,7 +402,7 @@ public class DisguiseConfig { for (String key : section.getKeys(false)) { String toParse = section.getString(key); - if (getCustomDisguise(toParse) != null) { + if (getRawCustomDisguise(toParse) != null) { DisguiseUtilities.getLogger() .severe("Cannot create the custom disguise '" + key + "' as there is a name conflict!"); continue; 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 d79f1fae..cbc60664 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -336,7 +336,7 @@ public class DisguiseParser { } } else { disguisePerm = getDisguisePerm(args[0]); - Entry customDisguise = DisguiseConfig.getCustomDisguise(args[0]); + Entry customDisguise = DisguiseConfig.getRawCustomDisguise(args[0]); if (customDisguise != null) { args = DisguiseUtilities.split(customDisguise.getValue());