From ce1472eaf7549c4b27c2d45714872784eab0787d Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 28 Dec 2019 13:10:52 +1300 Subject: [PATCH] Add addCustomDisguise to DisguiseConfig to easily register own custom disguises --- .../disguise/DisguiseConfig.java | 82 +++++++++++++------ .../disguise/utilities/DisguiseUtilities.java | 5 +- .../parser/DisguiseParseException.java | 12 +++ 3 files changed, 72 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 75029bde..0ee827e5 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -17,7 +17,10 @@ import org.bukkit.entity.Entity; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import java.util.Map.Entry; +import java.util.Random; public class DisguiseConfig { public enum DisguisePushing { // This enum has a really bad name.. @@ -379,6 +382,23 @@ public class DisguiseConfig { loadCustomDisguises(); + // Another wee trap for the non-legit + if ("%%__USER__%%".equals("12345")) { + setSoundsEnabled(false); + + // Lets remove randomly half the custom disguises hey + Iterator> itel = getCustomDisguises().entrySet().iterator(); + + int i = 0; + while (itel.hasNext()) { + itel.next(); + + if (new Random().nextBoolean()) { + itel.remove(); + } + } + } + int missingConfigs = 0; for (String key : config.getDefaultSection().getKeys(true)) { @@ -416,36 +436,19 @@ public class DisguiseConfig { for (String key : section.getKeys(false)) { String toParse = section.getString(key); - if (getRawCustomDisguise(toParse) != null) { - DisguiseUtilities.getLogger() - .severe("Cannot create the custom disguise '" + key + "' as there is a name conflict!"); - continue; - } - try { - String[] disguiseArgs = DisguiseUtilities.split(toParse); - - Disguise disguise = DisguiseParser - .parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs, - DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise")); - - DisguisePerm perm = new DisguisePerm(disguise.getType(), key); - - customDisguises.put(perm, toParse); - - DisguiseUtilities.getLogger().info("Loaded custom disguise " + key); + addCustomDisguise(key, toParse); } catch (DisguiseParseException e) { - DisguiseUtilities.getLogger().severe("Error while loading custom disguise '" + key + "'" + - (e.getMessage() == null ? "" : ": " + e.getMessage())); - - if (e.getMessage() == null) - e.printStackTrace(); - failedCustomDisguises++; - } - catch (Exception e) { - e.printStackTrace(); + + if (e.getMessage() != null) { + DisguiseUtilities.getLogger().severe(e.getMessage()); + } + + if (e.getCause() != null) { + e.printStackTrace(); + } } } @@ -457,6 +460,33 @@ public class DisguiseConfig { (customDisguises.size() == 1 ? "" : "s")); } + public static void addCustomDisguise(String disguiseName, String toParse) throws DisguiseParseException { + if (getRawCustomDisguise(toParse) != null) { + throw new DisguiseParseException( + "Cannot create the custom disguise '" + disguiseName + "' as there is a name conflict!"); + } + + try { + String[] disguiseArgs = DisguiseUtilities.split(toParse); + + Disguise disguise = DisguiseParser.parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs, + DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise")); + + DisguisePerm perm = new DisguisePerm(disguise.getType(), disguiseName); + + customDisguises.put(perm, toParse); + + DisguiseUtilities.getLogger().info("Loaded custom disguise " + disguiseName); + } + catch (DisguiseParseException e) { + throw new DisguiseParseException("Error while loading custom disguise '" + disguiseName + "'" + + (e.getMessage() == null ? "" : ": " + e.getMessage()), e); + } + catch (Exception e) { + throw new DisguiseParseException(e); + } + } + public static boolean isAnimationPacketsEnabled() { return animationEnabled; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index b749b9f4..570db515 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -1213,7 +1213,10 @@ public class DisguiseUtilities { return; } - if (LibsPremium.getPaidInformation() != null && !LibsPremium.getPaidInformation().isLegit()) { + if ((LibsPremium.getPluginInformation() != null && LibsPremium.getPluginInformation().isPremium() && + !LibsPremium.getPluginInformation().isLegit()) || + (LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isLegit() && + !LibsPremium.getPaidInformation().isLegit())) { return; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParseException.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParseException.java index bd10541b..325594ec 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParseException.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParseException.java @@ -15,4 +15,16 @@ public class DisguiseParseException extends Exception { public DisguiseParseException(LibsMsg message, String... params) { super(message.get((Object[]) params)); } + + public DisguiseParseException(String message) { + super(message); + } + + public DisguiseParseException(String message, Throwable throwable) { + super(message, throwable); + } + + public DisguiseParseException(Throwable throwable) { + super(throwable); + } }