From 4fe484dc10acbb870535d5a242db7f4561ebd58b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 20 Jun 2017 06:11:08 +1200 Subject: [PATCH] Finish up --- .../libraryaddict/disguise/LibsDisguises.java | 5 +--- .../disguise/disguisetypes/DisguiseType.java | 2 +- .../disguise/utilities/DisguiseParser.java | 20 ++++---------- .../disguise/utilities/LibsMsg.java | 7 ++--- .../utilities/ReflectionFlagWatchers.java | 16 +++++++++--- .../disguise/utilities/TranslateFiller.java | 12 ++++++--- .../disguise/utilities/TranslateType.java | 26 ++++++++++--------- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index d156fa60..0e8720dd 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -4,8 +4,6 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.utilities.*; @@ -20,7 +18,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Tameable; import org.bukkit.entity.Zombie; -import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.reflect.FieldAccessException; @@ -81,7 +78,7 @@ public class LibsDisguises extends JavaPlugin { PacketsManager.addPacketListeners(); - TranslateType.MESSAGE.name(); // Call the static loader + TranslateType.MESSAGES.name(); // Call the static loader listener = new DisguiseListener(this); diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index b61214c1..bb6d613e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -322,6 +322,6 @@ public enum DisguiseType { split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); } - return TranslateType.DISGUISE.get(StringUtils.join(split, " "), "Name for the " + name() + " disguise"); + return TranslateType.DISGUISES.get(StringUtils.join(split, " "), "Name for the " + name() + " disguise"); } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index 011a8853..e4cf6d33 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -37,7 +37,7 @@ public class DisguiseParser { } public DisguiseParseException(LibsMsg message, String... params) { - super(message.get(params)); + super(message.get((Object[]) params)); } } @@ -255,10 +255,6 @@ public class DisguiseParser { /** * Get perms for the node. Returns a hashmap of allowed disguisetypes and their options - * - * @param sender - * @param permissionNode - * @return */ public static HashMap, Boolean>> getPermissions(CommandSender sender, String permissionNode) { @@ -455,13 +451,6 @@ public class DisguiseParser { * Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The * commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this point, the * disguise has been feed a proper disguisetype. - * - * @param sender - * @param args - * @param permissionMap - * @return - * @throws java.lang.IllegalAccessException - * @throws java.lang.reflect.InvocationTargetException */ public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args, HashMap, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException { @@ -675,8 +664,9 @@ public class DisguiseParser { Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass()); for (int i = 0; i < args.length; i += 2) { - String methodName = args[i]; - String valueString = (args.length - 1 == i ? null : args[i + 1]); + String methodName = TranslateType.DISGUISE_OPTIONS.reverseGet(args[i]); + String valueString = TranslateType.DISGUISE_OPTIONS_PARAMETERS + .reverseGet(args.length - 1 == i ? null : args[i + 1]); Method methodToUse = null; Object value = null; DisguiseParseException storedEx = null; @@ -945,7 +935,7 @@ public class DisguiseParser { try { itemId = Material.valueOf(split[0].toUpperCase()).getId(); } - catch (Exception ex) { + catch (Exception ignored) { } } diff --git a/src/me/libraryaddict/disguise/utilities/LibsMsg.java b/src/me/libraryaddict/disguise/utilities/LibsMsg.java index 3725a882..496d314c 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsMsg.java +++ b/src/me/libraryaddict/disguise/utilities/LibsMsg.java @@ -1,9 +1,6 @@ package me.libraryaddict.disguise.utilities; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.ArrayList; /** * Created by libraryaddict on 15/06/2017. @@ -164,9 +161,9 @@ public enum LibsMsg { public String get(Object... strings) { if (strings.length == 0) - return TranslateType.MESSAGE.get(getRaw()); + return TranslateType.MESSAGES.get(getRaw()); - return String.format(TranslateType.MESSAGE.get(getRaw()), (Object[]) strings); + return String.format(TranslateType.MESSAGES.get(getRaw()), (Object[]) strings); } public String toString() { diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java index 9921ea3b..4eab12de 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java @@ -44,8 +44,8 @@ public class ReflectionFlagWatchers { } private ParamInfo(String name, String description) { - this.name = TranslateType.METHOD_PARAM.get(name, null); - this.description = TranslateType.METHOD_PARAM.get(description, null); + this.name = name; + this.description = description; } public ParamInfo(String className, String name, String description) throws ClassNotFoundException { @@ -81,10 +81,20 @@ public class ReflectionFlagWatchers { } public String getName() { + return TranslateType.DISGUISE_OPTIONS_PARAMETERS + .get(getRawName(), "Used as a disguise option for " + getRawName()); + } + + public String getRawName() { return name; } public String getDescription() { + return TranslateType.DISGUISE_OPTIONS_PARAMETERS + .get(getRawDescription(), "Used as a disguise option for " + getRawDescription()); + } + + public String getRawDescription() { return description; } @@ -143,7 +153,7 @@ public class ReflectionFlagWatchers { new ParamInfo(Villager.Profession.class, "Villager Profession", "View all the professions you can set on a villager"); new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 4), "Direction", - "View the five directions usable on player setSleeping disguise"); + "View the four directions usable on player setSleeping disguise"); new ParamInfo(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into"); new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species"); diff --git a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java index 6cad9a74..9510a54a 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java @@ -21,8 +21,12 @@ public class TranslateFiller { if (info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class) continue; + TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(info.getRawName(), "Used as a disguise option"); + TranslateType.DISGUISE_OPTIONS_PARAMETERS + .save(info.getRawDescription(), "Description for the disguise option " + info.getRawName()); + for (String e : info.getEnums("")) { - TranslateType.METHOD_PARAM.save(e, "Used as a disguise option for " + info.getName()); + TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(e, "Used for the disguise option " + info.getRawName()); } } @@ -33,7 +37,7 @@ public class TranslateFiller { split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); } - TranslateType.DISGUISE.save(StringUtils.join(split, " "), "Name for the " + type.name() + " disguise"); + TranslateType.DISGUISES.save(StringUtils.join(split, " "), "Name for the " + type.name() + " disguise"); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) { Class para = method.getParameterTypes()[0]; @@ -50,14 +54,14 @@ public class TranslateFiller { else if (className.equals("IllagerWizard")) className = "Illager"; - TranslateType.METHOD.save(method.getName(), + TranslateType.DISGUISE_OPTIONS.save(method.getName(), "Found in the disguise options for " + className + " and uses " + (para.isArray() ? "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s")); } } for (LibsMsg msg : LibsMsg.values()) { - TranslateType.MESSAGE.save(msg.getRaw()); + TranslateType.MESSAGES.save(msg.getRaw()); } if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) { diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java index c4adbcbf..98ae0a05 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateType.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -3,13 +3,10 @@ package me.libraryaddict.disguise.utilities; import me.libraryaddict.disguise.DisguiseConfig; import org.apache.commons.lang3.StringEscapeUtils; import org.bukkit.ChatColor; -import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -18,10 +15,11 @@ import java.util.Objects; * Created by libraryaddict on 10/06/2017. */ public enum TranslateType { - DISGUISE("disguises"), - MESSAGE("messages"), - METHOD_PARAM("disguise_options"), - METHOD("disguise_option_parameters"); + DISGUISES("disguises"), + MESSAGES("messages"), + DISGUISE_OPTIONS("disguise_options"), + DISGUISE_OPTIONS_PARAMETERS("disguise_option_parameters"); + private File file; private HashMap translated = new HashMap<>(); @@ -63,7 +61,8 @@ public enum TranslateType { if (value == null) System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'"); else - translated.put(key, ChatColor.translateAlternateColorCodes('&', value)); + translated.put(ChatColor.translateAlternateColorCodes('&', key), + ChatColor.translateAlternateColorCodes('&', value)); } } catch (Exception e) { @@ -76,7 +75,7 @@ public enum TranslateType { } public void save(String msg) { - if (this != TranslateType.MESSAGE) + if (this != TranslateType.MESSAGES) throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); save(msg, null); @@ -103,7 +102,7 @@ public enum TranslateType { if (!exists) { writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n"); - if (this == TranslateType.MESSAGE) { + if (this == TranslateType.MESSAGES) { writer.write("# %s is where text is inserted, look up printf format codes if you're interested\n"); } } @@ -119,6 +118,9 @@ public enum TranslateType { } public String reverseGet(String translated) { + if (translated == null) + return null; + translated = translated.toLowerCase(); for (Map.Entry entry : this.translated.entrySet()) { @@ -132,14 +134,14 @@ public enum TranslateType { } public String get(String msg) { - if (this != TranslateType.MESSAGE) + if (this != TranslateType.MESSAGES) throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); return get(msg, null); } public String get(String msg, String comment) { - if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) + if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) return msg; String toReturn = translated.get(msg);