From 4b5714ea653bcb97cce69a10cd06bc28759452e6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 12 Jun 2017 09:36:54 +1200 Subject: [PATCH 1/7] Current progress --- .../libraryaddict/disguise/LibsDisguises.java | 10 +- .../commands/DisguiseBaseCommand.java | 29 +++--- .../disguise/commands/DisguiseCommand.java | 33 ++++--- .../disguise/disguisetypes/DisguiseType.java | 4 +- .../utilities/ReflectionFlagWatchers.java | 5 +- .../disguise/utilities/TranslateFiller.java | 34 +++++++ .../disguise/utilities/TranslateType.java | 94 +++++++++++++++++++ 7 files changed, 166 insertions(+), 43 deletions(-) create mode 100644 src/me/libraryaddict/disguise/utilities/TranslateFiller.java create mode 100644 src/me/libraryaddict/disguise/utilities/TranslateType.java diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 63d76bc4..b37ec682 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.Iterator; import me.libraryaddict.disguise.disguisetypes.watchers.*; +import me.libraryaddict.disguise.utilities.*; import org.bukkit.Bukkit; import org.bukkit.command.CommandExecutor; import org.bukkit.command.PluginCommand; @@ -45,13 +46,6 @@ import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.DisguiseSound; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.DisguiseValues; -import me.libraryaddict.disguise.utilities.FakeBoundingBox; -import me.libraryaddict.disguise.utilities.Metrics; -import me.libraryaddict.disguise.utilities.PacketsManager; -import me.libraryaddict.disguise.utilities.ReflectionManager; public class LibsDisguises extends JavaPlugin { private static LibsDisguises instance; @@ -87,6 +81,8 @@ public class LibsDisguises extends JavaPlugin { PacketsManager.addPacketListeners(); + TranslateFiller.fillConfigs(); + listener = new DisguiseListener(this); Bukkit.getPluginManager().registerEvents(listener, this); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 34029738..cb317e42 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -36,7 +36,8 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { return new ArrayList(new HashSet(list)); } - protected ArrayList getAllowedDisguises(HashMap, Boolean>> hashMap) { + protected ArrayList getAllowedDisguises( + HashMap, Boolean>> hashMap) { ArrayList allowedDisguises = new ArrayList<>(); for (DisguisePerm type : hashMap.keySet()) { @@ -52,7 +53,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { } protected String[] getArgs(String[] args) { - ArrayList newArgs = new ArrayList(); + ArrayList newArgs = new ArrayList<>(); for (int i = 0; i < args.length - 1; i++) { String s = args[i]; @@ -69,29 +70,21 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { public final String getPermNode() { if (this instanceof DisguiseCommand) { return "disguise"; - } - else if (this instanceof DisguiseEntityCommand) { + } else if (this instanceof DisguiseEntityCommand) { return "disguiseentity"; - } - else if (this instanceof DisguisePlayerCommand) { + } else if (this instanceof DisguisePlayerCommand) { return "disguiseplayer"; - } - else if (this instanceof DisguiseRadiusCommand) { + } else if (this instanceof DisguiseRadiusCommand) { return "disguiseradius"; - } - else if (this instanceof DisguiseModifyCommand) { + } else if (this instanceof DisguiseModifyCommand) { return "disguisemodify"; - } - else if (this instanceof DisguiseModifyEntityCommand) { + } else if (this instanceof DisguiseModifyEntityCommand) { return "disguisemodifyentity"; - } - else if (this instanceof DisguiseModifyPlayerCommand) { + } else if (this instanceof DisguiseModifyPlayerCommand) { return "disguisemodifyplayer"; - } - else if (this instanceof DisguiseModifyRadiusCommand) { + } else if (this instanceof DisguiseModifyRadiusCommand) { return "disguisemodifyradius"; - } - else { + } else { throw new UnsupportedOperationException("Unknown disguise command, perm node not found"); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index 9e9f44ed..797ae011 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -12,6 +12,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -30,7 +31,8 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Entity)) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); return true; } @@ -69,9 +71,11 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter DisguiseAPI.disguiseToAll((Player) sender, disguise); if (disguise.isDisguiseInUse()) { - sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable()); + sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Now disguised as a %s"), + disguise.getType().toReadable())); } else { - sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable()); + sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Failed to disguise as a %s"), + disguise.getType().toReadable())); } return true; @@ -79,15 +83,13 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); HashMap, Boolean>> perms = getPermissions(sender); if (args.length == 0) { - for (String type : getAllowedDisguises(perms)) { - tabs.add(type); - } + tabs.addAll(getAllowedDisguises(perms)); } else { DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]); @@ -100,7 +102,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter tabs.add(player.getName()); } } else { - ArrayList usedOptions = new ArrayList(); + ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) { @@ -160,18 +162,21 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join( - allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!")); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player "); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguise player " + "")); } - sender.sendMessage(ChatColor.DARK_GREEN + "/disguise "); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguise " + "")); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer "); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "/disguise " + " ")); } } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index a721c64c..b61214c1 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -1,9 +1,9 @@ package me.libraryaddict.disguise.disguisetypes; +import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.omg.CORBA.UNKNOWN; public enum DisguiseType { AREA_EFFECT_CLOUD(3, 0), @@ -322,6 +322,6 @@ public enum DisguiseType { split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); } - return StringUtils.join(split, " "); + return TranslateType.DISGUISE.get(StringUtils.join(split, " "), "Name for the " + name() + " disguise"); } } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java index 0406ca7b..0ff5dd54 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java @@ -51,8 +51,8 @@ public class ReflectionFlagWatchers { } private ParamInfo(String name, String description) { - this.name = name; - this.description = description; + this.name = TranslateType.METHOD_PARAM.get(name, null); + this.description = TranslateType.METHOD_PARAM.get(description, null); } public ParamInfo(String className, String name, String description) throws ClassNotFoundException { @@ -169,6 +169,7 @@ public class ReflectionFlagWatchers { potionEnums.add(toReadable(effectType.getName())); } + String[] materials = new String[Material.values().length]; for (int i = 0; i < Material.values().length; i++) { diff --git a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java new file mode 100644 index 00000000..d75191ee --- /dev/null +++ b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java @@ -0,0 +1,34 @@ +package me.libraryaddict.disguise.utilities; + +import me.libraryaddict.disguise.disguisetypes.DisguiseType; + +import java.lang.reflect.Method; + +/** + * Created by libraryaddict on 10/06/2017. + */ +public class TranslateFiller { + public static void fillConfigs() { + // Fill the configs + + for (ReflectionFlagWatchers.ParamInfo info : ReflectionFlagWatchers.getParamInfos()) { + if (!info.isEnums()) + continue; + + for (String e : info.getEnums("")) { + TranslateType.METHOD_PARAM.get(e, "Name for the param for " + info.getName()); + } + } + + for (DisguiseType type : DisguiseType.values()) { + type.toReadable(); + + for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) { + TranslateType.METHOD.get(method.getName(), + "Found in " + method.getDeclaringClass().getSimpleName().replace("Watcher", + "") + " and accepts as a parameter " + TranslateType.METHOD_PARAM.get( + method.getParameterTypes()[0].getSimpleName())); + } + } + } +} diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java new file mode 100644 index 00000000..a966bfbd --- /dev/null +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -0,0 +1,94 @@ +package me.libraryaddict.disguise.utilities; + +import org.apache.commons.lang3.StringEscapeUtils; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; +import java.util.Objects; + +/** + * Created by libraryaddict on 10/06/2017. + */ +public enum TranslateType { + DISGUISE("disguise_names"), MESSAGE("messages"), METHOD_PARAM("option_names"), METHOD("disguise_options"); + private File file; + private YamlConfiguration config; + + TranslateType(String fileName) { + file = new File("translate", fileName + ".yml"); + reload(); + } + + public void reload() { + if (!file.exists()) + file.getParentFile().mkdirs(); + + try { + file.createNewFile(); + } + catch (IOException e) { + e.printStackTrace(); + } + + config = YamlConfiguration.loadConfiguration(file); + } + + private YamlConfiguration getConfig() { + return config; + } + + private File getFile() { + return file; + } + + public void save(String message, String comment) { + message = StringEscapeUtils.escapeJson(message); + + if (getConfig().contains(message)) + return; + + try { + PrintWriter writer = new PrintWriter(getFile()); + writer.write((comment != null ? "# " + comment + "\n" : "") + message + ": " + message + "\n"); + + writer.close(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + + public String reverseGet(String translated) { + translated = StringEscapeUtils.unescapeJson(translated).toLowerCase(); + + for (Map.Entry entry : getConfig().getValues(false).entrySet()) { + if (!Objects.equals(entry.getValue().toString().toLowerCase(), translated)) + continue; + + return entry.getKey(); + } + + return translated; + } + + public String get(String message) { + if (this != TranslateType.MESSAGE) + throw new IllegalArgumentException("Can't set no comment for '" + message + "'"); + + return get(message, null); + } + + public String get(String message, String comment) { + String msg = getConfig().getString(StringEscapeUtils.escapeJson(message)); + + if (msg != null) + return msg; + + save(message, comment); + + return message; + } +} From cba8cb417c5c618513666e486ffd75a27e9ff684 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 19 Jun 2017 21:23:02 +1200 Subject: [PATCH 2/7] Current work --- config.yml | 3 + .../disguise/DisguiseConfig.java | 13 +++ .../libraryaddict/disguise/LibsDisguises.java | 2 +- .../commands/DisguiseCloneCommand.java | 74 +++++++------- .../commands/DisguiseEntityCommand.java | 72 +++++++------- .../commands/DisguiseHelpCommand.java | 88 +++++++++-------- .../commands/DisguiseModifyCommand.java | 64 ++++++------ .../commands/DisguiseModifyEntityCommand.java | 50 +++++----- .../commands/DisguiseModifyPlayerCommand.java | 77 ++++++++------- .../commands/DisguiseModifyRadiusCommand.java | 99 +++++++++++-------- .../commands/DisguisePlayerCommand.java | 95 +++++++++--------- .../commands/DisguiseRadiusCommand.java | 83 ++++++++-------- .../commands/DisguiseViewSelfCommand.java | 12 +-- .../commands/LibsDisguisesCommand.java | 39 ++++---- .../disguise/commands/UndisguiseCommand.java | 33 +++---- .../commands/UndisguiseEntityCommand.java | 28 +++--- .../commands/UndisguisePlayerCommand.java | 37 ++++--- .../commands/UndisguiseRadiusCommand.java | 27 ++--- .../disguise/utilities/DisguiseParser.java | 59 ++++++----- .../disguise/utilities/LibsMessages.java | 22 +++++ .../utilities/ReflectionFlagWatchers.java | 12 +-- .../disguise/utilities/TranslateFiller.java | 25 ++++- .../disguise/utilities/TranslateType.java | 93 ++++++++++++----- .../utilities/json/SerializerGameProfile.java | 1 - 24 files changed, 622 insertions(+), 486 deletions(-) create mode 100644 src/me/libraryaddict/disguise/utilities/LibsMessages.java diff --git a/config.yml b/config.yml index 3adfda0a..195d7e08 100644 --- a/config.yml +++ b/config.yml @@ -28,6 +28,9 @@ SaveDisguises: KeepDisguises: PlayerDeath: false +# Should the plugin use translations? Note that a player must see the message before it will appear in translations.yml +Translations: false + # How should the plugin handle self disguises scoreboards? # MODIFY_SCOREBOARD - Modifies the player's current team if possible, otherwise assigns them to a new scoreboard team # IGNORE_SCOREBOARD - Doesn't touch scoreboards at all, effectively means that if you didn't disable pushing in their scoreboard team; They will still be pushed around diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index d1b0a238..32d565dc 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map.Entry; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; @@ -60,6 +61,7 @@ public class DisguiseConfig { private static boolean updatePlayerCache; private static boolean savePlayerDisguises; private static boolean saveEntityDisguises; + private static boolean useTranslations; public static Entry getCustomDisguise(String disguise) { for (Entry entry : customDisguises.entrySet()) { @@ -77,6 +79,16 @@ public class DisguiseConfig { return savePlayerDisguises; } + public static boolean isUseTranslations() { + return useTranslations; + } + + public static void setUseTranslations(boolean setUseTranslations) { + useTranslations = setUseTranslations; + + TranslateType.reloadTranslations(); + } + public static boolean isSaveEntityDisguises() { return saveEntityDisguises; } @@ -180,6 +192,7 @@ public class DisguiseConfig { setUpdateGameProfiles(config.getBoolean("UpdateGameProfiles")); setSavePlayerDisguises(config.getBoolean("SaveDisguises.Players")); setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities")); + setUseTranslations(config.getBoolean("Translations")); try { String option = config.getString("SelfDisguisesScoreboard", diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index b37ec682..5d44e530 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -81,7 +81,7 @@ public class LibsDisguises extends JavaPlugin { PacketsManager.addPacketListeners(); - TranslateFiller.fillConfigs(); + TranslateType.MESSAGE.name(); // Call the static loader listener = new DisguiseListener(this); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java index dd91f4b0..29d57f3f 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java @@ -1,9 +1,10 @@ package me.libraryaddict.disguise.commands; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -12,16 +13,16 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import me.libraryaddict.disguise.DisguiseConfig; -import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); return true; } @@ -37,43 +38,37 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp for (int i = player == null ? 0 : 1; i < args.length; i++) { String option = args[i]; - if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") - || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { + if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils.startsWithIgnoreCase(option, + "ignoreEnquip")) { doEquipment = false; - } - else if (option.equalsIgnoreCase("doSneakSprint")) { + } else if (option.equalsIgnoreCase("doSneakSprint")) { doSneak = true; doSprint = true; - } - else if (option.equalsIgnoreCase("doSneak")) { + } else if (option.equalsIgnoreCase("doSneak")) { doSneak = true; - } - else if (option.equalsIgnoreCase("doSprint")) { + } else if (option.equalsIgnoreCase("doSprint")) { doSprint = true; - } - else { - sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option - + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); + } else { + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.DARK_RED + "Unknown " + "option '%s" + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"), + option)); return true; } } - Boolean[] options = new Boolean[] { - doEquipment, doSneak, doSprint - }; + Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint}; if (player != null) { DisguiseUtilities.createClonedDisguise((Player) sender, player, options); - } - else { + } else { LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options); - sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire() - + " seconds to grab the disguise reference!"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Right click a entity in the next %s" + " seconds to grab the disguise reference!"), + DisguiseConfig.getDisguiseCloneExpire())); } - } - else { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); } return true; @@ -81,7 +76,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); @@ -103,12 +98,13 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { - sender.sendMessage(ChatColor.DARK_GREEN - + "Right click a entity to get a disguise reference you can pass to other disguise commands!"); - sender.sendMessage(ChatColor.DARK_GREEN - + "Security note: Any references you create will be available to all players able to use disguise references."); - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN - + "Optional" + ChatColor.DARK_GREEN + ")"); + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other " + "disguise commands!")); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players " + "able to use disguise references.")); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")")); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index bb680192..aa0a1992 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -1,19 +1,5 @@ package me.libraryaddict.disguise.commands; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.Disguise; @@ -23,17 +9,32 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); return true; } if (getPermissions(sender).isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -61,14 +62,14 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise); - sender.sendMessage(ChatColor.RED + "Right click an entity in the next " + DisguiseConfig.getDisguiseEntityExpire() - + " seconds to disguise it as a " + disguise.getType().toReadable() + "!"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "Right click an entity in the next " + DisguiseConfig.getDisguiseEntityExpire() + " " + "seconds to disguise it as a " + disguise.getType().toReadable() + "!")); return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); if (!(sender instanceof Player)) { return tabs; @@ -82,8 +83,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom for (String type : getAllowedDisguises(perms)) { tabs.add(type); } - } - else { + } else { DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]); if (disguiseType == null) @@ -93,9 +93,8 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); } - } - else { - ArrayList usedOptions = new ArrayList(); + } else { + ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) { @@ -124,8 +123,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.add(e); } - } - else { + } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); @@ -137,7 +135,8 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( + disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -155,22 +154,25 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom * @param map */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN - + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!")); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player "); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguiseentity player ")); } - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity "); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguiseentity ")); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity "); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "/disguiseentity " + "")); } } - } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index 8f56c578..111d5958 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -1,31 +1,29 @@ package me.libraryaddict.disguise.commands; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; - import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - for (String node : new String[] { - "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" - }) { + for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) { HashMap, Boolean>> permMap = DisguiseParser.getPermissions(sender, "libsdisguises." + node + "."); @@ -33,8 +31,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl if (args.length == 0) { sendCommandUsage(sender, null); return true; - } - else { + } else { ParamInfo help = null; for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { @@ -47,20 +44,28 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl } if (help != null) { - sender.sendMessage(ChatColor.RED + help.getName() + ": " + ChatColor.GREEN - + StringUtils.join(help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN)); + if (help.isEnums()) { + sender.sendMessage( + ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + StringUtils.join( + help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN)); + } else { + sender.sendMessage( + ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + help.getDescription()); + } return true; } DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]); if (type == null) { - sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the disguise ") + args[0]); return true; } if (!permMap.containsKey(type)) { - sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You do not have permission for " + "that disguise!")); return true; } @@ -80,8 +85,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl allowed = true; break; } - } - else if (!key.contains(method.getName().toLowerCase())) { + } else if (!key.contains(method.getName().toLowerCase())) { allowed = true; break; } @@ -105,13 +109,12 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl if (declaring == LivingWatcher.class) { methodColor = ChatColor.AQUA; - } - else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) { + } else if (!(FlagWatcher.class.isAssignableFrom( + declaring)) || declaring == FlagWatcher.class) { methodColor = ChatColor.GRAY; } - String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() - + ChatColor.DARK_RED + ")"; + String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")"; map.put(str, methodColor); methods.add(str); @@ -131,12 +134,13 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl methods.add(ChatColor.RED + "No options with permission to use"); } - sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: " - + StringUtils.join(methods, ChatColor.DARK_RED + ", ")); + sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + TranslateType.MESSAGE.get( + " options: ") + StringUtils.join(methods, ChatColor.DARK_RED + ", ")); if (ignored > 0) { - sender.sendMessage(ChatColor.RED + "Ignored " + ignored - + " options you do not have permission to use. Add 'show' to view unusable options."); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Ignored %s" + " options you do not have permission to use. Add " + "'show' to view unusable options."), + ignored)); } return true; @@ -144,18 +148,16 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl } } - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); - for (String node : new String[] { - "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" - }) { + for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) { HashMap, Boolean>> perms = DisguiseParser.getPermissions(sender, "libsdisguises." + node + "."); @@ -170,8 +172,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { tabs.add(s.getName().replaceAll(" ", "")); } - } - else if (DisguiseParser.getDisguisePerm(args[0]) == null) { + } else if (DisguiseParser.getDisguisePerm(args[0]) == null) { tabs.add("Show"); } } @@ -183,13 +184,14 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { - sender.sendMessage(ChatColor.RED + "/disguisehelp " + ChatColor.GREEN - + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"); + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "/disguisehelp " + ChatColor.GREEN + "- View the options you can set " + "on a disguise. Add 'show' to reveal the options you don't have permission to use")); for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { - sender.sendMessage(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ", "") + ChatColor.GREEN + " - " - + s.getDescription()); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ", + "") + ChatColor.GREEN + " - " + s.getDescription())); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java index 577f74f0..72a3e4a6 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java @@ -1,19 +1,5 @@ package me.libraryaddict.disguise.commands; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; @@ -22,19 +8,34 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Entity)) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); return true; } HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -46,18 +47,18 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); if (disguise == null) { - sender.sendMessage(ChatColor.RED + "You are not disguised!"); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are not disguised!")); return true; } if (!map.containsKey(new DisguisePerm(disguise.getType()))) { - sender.sendMessage(ChatColor.RED + "No permission to modify your disguise!"); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "No permission to modify your disguise!")); return true; } try { - DisguiseParser.callMethods(sender, disguise, getPermissions(sender).get(new DisguisePerm(disguise.getType())), - new ArrayList(), args); + DisguiseParser.callMethods(sender, disguise, + getPermissions(sender).get(new DisguisePerm(disguise.getType())), new ArrayList(), args); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -71,14 +72,14 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom return true; } - sender.sendMessage(ChatColor.RED + "Your disguise has been modified!"); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Your disguise has been modified!")); return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); if (!(sender instanceof Player)) return tabs; @@ -94,7 +95,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); - ArrayList usedOptions = new ArrayList(); + ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) { @@ -123,8 +124,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.add(e); } - } - else { + } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); @@ -149,11 +149,15 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Modify your own disguise as you wear it!"); - sender.sendMessage(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN - + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Modify your own disguise as you wear " + "it!")); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true")); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java index 574b043d..ed262ba1 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java @@ -1,10 +1,11 @@ package me.libraryaddict.disguise.commands; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; +import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -13,22 +14,22 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import me.libraryaddict.disguise.DisguiseConfig; -import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; -import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; -import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); return true; } if (getPermissions(sender).isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -39,14 +40,15 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements LibsDisguises.getInstance().getListener().setDisguiseModify(sender.getName(), args); - sender.sendMessage(ChatColor.RED + "Right click a disguised entity in the next " - + DisguiseConfig.getDisguiseEntityExpire() + " seconds to modify their disguise!"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Right click a disguised entity " + "in the next %s seconds to modify their disguise!"), + DisguiseConfig.getDisguiseEntityExpire())); return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); if (!(sender instanceof Player)) { return tabs; @@ -75,8 +77,7 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.add(e); } - } - else { + } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); @@ -88,7 +89,8 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(perm.getType().getWatcherClass())) { + for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( + perm.getType().getWatcherClass())) { tabs.add(method.getName()); } } @@ -104,12 +106,14 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements * @param map */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN - + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!")); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } - } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java index 31966612..3574ed20 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java @@ -1,18 +1,5 @@ package me.libraryaddict.disguise.commands; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.utilities.DisguiseParser; @@ -20,6 +7,19 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter { @@ -28,7 +28,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -40,7 +40,9 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s" + "'"), + args[0])); return true; } @@ -61,18 +63,21 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements disguise = DisguiseAPI.getDisguise(player); if (disguise == null) { - sender.sendMessage(ChatColor.RED + "The player '" + player.getName() + "' is not disguised"); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "The player '%s' is " + "not disguised"), + player.getName())); return true; } if (!map.containsKey(new DisguisePerm(disguise.getType()))) { - sender.sendMessage(ChatColor.RED + "You do not have permission to modify this disguise"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You do not have permission to modify this " + "disguise")); return true; } try { - DisguiseParser.callMethods(sender, disguise, map.get(new DisguisePerm(disguise.getType())), new ArrayList(), - newArgs); + DisguiseParser.callMethods(sender, disguise, map.get(new DisguisePerm(disguise.getType())), + new ArrayList(), newArgs); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -86,14 +91,15 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements return true; } - sender.sendMessage(ChatColor.RED + "Modified the disguise of " + player.getName() + "!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "Modified the disguise of " + player.getName() + "!")); return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); HashMap, Boolean>> perms = getPermissions(sender); @@ -105,12 +111,13 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); } - } - else { + } else { Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s'"), + args[0])); return tabs; } @@ -123,13 +130,15 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements disguise = DisguiseAPI.getDisguise(player); if (disguise == null) { - sender.sendMessage(ChatColor.RED + "The player '" + player.getName() + "' is not disguised"); + sender.sendMessage(String.format( + TranslateType.MESSAGE.get(ChatColor.RED + "The player '%s' " + "is not disguised"), + player.getName())); return tabs; } DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); - ArrayList usedOptions = new ArrayList(); + ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (int i = 1; i < args.length; i++) { @@ -158,8 +167,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.add(e); } - } - else { + } else { if (info.getParamClass() == String.class) { for (Player p : Bukkit.getOnlinePlayers()) { tabs.add(p.getName()); @@ -171,7 +179,8 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( + disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -185,11 +194,13 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Modify the disguise of another player!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN - + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Modify the disguise of another player!")); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java index ed7db55d..f26aa3ba 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java @@ -9,6 +9,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -42,8 +43,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements if (sender instanceof Player) { center = ((Player) sender).getLocation(); - } - else { + } else { center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); } @@ -53,14 +53,15 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); return true; } HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -78,8 +79,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements Collections.sort(classes); - sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN - + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "EntityTypes usable " + "are: %s"), + ChatColor.GREEN + StringUtils.join(classes, + ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + ".")); return true; } @@ -104,31 +107,36 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements } if (type == null) { - sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Unrecognised " + "EntityType %s"), + args[0])); return true; } } } if (args.length == starting + 1) { - sender.sendMessage(ChatColor.RED + "You need to supply the disguise options as well as the radius" - + (starting != 0 ? " and EntityType" : "")); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You need to supply the disguise options as well as the radius" + (starting != 0 ? + " and EntityType" : ""))); return true; - } - else if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise options"); + } else if (args.length < 2) { + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You need to supply a radius as well as " + "the disguise options")); return true; } if (!isNumeric(args[starting])) { - sender.sendMessage(ChatColor.RED + args[starting] + " is not a number"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "%s is not a " + "number"), + args[starting])); return true; } int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { - sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius)); radius = maxRadius; } @@ -184,14 +192,16 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements } if (noPermission > 0) { - sender.sendMessage(ChatColor.RED + "No permission to modify " + noPermission + " disguises!"); + sender.sendMessage(String.format( + TranslateType.MESSAGE.get(ChatColor.RED + "No permission to modify " + "%s disguises!"), + noPermission)); } if (modifiedDisguises > 0) { - sender.sendMessage(ChatColor.RED + "Successfully modified the disguises of " + modifiedDisguises + " entities!"); - } - else { - sender.sendMessage(ChatColor.RED + "Couldn't find any disguised entities!"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Successfully modified the disguises of %s" + " entities!"), modifiedDisguises)); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Couldn't find any disguised entities!")); } return true; @@ -199,7 +209,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); HashMap, Boolean>> perms = getPermissions(sender); @@ -231,11 +241,12 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { - sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius)); radius = maxRadius; } - ArrayList usedOptions = new ArrayList(); + ArrayList usedOptions = new ArrayList<>(); for (Entity entity : getNearbyEntities(sender, radius)) { Disguise disguise = DisguiseAPI.getDisguise(entity); @@ -246,9 +257,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements DisguiseType disguiseType = disguise.getType(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { - for (int i = 0; i < args.length; i++) { - String arg = args[i]; - + for (String arg : args) { if (!method.getName().equalsIgnoreCase(arg)) continue; @@ -256,7 +265,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements } } - if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { + if (passesCheck(sender, perms.get(new DisguisePerm(disguiseType)), usedOptions)) { boolean addMethods = true; if (args.length > 1 + starting) { @@ -272,8 +281,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.add(e); } - } - else { + } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); @@ -285,7 +293,8 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( + disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -299,31 +308,35 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at " + maxRadius + " blocks!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN - + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), maxRadius)); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; if (allowedDisguises.contains("player")) { - sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius player ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); + sender.sendMessage(TranslateType.MESSAGE.get( + (ChatColor.DARK_GREEN + "/disguiseradius player ").replace( + "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); } - sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius ").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); + sender.sendMessage(TranslateType.MESSAGE.get( + (ChatColor.DARK_GREEN + "/disguiseradius ").replace( + "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); + sender.sendMessage(TranslateType.MESSAGE.get( + (ChatColor.DARK_GREEN + "/disguiseradius ").replace( + "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); } - sender.sendMessage( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes")); } - } diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 10718ee6..dfb20969 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -1,18 +1,5 @@ package me.libraryaddict.disguise.commands; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; @@ -23,6 +10,20 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter { @@ -31,7 +32,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -41,14 +42,16 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom } if (args.length == 1) { - sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the player"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You need to supply a disguise as well as " + "the player")); return true; } Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s'"), args[0])); return true; } @@ -78,8 +81,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom } if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) { - sender.sendMessage( - ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the" + " config!")); return true; } @@ -97,12 +100,13 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom DisguiseAPI.disguiseToAll(player, disguise); if (disguise.isDisguiseInUse()) { - sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a " - + disguise.getType().toReadable() + "!"); - } - else { sender.sendMessage( - ChatColor.RED + "Failed to disguise " + player.getName() + " as a " + disguise.getType().toReadable() + "!"); + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully disguised %s as a %s!"), + player.getName(), disguise.getType().toReadable())); + } else { + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Failed to disguise %s as a %s!"), + player.getName(), disguise.getType().toReadable())); } return true; @@ -110,7 +114,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); HashMap, Boolean>> perms = getPermissions(sender); @@ -119,13 +123,9 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); } - } - else if (args.length == 1) { - for (String type : getAllowedDisguises(perms)) { - tabs.add(type); - } - } - else { + } else if (args.length == 1) { + tabs.addAll(getAllowedDisguises(perms)); + } else { DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[1]); if (disguiseType == null) @@ -135,9 +135,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); } - } - else { - ArrayList usedOptions = new ArrayList(); + } else { + ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 3 : 2; i < args.length; i++) { @@ -163,11 +162,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom addMethods = false; if (info.isEnums()) { - for (String e : info.getEnums(origArgs[origArgs.length - 1])) { - tabs.add(e); - } - } - else { + tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1]))); + } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { tabs.add(player.getName()); @@ -179,7 +175,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( + disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -194,22 +191,26 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { + protected void sendCommandUsage(CommandSender sender, + HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN - + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer player "); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "/disguiseplayer player " + "")); } - sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer "); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "/disguiseplayer " + " ")); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage( - ChatColor.DARK_GREEN + "/disguiseplayer "); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "/disguiseplayer " + "")); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 62c9d4ca..60025b45 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -11,6 +11,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; +import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -25,10 +26,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter { private int maxRadius = 30; @@ -46,14 +44,15 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); return true; } HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); return true; } @@ -72,8 +71,9 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom Collections.sort(classes); sender.sendMessage( - ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN + StringUtils.join(classes, - ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."); + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), + ChatColor.GREEN + StringUtils.join(classes, + ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); return true; } @@ -94,35 +94,40 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom try { type = EntityType.valueOf(args[0].toUpperCase()); } - catch (Exception ex) { + catch (Exception ignored) { } if (type == null) { - sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Unrecognised " + "EntityType %s"), + args[0])); return true; } } } if (args.length == starting + 1) { - sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ? - " and EntityType" : "")); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ? + " and EntityType" : ""))); return true; } else if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "You need to supply a radius as well as " + "the disguise")); return true; } if (!isNumeric(args[starting])) { - sender.sendMessage(ChatColor.RED + args[starting] + " is not a number"); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "%s is not a number"), args[starting])); return true; } int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { - sender.sendMessage( - ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius)); radius = maxRadius; } @@ -193,14 +198,17 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (disguisedEntitys > 0) { - sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully disguised %s" + " entities!"), + disguisedEntitys)); } else { - sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!"); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Couldn't find any entities to disguise!")); } if (miscDisguises > 0) { - sender.sendMessage( - ChatColor.RED + "Failed to disguise " + miscDisguises + " entities because the option to disguise a living entity as a non-living has been disabled in the config"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as" + " a non-living has been disabled in the config"), + miscDisguises)); } return true; @@ -208,7 +216,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); HashMap, Boolean>> perms = getPermissions(sender); @@ -238,9 +246,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (args.length == starting) { - for (String type : getAllowedDisguises(perms)) { - tabs.add(type); - } + tabs.addAll(getAllowedDisguises(perms)); } else { DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[starting]); @@ -253,7 +259,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom tabs.add(player.getName()); } } else { - ArrayList usedOptions = new ArrayList(); + ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 : @@ -280,9 +286,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom addMethods = false; if (info.isEnums()) { - for (String e : info.getEnums(origArgs[origArgs.length - 1])) { - tabs.add(e); - } + tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1]))); } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { @@ -315,30 +319,31 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), maxRadius)); sender.sendMessage( - ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at " + maxRadius + " blocks!"); - sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join( - allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; if (allowedDisguises.contains("player")) { - sender.sendMessage( + sender.sendMessage(TranslateType.MESSAGE.get( (ChatColor.DARK_GREEN + "/disguiseradius player ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); + "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); } - sender.sendMessage( + sender.sendMessage(TranslateType.MESSAGE.get( (ChatColor.DARK_GREEN + "/disguiseradius ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); + "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage( + sender.sendMessage(TranslateType.MESSAGE.get( (ChatColor.DARK_GREEN + "/disguiseradius ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); + "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); } - sender.sendMessage( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes")); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java index 84d0ecf3..7c38b092 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -16,7 +17,8 @@ public class DisguiseViewSelfCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); return true; } @@ -24,14 +26,12 @@ public class DisguiseViewSelfCommand implements CommandExecutor { if (DisguiseAPI.isViewSelfToggled(player)) { DisguiseAPI.setViewDisguiseToggled(player, false); - sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise off!"); - } - else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "Toggled viewing own disguise off!")); + } else { DisguiseAPI.setViewDisguiseToggled(player, true); - sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise on!"); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "Toggled viewing own disguise on!")); } return true; } - } diff --git a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index 6b413ac4..0625174d 100644 --- a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -1,10 +1,8 @@ package me.libraryaddict.disguise.commands; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - +import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -12,7 +10,9 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import me.libraryaddict.disguise.LibsDisguises; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { protected ArrayList filterTabs(ArrayList list, String[] origArgs) { @@ -52,29 +52,28 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0) { - sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" - + Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion() - + " by libraryaddict, formerly maintained by Byteflux and NavidK0.\n" + "Use " + ChatColor.GREEN - + "/libsdisguises reload" + ChatColor.DARK_GREEN - + " to reload the config. All disguises will be blown by doing this."); + sender.sendMessage( + ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + Bukkit.getPluginManager().getPlugin( + "LibsDisguises").getDescription().getVersion() + " by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." + ( + sender.hasPermission("libsdisguises.reload") ? + "\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" + "." : + "")); if (LibsPremium.isPremium()) { sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); } - } - else if (args.length > 0) { + } else if (args.length > 0) { if (sender.hasPermission("libsdisguises.reload")) { if (args[0].equalsIgnoreCase("reload")) { LibsDisguises.getInstance().reload(); - sender.sendMessage(ChatColor.GREEN + "[LibsDisguises] Reloaded config."); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "[LibsDisguises] Reloaded config.")); return true; + } else { + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?")); } - else { - sender.sendMessage(ChatColor.RED + "[LibsDisguises] That command doesn't exist!"); - } - } - else { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); } } return true; @@ -82,7 +81,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); if (args.length == 0) diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java index 27abc63c..bcaab320 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -9,32 +10,24 @@ import org.bukkit.entity.Player; import me.libraryaddict.disguise.DisguiseAPI; -public class UndisguiseCommand implements CommandExecutor -{ +public class UndisguiseCommand implements CommandExecutor { @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) - { - if (sender.getName().equals("CONSOLE")) - { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); return true; } - if (sender.hasPermission("libsdisguises.undisguise")) - { - if (DisguiseAPI.isDisguised((Entity) sender)) - { + if (sender.hasPermission("libsdisguises.undisguise")) { + if (DisguiseAPI.isDisguised((Entity) sender)) { DisguiseAPI.undisguiseToAll((Player) sender); - sender.sendMessage(ChatColor.RED + "You are no longer disguised"); + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are no longer disguised")); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are not disguised!")); } - else - { - sender.sendMessage(ChatColor.RED + "You are not disguised!"); - } - } - else - { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); } return true; } diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java index 6b586f2c..d49d988a 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java @@ -1,31 +1,27 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import me.libraryaddict.disguise.LibsDisguises; - -public class UndisguiseEntityCommand implements CommandExecutor -{ +public class UndisguiseEntityCommand implements CommandExecutor { @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) - { - if (sender.getName().equals("CONSOLE")) - { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); return true; } - if (sender.hasPermission("libsdisguises.undisguiseentity")) - { + if (sender.hasPermission("libsdisguises.undisguiseentity")) { LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null); - sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!"); - } - else - { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage(TranslateType.MESSAGE.get( + ChatColor.RED + "Right click a disguised entity to " + "undisguise them!")); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); } return true; } diff --git a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java index 75c2b5fa..c7537e1e 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java @@ -1,9 +1,7 @@ package me.libraryaddict.disguise.commands; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -12,7 +10,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import me.libraryaddict.disguise.DisguiseAPI; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { protected ArrayList filterTabs(ArrayList list, String[] origArgs) { @@ -35,7 +35,7 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { } protected String[] getArgs(String[] args) { - ArrayList newArgs = new ArrayList(); + ArrayList newArgs = new ArrayList<>(); for (int i = 0; i < args.length - 1; i++) { String s = args[i]; @@ -57,29 +57,26 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { if (p != null) { if (DisguiseAPI.isDisguised(p)) { DisguiseAPI.undisguiseToAll(p); - sender.sendMessage(ChatColor.RED + "The player is no longer disguised"); - } - else { - sender.sendMessage(ChatColor.RED + "The player is not disguised!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "The player is no longer disguised")); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "The player is not disguised!")); } + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Player not found")); } - else { - sender.sendMessage(ChatColor.RED + "Player not found"); - } + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/undisguiseplayer ")); } - else { - sender.sendMessage(ChatColor.RED + "/undisguiseplayer "); - } - } - else { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); } return true; } @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList(); + ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); if (args.length != 0) diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java index b8d12918..a01df165 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java @@ -1,5 +1,7 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -7,8 +9,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import me.libraryaddict.disguise.DisguiseAPI; - public class UndisguiseRadiusCommand implements CommandExecutor { private int maxRadius = 30; @@ -29,24 +29,28 @@ public class UndisguiseRadiusCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); + sender.sendMessage( + TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); return true; } if (sender.hasPermission("libsdisguises.undisguiseradius")) { int radius = maxRadius; if (args.length > 0) { if (!isNumeric(args[0])) { - sender.sendMessage( - ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED + " is not a number!"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! " + ChatColor.GREEN + "%s" + ChatColor.RED + " is not a " + "number!"), + args[0])); return true; } radius = Integer.parseInt(args[0]); if (radius > maxRadius) { - sender.sendMessage( - ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); + sender.sendMessage(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Limited radius to %s" + "! Don't want to make too much lag right?"), + maxRadius)); radius = maxRadius; } } + int disguisedEntitys = 0; for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { if (entity == sender) { @@ -57,10 +61,11 @@ public class UndisguiseRadiusCommand implements CommandExecutor { disguisedEntitys++; } } - sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!"); - } - else { - sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + sender.sendMessage( + String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully undisguised %s entities!"), + disguisedEntitys)); + } else { + sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); } return true; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index 68b0b279..06fdba72 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -36,8 +36,8 @@ public class DisguiseParser { super(); } - public DisguiseParseException(String string) { - super(string); + public DisguiseParseException(LibsMessages message, String... params) { + super(message.get(params)); } } @@ -467,11 +467,12 @@ public class DisguiseParser { public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args, HashMap, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException { if (permissionMap.isEmpty()) { - throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this command."); + throw new DisguiseParseException( + TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this " + "command.")); } if (args.length == 0) { - throw new DisguiseParseException("No arguments defined"); + throw new DisguiseParseException(TranslateType.MESSAGE.get("No arguments defined")); } // How many args to skip due to the disugise being constructed @@ -487,15 +488,17 @@ public class DisguiseParser { disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase()); if (disguise == null) { - throw new DisguiseParseException( - ChatColor.RED + "Cannot find a disguise under the reference " + args[0]); + throw new DisguiseParseException(String.format( + TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find a disguise under the reference %s"), + args[0])); } } else { - throw new DisguiseParseException( - ChatColor.RED + "You do not have perimssion to use disguise references!"); + throw new DisguiseParseException(TranslateType.MESSAGE.get( + ChatColor.RED + "You do not have perimssion to use disguise references!")); } - optionPermissions = (permissionMap.containsKey(disguise.getType()) ? permissionMap.get(disguise.getType()) : + optionPermissions = (permissionMap.containsKey(new DisguisePerm(disguise.getType())) ? + permissionMap.get(new DisguisePerm(disguise.getType())) : new HashMap, Boolean>()); } else { DisguisePerm disguisePerm = getDisguisePerm(args[0]); @@ -506,21 +509,24 @@ public class DisguiseParser { } if (disguisePerm == null) { - throw new DisguiseParseException( - ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0] + ChatColor.RED + " doesn't exist!"); + throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " " + "doesn't exist!"), + args[0])); } if (disguisePerm.isUnknown()) { - throw new DisguiseParseException( - ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"); + throw new DisguiseParseException(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!")); } if (disguisePerm.getEntityType() == null) { - throw new DisguiseParseException(ChatColor.RED + "Error! This disguise couldn't be loaded!"); + throw new DisguiseParseException( + TranslateType.MESSAGE.get(ChatColor.RED + "Error! This disguise " + "couldn't be loaded!")); } if (!permissionMap.containsKey(disguisePerm)) { - throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this disguise."); + throw new DisguiseParseException( + TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use " + "this disguise.")); } optionPermissions = permissionMap.get(disguisePerm); @@ -532,12 +538,13 @@ public class DisguiseParser { // If he is doing a player disguise if (args.length == 1) { // He needs to give the player name - throw new DisguiseParseException(ChatColor.RED + "Error! You need to give a player name!"); + throw new DisguiseParseException(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! You need " + "to give a player name!")); } else { if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey( args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) { - throw new DisguiseParseException( - ChatColor.RED + "Error! You don't have permission to use that name!"); + throw new DisguiseParseException(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! You don't have permission to use that name!")); } args[1] = args[1].replace("\\_", " "); @@ -604,8 +611,9 @@ public class DisguiseParser { case WITHER_SKULL: break; default: - throw new DisguiseParseException( - ChatColor.RED + "Error! " + disguisePerm.toReadable() + " doesn't know what to do with " + args[1] + "!"); + throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! %s doesn't know" + " " + "what to do with %s!"), + disguisePerm.toReadable(), args[1])); } toSkip++; // If they also defined a data value @@ -615,8 +623,10 @@ public class DisguiseParser { } if (secondArg != null) { if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm.getType() != DisguiseType.DROPPED_ITEM) { - throw new DisguiseParseException( - ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!"); + throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!"), + DisguiseType.FALLING_BLOCK.toReadable(), + DisguiseType.DROPPED_ITEM.toReadable())); } miscData = Integer.parseInt(secondArg); } @@ -635,8 +645,9 @@ public class DisguiseParser { } if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { - throw new DisguiseParseException( - ChatColor.RED + "Error! You do not have permission to use the parameter " + toCheck + " on the " + disguisePerm.toReadable() + " disguise!"); + throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( + ChatColor.RED + "Error! You do not have permission to use the parameter %s on the" + " %s disguise!"), + toCheck, disguisePerm.toReadable())); } } diff --git a/src/me/libraryaddict/disguise/utilities/LibsMessages.java b/src/me/libraryaddict/disguise/utilities/LibsMessages.java new file mode 100644 index 00000000..86fad618 --- /dev/null +++ b/src/me/libraryaddict/disguise/utilities/LibsMessages.java @@ -0,0 +1,22 @@ +package me.libraryaddict.disguise.utilities; + +/** + * Created by libraryaddict on 15/06/2017. + */ +public enum LibsMessages { + // Format being CLASS_STRING. So no perm = DISG_COMMAND_NO_PERM. Or DISG_PARSE_NO_PERM_OPTION + TEST("This is a test string"); + + private String string; + + LibsMessages(String string) { + this.string = string; + } + + public String get(String... strings) { + if (strings.length == 0) + return TranslateType.MESSAGE.get(string); + + return String.format(TranslateType.MESSAGE.get(string), (Object[]) strings); + } +} diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java index 0ff5dd54..5965049f 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java @@ -149,7 +149,7 @@ public class ReflectionFlagWatchers { new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots"); 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(), 5), "Direction", + new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 4), "Direction", "View the five directions usable on player setSleeping disguise"); new ParamInfo(Rabbit.Type.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"); @@ -178,7 +178,7 @@ public class ReflectionFlagWatchers { new ParamInfo(ItemStack.class, "Item (id:damage)", "An ItemStack compromised of ID:Durability", materials); - new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..)", "Four ItemStacks seperated by an ,", + new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..)", "Four ItemStacks separated by an ,", materials) { @Override public String[] getEnums(String tabComplete) { @@ -203,14 +203,14 @@ public class ReflectionFlagWatchers { potionEnums.toArray(new String[0])); new ParamInfo(String.class, "Text", "A line of text"); new ParamInfo(boolean.class, "True/False", "True or False", new String[]{"true", "false"}); - new ParamInfo(int.class, "Number", "A whole number, no decimcals"); + new ParamInfo(int.class, "Number", "A whole number, no decimals"); new ParamInfo(double.class, "Number", "A number which can have decimals"); new ParamInfo(float.class, "Number", "A number which can have decimals"); new ParamInfo(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse"); - new ParamInfo(int[].class, "number,number,number...", "Numbers seperated by an ,"); + new ParamInfo(int[].class, "number,number,number..", "Numbers separated by an ,"); - new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers seperated by an ,"); + new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers separated by a ,"); new ParamInfo(GameProfile.class, "GameProfile", "Get the gameprofile here https://sessionserver.mojang.com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false"); @@ -223,7 +223,7 @@ public class ReflectionFlagWatchers { } public static Method[] getDisguiseWatcherMethods(Class watcherClass) { - ArrayList methods = new ArrayList(Arrays.asList(watcherClass.getMethods())); + ArrayList methods = new ArrayList<>(Arrays.asList(watcherClass.getMethods())); Iterator itel = methods.iterator(); diff --git a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java index d75191ee..d6c8a9a2 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.utilities; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import org.bukkit.inventory.ItemStack; import java.lang.reflect.Method; @@ -15,8 +16,11 @@ public class TranslateFiller { if (!info.isEnums()) continue; + if (info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class) + continue; + for (String e : info.getEnums("")) { - TranslateType.METHOD_PARAM.get(e, "Name for the param for " + info.getName()); + TranslateType.METHOD_PARAM.get(e, "Used as a disguise option for " + info.getName()); } } @@ -24,10 +28,23 @@ public class TranslateFiller { type.toReadable(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) { + Class para = method.getParameterTypes()[0]; + String className = method.getDeclaringClass().getSimpleName().replace("Watcher", ""); + + if (className.equals("Flag") || className.equals("Disguise")) + className = "Entity"; + else if (className.equals("Living")) + className = "Living Entity"; + else if (className.equals("AbstractHorse")) + className = "Horse"; + else if (className.equals("DroppedItem")) + className = "Item"; + else if (className.equals("IllagerWizard")) + className = "Illager"; + TranslateType.METHOD.get(method.getName(), - "Found in " + method.getDeclaringClass().getSimpleName().replace("Watcher", - "") + " and accepts as a parameter " + TranslateType.METHOD_PARAM.get( - method.getParameterTypes()[0].getSimpleName())); + "Found in the disguise options for " + className + " and uses " + (para.isArray() ? + "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s")); } } } diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java index a966bfbd..b6f99e4b 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateType.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -1,11 +1,15 @@ package me.libraryaddict.disguise.utilities; +import me.libraryaddict.disguise.DisguiseConfig; import org.apache.commons.lang3.StringEscapeUtils; +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; @@ -13,46 +17,80 @@ import java.util.Objects; * Created by libraryaddict on 10/06/2017. */ public enum TranslateType { - DISGUISE("disguise_names"), MESSAGE("messages"), METHOD_PARAM("option_names"), METHOD("disguise_options"); + DISGUISE("disguises"), MESSAGE("messages"), METHOD_PARAM("disguise_options"), METHOD("disguise_option_parameters"); private File file; - private YamlConfiguration config; + private HashMap translated = new HashMap<>(); TranslateType(String fileName) { - file = new File("translate", fileName + ".yml"); + file = new File("plugins/LibsDisguises/Translations", fileName + ".yml"); reload(); } - public void reload() { - if (!file.exists()) - file.getParentFile().mkdirs(); - - try { - file.createNewFile(); - } - catch (IOException e) { - e.printStackTrace(); + public static void reloadTranslations() { + for (TranslateType type : values()) { + type.reload(); } - config = YamlConfiguration.loadConfiguration(file); + TranslateFiller.fillConfigs(); } - private YamlConfiguration getConfig() { - return config; + private void reload() { + if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) + return; + + translated.clear(); + + if (!file.exists()) + return; + + System.out.println("[LibsDisguises] Loading translations: " + name()); + YamlConfiguration config = new YamlConfiguration(); + config.options().pathSeparator(Character.toChars(0)[0]); + + try { + config.load(file); + + for (String key : config.getKeys(false)) { + String value = config.getString(key); + + if (value == null) + System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'"); + else + translated.put(key, value); + } + } + catch (Exception e) { + e.printStackTrace(); + } } private File getFile() { return file; } - public void save(String message, String comment) { - message = StringEscapeUtils.escapeJson(message); - - if (getConfig().contains(message)) + private void save(String message, String comment) { + if (translated.containsKey(message)) return; + translated.put(message, message); + + message = StringEscapeUtils.escapeJava(message); + try { - PrintWriter writer = new PrintWriter(getFile()); - writer.write((comment != null ? "# " + comment + "\n" : "") + message + ": " + message + "\n"); + boolean exists = file.exists(); + + if (!exists) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + + FileWriter writer = new FileWriter(getFile(), true); + + if (!exists) + writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n"); + + writer.write("\n" + (comment != null ? "# " + comment + "\n" : + "") + "\"" + message + "\": \"" + message + "\"\n"); writer.close(); } @@ -62,10 +100,10 @@ public enum TranslateType { } public String reverseGet(String translated) { - translated = StringEscapeUtils.unescapeJson(translated).toLowerCase(); + translated = translated.toLowerCase(); - for (Map.Entry entry : getConfig().getValues(false).entrySet()) { - if (!Objects.equals(entry.getValue().toString().toLowerCase(), translated)) + for (Map.Entry entry : this.translated.entrySet()) { + if (!Objects.equals(entry.getValue().toLowerCase(), translated)) continue; return entry.getKey(); @@ -82,10 +120,15 @@ public enum TranslateType { } public String get(String message, String comment) { - String msg = getConfig().getString(StringEscapeUtils.escapeJson(message)); + if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) + return message; + System.out.println("1"); + + String msg = translated.get(message); if (msg != null) return msg; + System.out.println("2"); save(message, comment); diff --git a/src/me/libraryaddict/disguise/utilities/json/SerializerGameProfile.java b/src/me/libraryaddict/disguise/utilities/json/SerializerGameProfile.java index dcabf0a4..52204ad9 100644 --- a/src/me/libraryaddict/disguise/utilities/json/SerializerGameProfile.java +++ b/src/me/libraryaddict/disguise/utilities/json/SerializerGameProfile.java @@ -13,7 +13,6 @@ public class SerializerGameProfile implements JsonSerializer @Override public JsonElement serialize(WrappedGameProfile src, Type typeOfSrc, JsonSerializationContext context) { - System.out.println(src.getHandle().toString()); return context.serialize(src.getHandle(), GameProfile.class); } From 716bfd449b02170a043db53048e0825495dc7d90 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 20 Jun 2017 05:06:35 +1200 Subject: [PATCH 3/7] Current work --- config.yml | 1 - .../disguise/DisguiseConfig.java | 38 +--- .../disguise/DisguiseListener.java | 119 ++++++---- .../commands/DisguiseBaseCommand.java | 2 +- .../commands/DisguiseCloneCommand.java | 27 +-- .../disguise/commands/DisguiseCommand.java | 29 +-- .../commands/DisguiseEntityCommand.java | 29 ++- .../commands/DisguiseHelpCommand.java | 43 ++-- .../commands/DisguiseModifyCommand.java | 28 ++- .../commands/DisguiseModifyEntityCommand.java | 22 +- .../commands/DisguiseModifyPlayerCommand.java | 37 ++-- .../commands/DisguiseModifyRadiusCommand.java | 73 ++---- .../commands/DisguisePlayerCommand.java | 40 ++-- .../commands/DisguiseRadiusCommand.java | 76 +++---- .../commands/DisguiseViewSelfCommand.java | 11 +- .../commands/LibsDisguisesCommand.java | 15 +- .../disguise/commands/UndisguiseCommand.java | 15 +- .../commands/UndisguiseEntityCommand.java | 9 +- .../commands/UndisguisePlayerCommand.java | 14 +- .../commands/UndisguiseRadiusCommand.java | 20 +- .../disguise/utilities/DisguiseParser.java | 95 ++++---- .../disguise/utilities/DisguiseUtilities.java | 209 +++++++++--------- .../disguise/utilities/LibsMessages.java | 22 -- .../disguise/utilities/LibsMsg.java | 180 +++++++++++++++ .../disguise/utilities/TranslateFiller.java | 4 + .../disguise/utilities/TranslateType.java | 29 ++- 26 files changed, 626 insertions(+), 561 deletions(-) delete mode 100644 src/me/libraryaddict/disguise/utilities/LibsMessages.java create mode 100644 src/me/libraryaddict/disguise/utilities/LibsMsg.java diff --git a/config.yml b/config.yml index 195d7e08..cc7e79fc 100644 --- a/config.yml +++ b/config.yml @@ -111,7 +111,6 @@ MonstersIgnoreDisguises: false # Works only for disguised players when attacked by a entity (arrow, monster. etc) # This will blow all disguises he has on him BlowDisguises: false -BlownDisguiseMessage: '&cYour disguise was blown!' #Stop shulker disguises from moving, they're weird. This option only effects PLAYERS that are disguised, other entities disguised as shulkers will NOT be effected! StopShulkerDisguisesFromMoving: true diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index 32d565dc..83a36c6a 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -26,9 +26,8 @@ public class DisguiseConfig { private static boolean collectEnabled; private static boolean colorizeSheep; private static boolean colorizeWolf; - private static HashMap customDisguises = new HashMap(); + private static HashMap customDisguises = new HashMap<>(); private static boolean disableInvisibility; - private static String disguiseBlownMessage; private static int disguiseCloneExpire; private static int disguiseEntityExpire; private static boolean displayPlayerDisguisesInTab; @@ -52,7 +51,6 @@ public class DisguiseConfig { private static boolean stopShulkerDisguisesFromMoving; private static boolean targetDisguises; private static boolean undisguiseSwitchWorlds; - private static String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"; private static String updateNotificationPermission; private static boolean viewSelfDisguise; private static boolean witherSkullEnabled; @@ -65,8 +63,8 @@ public class DisguiseConfig { public static Entry getCustomDisguise(String disguise) { for (Entry entry : customDisguises.entrySet()) { - if (!entry.getKey().equalsIgnoreCase(disguise) && !entry.getKey().replaceAll("_", "").equalsIgnoreCase( - disguise)) + if (!entry.getKey().equalsIgnoreCase(disguise) && !entry.getKey().replaceAll("_", "") + .equalsIgnoreCase(disguise)) continue; return entry; @@ -109,10 +107,6 @@ public class DisguiseConfig { return customDisguises; } - public static String getDisguiseBlownMessage() { - return disguiseBlownMessage; - } - public static int getDisguiseCloneExpire() { return disguiseCloneExpire; } @@ -125,10 +119,6 @@ public class DisguiseConfig { return maxClonedDisguises; } - public static String getUpdateMessage() { - return updateMessage; - } - public static String getUpdateNotificationPermission() { return updateNotificationPermission; } @@ -165,7 +155,6 @@ public class DisguiseConfig { setModifyBoundingBox(config.getBoolean("ModifyBoundingBox")); setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises")); setDisguiseBlownOnAttack(config.getBoolean("BlowDisguises")); - setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&', config.getString("BlownDisguiseMessage"))); setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath")); setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving")); setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement")); @@ -195,8 +184,8 @@ public class DisguiseConfig { setUseTranslations(config.getBoolean("Translations")); try { - String option = config.getString("SelfDisguisesScoreboard", - DisguisePushing.MODIFY_SCOREBOARD.name()).toUpperCase(); + String option = config.getString("SelfDisguisesScoreboard", DisguisePushing.MODIFY_SCOREBOARD.name()) + .toUpperCase(); if (!option.endsWith("_SCOREBOARD")) option += "_SCOREBOARD"; @@ -204,8 +193,8 @@ public class DisguiseConfig { disablePushing = DisguisePushing.valueOf(option); } catch (Exception ex) { - System.out.println("[LibsDisguises] Cannot parse '" + config.getString( - "SelfDisguisesScoreboard") + "' to a valid option for SelfDisguisesTeam"); + System.out.println("[LibsDisguises] Cannot parse '" + config + .getString("SelfDisguisesScoreboard") + "' to a valid option for SelfDisguisesTeam"); } customDisguises.clear(); @@ -233,8 +222,9 @@ public class DisguiseConfig { } try { - Disguise disguise = DisguiseParser.parseDisguise(Bukkit.getConsoleSender(), "disguise", - toParse.split(" "), DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise")); + Disguise disguise = DisguiseParser + .parseDisguise(Bukkit.getConsoleSender(), "disguise", toParse.split(" "), + DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise")); customDisguises.put(key, disguise); @@ -429,10 +419,6 @@ public class DisguiseConfig { disableInvisibility = disableInvis; } - public static void setDisguiseBlownMessage(String newMessage) { - disguiseBlownMessage = newMessage; - } - public static void setDisguiseBlownOnAttack(boolean blowDisguise) { blowDisguisesOnAttack = blowDisguise; } @@ -567,10 +553,6 @@ public class DisguiseConfig { undisguiseSwitchWorlds = isUndisguise; } - public static void setUpdateMessage(String newMessage) { - updateMessage = newMessage; - } - public static void setUpdateNotificationPermission(String newPermission) { updateNotificationPermission = newPermission; } diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 7bf5557b..9668d9b4 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.UpdateChecker; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -86,15 +87,14 @@ public class DisguiseListener implements Listener { continue; } - p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, - latestVersion)); + p.sendMessage(LibsMsg.UPDATE_READY.get(currentVersion, latestVersion)); } } }); } catch (Exception ex) { - System.out.print( - String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage())); + System.out.print(String + .format("[LibsDisguises] Failed to check for update: %s", ex.getMessage())); } } }, 0, (20 * 60 * 60 * 6)); // Check every 6 hours @@ -138,8 +138,10 @@ public class DisguiseListener implements Listener { if (disguises.length > 0) { DisguiseAPI.undisguiseToAll(entity); - if (DisguiseConfig.getDisguiseBlownMessage().length() > 0) { - entity.sendMessage(DisguiseConfig.getDisguiseBlownMessage()); + String blown = LibsMsg.BLOWN_DISGUISE.get(); + + if (blown.length() > 0) { + entity.sendMessage(blown); } } } @@ -278,15 +280,15 @@ public class DisguiseListener implements Listener { Player p = event.getPlayer(); if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) { - p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion)); + p.sendMessage(LibsMsg.UPDATE_READY.get(currentVersion, latestVersion)); } if (DisguiseConfig.isBedPacketsEnabled()) { chunkMove(p, p.getLocation(), null); } - if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && DisguiseUtilities.hasGameProfile( - p.getName())) { + if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && DisguiseUtilities + .hasGameProfile(p.getName())) { WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p); if (!profile.getProperties().isEmpty()) { @@ -364,9 +366,9 @@ public class DisguiseListener implements Listener { Location to = event.getTo(); Location from = event.getFrom(); - if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord( - from.getBlockX()) || DisguiseUtilities.getChunkCord( - to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { + if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities + .getChunkCord(from.getBlockX()) || DisguiseUtilities + .getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { chunkMove(event.getPlayer(), to, from); } } @@ -375,7 +377,8 @@ public class DisguiseListener implements Listener { Disguise disguise; if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) { - if (disguise.getType() == DisguiseType.SHULKER) { // Stop Shulker disguises from moving their coordinates + if (disguise + .getType() == DisguiseType.SHULKER) { // Stop Shulker disguises from moving their coordinates Location from = event.getFrom(); Location to = event.getTo(); @@ -429,8 +432,8 @@ public class DisguiseListener implements Listener { @EventHandler public void onRightClick(PlayerInteractEntityEvent event) { - if (!disguiseEntity.containsKey(event.getPlayer().getName()) && !disguiseClone.containsKey( - event.getPlayer().getName())) { + if (!disguiseEntity.containsKey(event.getPlayer().getName()) && !disguiseClone + .containsKey(event.getPlayer().getName())) { return; } @@ -456,9 +459,9 @@ public class DisguiseListener implements Listener { Disguise disguise = disguiseEntity.remove(p.getName()); if (disguise != null) { - if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { - p.sendMessage( - ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); + if (disguise.isMiscDisguise() && !DisguiseConfig + .isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { + p.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get()); } else { if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { if (disguise.getWatcher() instanceof LivingWatcher) { @@ -472,31 +475,62 @@ public class DisguiseListener implements Listener { DisguiseAPI.disguiseToAll(entity, disguise); - String disguiseName = "a "; + String disguiseName; if (disguise instanceof PlayerDisguise) { - disguiseName = "the player " + ((PlayerDisguise) disguise).getName(); + disguiseName = ((PlayerDisguise) disguise).getName(); } else { - disguiseName += disguise.getType().toReadable(); + disguiseName = disguise.getType().toReadable(); } + // Jeez, maybe I should redo my messages here if (disguise.isDisguiseInUse()) { - p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : - "the ") + entityName + " as " + disguiseName + "!"); + if (disguise.isPlayerDisguise()) { + if (entity instanceof Player) { + p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER.get(entityName, disguiseName)); + } else { + p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER.get(entityName, disguiseName)); + } + } else { + if (entity instanceof Player) { + p.sendMessage(LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY.get(entityName, disguiseName)); + } else { + p.sendMessage(LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY.get(entityName, disguiseName)); + } + } } else { - p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : - "the ") + entityName + " as " + disguiseName + "!"); + if (disguise.isPlayerDisguise()) { + if (entity instanceof Player) { + p.sendMessage( + LibsMsg.LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL.get(entityName, disguiseName)); + } else { + p.sendMessage( + LibsMsg.LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL.get(entityName, disguiseName)); + } + } else { + if (entity instanceof Player) { + p.sendMessage( + LibsMsg.LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL.get(entityName, disguiseName)); + } else { + p.sendMessage( + LibsMsg.LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL.get(entityName, disguiseName)); + } + } } } } else { if (DisguiseAPI.isDisguised(entity)) { DisguiseAPI.undisguiseToAll(entity); - p.sendMessage( - ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName); + if (entity instanceof Player) + p.sendMessage(LibsMsg.LISTEN_UNDISG_PLAYER.get(entityName)); + else + p.sendMessage(LibsMsg.LISTEN_UNDISG_ENT.get(entityName)); } else { - p.sendMessage( - ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!"); + if (entity instanceof Player) + p.sendMessage(LibsMsg.LISTEN_UNDISG_PLAYER_FAIL.get(entityName)); + else + p.sendMessage(LibsMsg.LISTEN_UNDISG_ENT_FAIL.get(entityName)); } } } else if (disguiseModify.containsKey(p.getName())) { @@ -505,22 +539,22 @@ public class DisguiseListener implements Listener { Disguise disguise = DisguiseAPI.getDisguise(p, entity); if (disguise == null) { - p.sendMessage(ChatColor.RED + entityName + " is not disguised!"); + p.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityName)); return; } - HashMap, Boolean>> perms = DisguiseParser.getPermissions(p, - "libsdisguises.disguiseentitymodify."); + HashMap, Boolean>> perms = DisguiseParser + .getPermissions(p, "libsdisguises.disguiseentitymodify."); if (!perms.containsKey(new DisguisePerm(disguise.getType()))) { - p.sendMessage(ChatColor.RED + "You do not have permission to modify this disguise"); + p.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get()); return; } try { DisguiseParser.callMethods(p, disguise, perms.get(new DisguisePerm(disguise.getType())), new ArrayList(), options); - p.sendMessage(ChatColor.RED + "Modified the disguise!"); + p.sendMessage(LibsMsg.LISTENER_MODIFIED_DISG.get()); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -535,8 +569,8 @@ public class DisguiseListener implements Listener { @EventHandler public void onTarget(EntityTargetEvent event) { - if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player && DisguiseAPI.isDisguised( - event.getTarget())) { + if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event + .getTarget() instanceof Player && DisguiseAPI.isDisguised(event.getTarget())) { switch (event.getReason()) { case TARGET_ATTACKED_ENTITY: case TARGET_ATTACKED_OWNER: @@ -557,9 +591,9 @@ public class DisguiseListener implements Listener { Location from = event.getFrom(); if (DisguiseConfig.isBedPacketsEnabled()) { - if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord( - from.getBlockX()) || DisguiseUtilities.getChunkCord( - to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { + if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities + .getChunkCord(from.getBlockX()) || DisguiseUtilities + .getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { chunkMove(player, null, from); Bukkit.getScheduler().runTask(plugin, new Runnable() { @@ -575,7 +609,8 @@ public class DisguiseListener implements Listener { return; } - if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null && to.getWorld() != from.getWorld()) { + if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null && to + .getWorld() != from.getWorld()) { for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) { disguise.removeDisguise(); } @@ -584,8 +619,8 @@ public class DisguiseListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onVehicleEnter(VehicleEnterEvent event) { - if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), - event.getEntered())) { + if (event.getEntered() instanceof Player && DisguiseAPI + .isDisguised((Player) event.getEntered(), event.getEntered())) { DisguiseUtilities.removeSelfDisguise((Player) event.getEntered()); ((Player) event.getEntered()).updateInventory(); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index cb317e42..a0c6f75b 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -33,7 +33,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { itel.remove(); } - return new ArrayList(new HashSet(list)); + return new ArrayList<>(new HashSet<>(list)); } protected ArrayList getAllowedDisguises( diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java index 29d57f3f..5b8fa379 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java @@ -4,6 +4,7 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -21,8 +22,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } @@ -38,8 +38,8 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp for (int i = player == null ? 0 : 1; i < args.length; i++) { String option = args[i]; - if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils.startsWithIgnoreCase(option, - "ignoreEnquip")) { + if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils + .startsWithIgnoreCase(option, "ignoreEnquip")) { doEquipment = false; } else if (option.equalsIgnoreCase("doSneakSprint")) { doSneak = true; @@ -49,9 +49,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp } else if (option.equalsIgnoreCase("doSprint")) { doSprint = true; } else { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.DARK_RED + "Unknown " + "option '%s" + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"), - option)); + sender.sendMessage(LibsMsg.INVALID_CLONE.get(option)); return true; } } @@ -63,12 +61,10 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp } else { LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options); - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Right click a entity in the next %s" + " seconds to grab the disguise reference!"), - DisguiseConfig.getDisguiseCloneExpire())); + sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire())); } } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); } return true; @@ -100,11 +96,8 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp @Override protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other " + "disguise commands!")); - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players " + "able to use disguise references.")); - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")")); + sender.sendMessage(LibsMsg.CLONE_HELP1.get()); + sender.sendMessage(LibsMsg.CLONE_HELP2.get()); + sender.sendMessage(LibsMsg.CLONE_HELP3.get()); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index 797ae011..831cb990 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -10,6 +10,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.TranslateType; @@ -31,8 +32,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Entity)) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } @@ -71,11 +71,9 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter DisguiseAPI.disguiseToAll((Player) sender, disguise); if (disguise.isDisguiseInUse()) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Now disguised as a %s"), - disguise.getType().toReadable())); + sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable())); } else { - sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Failed to disguise as a %s"), - disguise.getType().toReadable())); + sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getType().toReadable())); } return true; @@ -143,8 +141,8 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -162,21 +160,18 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!")); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DISG_HELP1.get()); + sender.sendMessage(LibsMsg.CAN_USE_DISGS + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguise player " + "")); + sender.sendMessage(LibsMsg.DISG_HELP2.get()); } - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguise " + "")); + sender.sendMessage(LibsMsg.DISG_HELP3.get()); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "/disguise " + " ")); + sender.sendMessage(LibsMsg.DISG_HELP4.get()); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index aa0a1992..716deefb 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -7,6 +7,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.TranslateType; @@ -28,13 +29,12 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } if (getPermissions(sender).isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -62,8 +62,8 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise); - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "Right click an entity in the next " + DisguiseConfig.getDisguiseEntityExpire() + " " + "seconds to disguise it as a " + disguise.getType().toReadable() + "!")); + sender.sendMessage( + LibsMsg.DISG_ENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire(), disguise.getType().toReadable())); return true; } @@ -135,8 +135,8 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -158,21 +158,18 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!")); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DISG_ENT_HELP1.get()); + sender.sendMessage(LibsMsg.DISG_ENT_HELP2 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguiseentity player ")); + sender.sendMessage(LibsMsg.DISG_ENT_HELP3.get()); } - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguiseentity ")); + sender.sendMessage(LibsMsg.DISG_ENT_HELP4.get()); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "/disguiseentity " + "")); + sender.sendMessage(LibsMsg.DISG_ENT_HELP5.get()); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index 111d5958..041c2dbf 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -4,6 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.TranslateType; @@ -24,8 +25,8 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) { - HashMap, Boolean>> permMap = DisguiseParser.getPermissions(sender, - "libsdisguises." + node + "."); + HashMap, Boolean>> permMap = DisguiseParser + .getPermissions(sender, "libsdisguises." + node + "."); if (!permMap.isEmpty()) { if (args.length == 0) { @@ -45,9 +46,8 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl if (help != null) { if (help.isEnums()) { - sender.sendMessage( - ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + StringUtils.join( - help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN)); + sender.sendMessage(ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + StringUtils + .join(help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN)); } else { sender.sendMessage( ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + help.getDescription()); @@ -58,14 +58,12 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]); if (type == null) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the disguise ") + args[0]); + sender.sendMessage(LibsMsg.DHELP_CANTFIND.get(args[0])); return true; } if (!permMap.containsKey(type)) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You do not have permission for " + "that disguise!")); + sender.sendMessage(LibsMsg.NO_PERM_DISGUISE.get()); return true; } @@ -109,12 +107,13 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl if (declaring == LivingWatcher.class) { methodColor = ChatColor.AQUA; - } else if (!(FlagWatcher.class.isAssignableFrom( - declaring)) || declaring == FlagWatcher.class) { + } else if (!(FlagWatcher.class + .isAssignableFrom(declaring)) || declaring == FlagWatcher.class) { methodColor = ChatColor.GRAY; } - String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")"; + String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info + .getName() + ChatColor.DARK_RED + ")"; map.put(str, methodColor); methods.add(str); @@ -134,13 +133,11 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl methods.add(ChatColor.RED + "No options with permission to use"); } - sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + TranslateType.MESSAGE.get( - " options: ") + StringUtils.join(methods, ChatColor.DARK_RED + ", ")); + sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(), + StringUtils.join(methods, ChatColor.DARK_RED + ", "))); if (ignored > 0) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Ignored %s" + " options you do not have permission to use. Add " + "'show' to view unusable options."), - ignored)); + sender.sendMessage(LibsMsg.NO_PERMS_USE_OPTIONS.get(ignored)); } return true; @@ -148,7 +145,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl } } - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -158,8 +155,8 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl String[] args = getArgs(origArgs); for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) { - HashMap, Boolean>> perms = DisguiseParser.getPermissions(sender, - "libsdisguises." + node + "."); + HashMap, Boolean>> perms = DisguiseParser + .getPermissions(sender, "libsdisguises." + node + "."); if (args.length == 0) { for (DisguisePerm type : perms.keySet()) { @@ -186,12 +183,10 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl @Override protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "/disguisehelp " + ChatColor.GREEN + "- View the options you can set " + "on a disguise. Add 'show' to reveal the options you don't have permission to use")); + sender.sendMessage(LibsMsg.DHELP_HELP1.get()); for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ", - "") + ChatColor.GREEN + " - " + s.getDescription())); + sender.sendMessage(LibsMsg.DHELP_HELP2.get(s.getName().replaceAll(" ", ""), s.getDescription())); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java index 72a3e4a6..db33f34e 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java @@ -6,6 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.TranslateType; @@ -27,15 +28,14 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Entity)) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -47,18 +47,19 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); if (disguise == null) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are not disguised!")); + sender.sendMessage(LibsMsg.NOT_DISGUISED.get()); return true; } if (!map.containsKey(new DisguisePerm(disguise.getType()))) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "No permission to modify your disguise!")); + sender.sendMessage(LibsMsg.DMODIFY_NO_PERM.get()); return true; } try { - DisguiseParser.callMethods(sender, disguise, - getPermissions(sender).get(new DisguisePerm(disguise.getType())), new ArrayList(), args); + DisguiseParser + .callMethods(sender, disguise, getPermissions(sender).get(new DisguisePerm(disguise.getType())), + new ArrayList(), args); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -72,7 +73,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom return true; } - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Your disguise has been modified!")); + sender.sendMessage(LibsMsg.DMODIFY_MODIFIED.get()); return true; } @@ -152,12 +153,9 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Modify your own disguise as you wear " + "it!")); - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true")); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DMODIFY_HELP3.get()); + sender.sendMessage(LibsMsg.DMODIFY_HELP3.get()); + sender.sendMessage(LibsMsg.DMODIFY_HELP3 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java index ed262ba1..ab0dbfe8 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.TranslateType; @@ -23,13 +24,12 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } if (getPermissions(sender).isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -40,9 +40,7 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements LibsDisguises.getInstance().getListener().setDisguiseModify(sender.getName(), args); - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Right click a disguised entity " + "in the next %s seconds to modify their disguise!"), - DisguiseConfig.getDisguiseEntityExpire())); + sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire())); return true; } @@ -89,8 +87,8 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - perm.getType().getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(perm.getType().getWatcherClass())) { tabs.add(method.getName()); } } @@ -110,10 +108,8 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!")); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DMODENT_HELP1.get()); + sender.sendMessage(LibsMsg.DMODENT_HELP2 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java index 3574ed20..cb81322d 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java @@ -5,9 +5,9 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -28,7 +28,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -40,9 +40,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s" + "'"), - args[0])); + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); return true; } @@ -63,15 +61,12 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements disguise = DisguiseAPI.getDisguise(player); if (disguise == null) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "The player '%s' is " + "not disguised"), - player.getName())); + sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(player.getName())); return true; } if (!map.containsKey(new DisguisePerm(disguise.getType()))) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You do not have permission to modify this " + "disguise")); + sender.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get()); return true; } @@ -91,8 +86,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements return true; } - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "Modified the disguise of " + player.getName() + "!")); + sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(player.getName())); return true; } @@ -115,9 +109,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s'"), - args[0])); + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); return tabs; } @@ -130,9 +122,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements disguise = DisguiseAPI.getDisguise(player); if (disguise == null) { - sender.sendMessage(String.format( - TranslateType.MESSAGE.get(ChatColor.RED + "The player '%s' " + "is not disguised"), - player.getName())); + sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(player.getName())); return tabs; } @@ -179,8 +169,8 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -198,9 +188,8 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Modify the disguise of another player!")); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DMODPLAYER_HELP1.get()); + sender.sendMessage(LibsMsg.DMODPLAYER_HELP2 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java index f26aa3ba..33e8d88a 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java @@ -3,13 +3,10 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; -import me.libraryaddict.disguise.utilities.ClassGetter; -import me.libraryaddict.disguise.utilities.DisguiseParser; +import me.libraryaddict.disguise.utilities.*; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; -import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -53,15 +50,14 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -79,10 +75,8 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements Collections.sort(classes); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "EntityTypes usable " + "are: %s"), - ChatColor.GREEN + StringUtils.join(classes, - ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + ".")); + sender.sendMessage(LibsMsg.DMODRADIUS_USABLE + .get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); return true; } @@ -107,36 +101,30 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements } if (type == null) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Unrecognised " + "EntityType %s"), - args[0])); + sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); return true; } } } if (args.length == starting + 1) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You need to supply the disguise options as well as the radius" + (starting != 0 ? - " and EntityType" : ""))); + sender.sendMessage( + (starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY).get()); return true; } else if (args.length < 2) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You need to supply a radius as well as " + "the disguise options")); + sender.sendMessage(LibsMsg.DMODRADIUS_NEEDOPTIONS.get()); return true; } if (!isNumeric(args[starting])) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "%s is not a " + "number"), - args[starting])); + sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); return true; } int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius)); + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); radius = maxRadius; } @@ -192,16 +180,13 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements } if (noPermission > 0) { - sender.sendMessage(String.format( - TranslateType.MESSAGE.get(ChatColor.RED + "No permission to modify " + "%s disguises!"), - noPermission)); + sender.sendMessage(LibsMsg.DMODRADIUS_NOPERM.get(noPermission)); } if (modifiedDisguises > 0) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Successfully modified the disguises of %s" + " entities!"), modifiedDisguises)); + sender.sendMessage(LibsMsg.DMODRADIUS.get(modifiedDisguises)); } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Couldn't find any disguised entities!")); + sender.sendMessage(LibsMsg.DMODRADIUS_NOENTS.get()); } return true; @@ -241,8 +226,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius)); + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); radius = maxRadius; } @@ -293,8 +277,8 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -312,31 +296,22 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), maxRadius)); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP1.get(maxRadius)); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP2 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; if (allowedDisguises.contains("player")) { - sender.sendMessage(TranslateType.MESSAGE.get( - (ChatColor.DARK_GREEN + "/disguiseradius player ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get()); } - sender.sendMessage(TranslateType.MESSAGE.get( - (ChatColor.DARK_GREEN + "/disguiseradius ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP4.get()); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(TranslateType.MESSAGE.get( - (ChatColor.DARK_GREEN + "/disguiseradius ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP5.get()); } - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes")); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP6.get()); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index dfb20969..15e8628e 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -8,6 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.TranslateType; @@ -32,7 +33,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -42,16 +43,14 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom } if (args.length == 1) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You need to supply a disguise as well as " + "the player")); + sender.sendMessage(LibsMsg.DPLAYER_SUPPLY.get()); return true; } Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s'"), args[0])); + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); return true; } @@ -81,8 +80,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom } if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the" + " config!")); + sender.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get()); return true; } @@ -100,13 +98,9 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom DisguiseAPI.disguiseToAll(player, disguise); if (disguise.isDisguiseInUse()) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully disguised %s as a %s!"), - player.getName(), disguise.getType().toReadable())); + sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(player.getName(), disguise.getType().toReadable())); } else { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Failed to disguise %s as a %s!"), - player.getName(), disguise.getType().toReadable())); + sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL.get(player.getName(), disguise.getType().toReadable())); } return true; @@ -175,8 +169,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -195,22 +189,18 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!"); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.D_HELP1.get()); + sender.sendMessage(LibsMsg.D_HELP2 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "/disguiseplayer player " + "")); + sender.sendMessage(LibsMsg.D_HELP3.get()); } - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "/disguiseplayer " + " ")); + sender.sendMessage(LibsMsg.D_HELP4.get()); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "/disguiseplayer " + "")); + sender.sendMessage(LibsMsg.D_HELP5.get()); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 60025b45..6730c124 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -5,13 +5,10 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.utilities.ClassGetter; -import me.libraryaddict.disguise.utilities.DisguiseParser; +import me.libraryaddict.disguise.utilities.*; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; -import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -44,15 +41,14 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } HashMap, Boolean>> map = getPermissions(sender); if (map.isEmpty()) { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -70,10 +66,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom Collections.sort(classes); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), - ChatColor.GREEN + StringUtils.join(classes, - ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); + sender.sendMessage(LibsMsg.DRADIUS_ENTITIES + .get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); return true; } @@ -98,36 +92,30 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (type == null) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Unrecognised " + "EntityType %s"), - args[0])); + sender.sendMessage(LibsMsg.DRADIUS_UNRECOG.get(args[0])); return true; } } } if (args.length == starting + 1) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ? - " and EntityType" : ""))); + sender.sendMessage( + (starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY).get()); return true; } else if (args.length < 2) { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "You need to supply a radius as well as " + "the disguise")); + sender.sendMessage(LibsMsg.DRADIUS_NEEDOPTIONS.get()); return true; } if (!isNumeric(args[starting])) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "%s is not a number"), args[starting])); + sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); return true; } int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius)); + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); radius = maxRadius; } @@ -173,7 +161,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) { - if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { + if (disguise.isMiscDisguise() && !DisguiseConfig + .isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { miscDisguises++; continue; } @@ -198,17 +187,13 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (disguisedEntitys > 0) { - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully disguised %s" + " entities!"), - disguisedEntitys)); + sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys)); } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Couldn't find any entities to disguise!")); + sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get()); } if (miscDisguises > 0) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as" + " a non-living has been disabled in the config"), - miscDisguises)); + sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises)); } return true; @@ -299,8 +284,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom if (addMethods) { // If this is a method, add. Else if it can be a param of the previous argument, add. - for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods( - disguiseType.getWatcherClass())) { + for (Method method : ReflectionFlagWatchers + .getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { tabs.add(method.getName()); } } @@ -319,31 +304,20 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom HashMap, Boolean>> map) { ArrayList allowedDisguises = getAllowedDisguises(map); - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), maxRadius)); - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), - ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - - String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; + sender.sendMessage(LibsMsg.DRADIUS_HELP1.get(maxRadius)); + sender.sendMessage(LibsMsg.DRADIUS_HELP2 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { - sender.sendMessage(TranslateType.MESSAGE.get( - (ChatColor.DARK_GREEN + "/disguiseradius player ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); + sender.sendMessage(LibsMsg.DRADIUS_HELP3.get()); } - sender.sendMessage(TranslateType.MESSAGE.get( - (ChatColor.DARK_GREEN + "/disguiseradius ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); + sender.sendMessage(LibsMsg.DRADIUS_HELP4.get()); if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(TranslateType.MESSAGE.get( - (ChatColor.DARK_GREEN + "/disguiseradius ").replace( - "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"))); + sender.sendMessage(LibsMsg.DRADIUS_HELP5.get()); } - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes")); + sender.sendMessage(LibsMsg.DRADIUS_HELP6.get()); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java index 7c38b092..77012e8a 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java @@ -1,5 +1,7 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -7,8 +9,6 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import me.libraryaddict.disguise.DisguiseAPI; - /** * @author Navid */ @@ -17,8 +17,7 @@ public class DisguiseViewSelfCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } @@ -26,10 +25,10 @@ public class DisguiseViewSelfCommand implements CommandExecutor { if (DisguiseAPI.isViewSelfToggled(player)) { DisguiseAPI.setViewDisguiseToggled(player, false); - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "Toggled viewing own disguise off!")); + sender.sendMessage(LibsMsg.VIEW_SELF_ON.get()); } else { DisguiseAPI.setViewDisguiseToggled(player, true); - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "Toggled viewing own disguise on!")); + sender.sendMessage(LibsMsg.VIEW_SELF_OFF.get()); } return true; diff --git a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index 0625174d..d7ee422f 100644 --- a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.Bukkit; @@ -35,7 +36,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { } protected String[] getArgs(String[] args) { - ArrayList newArgs = new ArrayList(); + ArrayList newArgs = new ArrayList<>(); for (int i = 0; i < args.length - 1; i++) { String s = args[i]; @@ -53,8 +54,9 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0) { sender.sendMessage( - ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + Bukkit.getPluginManager().getPlugin( - "LibsDisguises").getDescription().getVersion() + " by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." + ( + ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + Bukkit.getPluginManager() + .getPlugin("LibsDisguises").getDescription() + .getVersion() + " by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." + ( sender.hasPermission("libsdisguises.reload") ? "\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" + "." : "")); @@ -66,14 +68,13 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { if (sender.hasPermission("libsdisguises.reload")) { if (args[0].equalsIgnoreCase("reload")) { LibsDisguises.getInstance().reload(); - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "[LibsDisguises] Reloaded config.")); + sender.sendMessage(LibsMsg.RELOADED_CONFIG.get()); return true; } else { - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?")); + sender.sendMessage(LibsMsg.LIBS_RELOAD_WRONG.get()); } } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); } } return true; diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java index bcaab320..10d27d33 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java @@ -1,5 +1,7 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -8,27 +10,26 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import me.libraryaddict.disguise.DisguiseAPI; - public class UndisguiseCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } + if (sender.hasPermission("libsdisguises.undisguise")) { if (DisguiseAPI.isDisguised((Entity) sender)) { DisguiseAPI.undisguiseToAll((Player) sender); - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are no longer disguised")); + sender.sendMessage(LibsMsg.UNDISG.get()); } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are not disguised!")); + sender.sendMessage(LibsMsg.UNDISG_FAIL.get()); } } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); } + return true; } } diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java index d49d988a..53cfc555 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -12,16 +13,14 @@ public class UndisguiseEntityCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } if (sender.hasPermission("libsdisguises.undisguiseentity")) { LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null); - sender.sendMessage(TranslateType.MESSAGE.get( - ChatColor.RED + "Right click a disguised entity to " + "undisguise them!")); + sender.sendMessage(LibsMsg.UND_ENTITY.get()); } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); } return true; } diff --git a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java index c7537e1e..99f12df5 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java @@ -1,9 +1,8 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.utilities.TranslateType; +import me.libraryaddict.disguise.utilities.LibsMsg; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -57,19 +56,18 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { if (p != null) { if (DisguiseAPI.isDisguised(p)) { DisguiseAPI.undisguiseToAll(p); - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "The player is no longer disguised")); + sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(p.getName())); } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "The player is not disguised!")); + sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(p.getName())); } } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Player not found")); + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); } } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/undisguiseplayer ")); + sender.sendMessage(LibsMsg.UNDISG_PLAYER_HELP.get()); } } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); } return true; } diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java index a01df165..948a30cd 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -29,24 +30,20 @@ public class UndisguiseRadiusCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { - sender.sendMessage( - TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!")); + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; } + if (sender.hasPermission("libsdisguises.undisguiseradius")) { int radius = maxRadius; if (args.length > 0) { if (!isNumeric(args[0])) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! " + ChatColor.GREEN + "%s" + ChatColor.RED + " is not a " + "number!"), - args[0])); + sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0])); return true; } radius = Integer.parseInt(args[0]); if (radius > maxRadius) { - sender.sendMessage(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Limited radius to %s" + "! Don't want to make too much lag right?"), - maxRadius)); + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); radius = maxRadius; } } @@ -61,11 +58,10 @@ public class UndisguiseRadiusCommand implements CommandExecutor { disguisedEntitys++; } } - sender.sendMessage( - String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully undisguised %s entities!"), - disguisedEntitys)); + + sender.sendMessage(LibsMsg.UNDISRADIUS.get(disguisedEntitys)); } else { - sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command.")); + sender.sendMessage(LibsMsg.NO_PERM.get()); } return true; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index 06fdba72..011a8853 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -36,7 +36,7 @@ public class DisguiseParser { super(); } - public DisguiseParseException(LibsMessages message, String... params) { + public DisguiseParseException(LibsMsg message, String... params) { super(message.get(params)); } } @@ -145,9 +145,7 @@ public class DisguiseParser { ArrayList usedOptions) throws DisguiseParseException { if (!passesCheck(sender, optionPermissions, usedOptions)) { - throw new DisguiseParseException( - ChatColor.RED + "You do not have permission to use the option " + usedOptions.get( - usedOptions.size() - 1)); + throw new DisguiseParseException(LibsMsg.D_PARSE_NOPERM, usedOptions.get(usedOptions.size() - 1)); } } @@ -201,7 +199,8 @@ public class DisguiseParser { } public static DisguisePerm[] getDisguisePerms() { - DisguisePerm[] perms = new DisguisePerm[DisguiseType.values().length + DisguiseConfig.getCustomDisguises().size()]; + DisguisePerm[] perms = new DisguisePerm[DisguiseType.values().length + DisguiseConfig.getCustomDisguises() + .size()]; int i = 0; for (DisguiseType disguiseType : DisguiseType.values()) { @@ -467,12 +466,11 @@ public class DisguiseParser { public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args, HashMap, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException { if (permissionMap.isEmpty()) { - throw new DisguiseParseException( - TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this " + "command.")); + throw new DisguiseParseException(LibsMsg.NO_PERM); } if (args.length == 0) { - throw new DisguiseParseException(TranslateType.MESSAGE.get("No arguments defined")); + throw new DisguiseParseException(LibsMsg.PARSE_NO_ARGS); } // How many args to skip due to the disugise being constructed @@ -488,13 +486,10 @@ public class DisguiseParser { disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase()); if (disguise == null) { - throw new DisguiseParseException(String.format( - TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find a disguise under the reference %s"), - args[0])); + throw new DisguiseParseException(LibsMsg.PARSE_NO_REF, args[0]); } } else { - throw new DisguiseParseException(TranslateType.MESSAGE.get( - ChatColor.RED + "You do not have perimssion to use disguise references!")); + throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_REF); } optionPermissions = (permissionMap.containsKey(new DisguisePerm(disguise.getType())) ? @@ -509,24 +504,19 @@ public class DisguiseParser { } if (disguisePerm == null) { - throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " " + "doesn't exist!"), - args[0])); + throw new DisguiseParseException(LibsMsg.PARSE_DISG_NO_EXIST, args[0]); } if (disguisePerm.isUnknown()) { - throw new DisguiseParseException(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!")); + throw new DisguiseParseException(LibsMsg.PARSE_CANT_DISG_UNKNOWN); } if (disguisePerm.getEntityType() == null) { - throw new DisguiseParseException( - TranslateType.MESSAGE.get(ChatColor.RED + "Error! This disguise " + "couldn't be loaded!")); + throw new DisguiseParseException(LibsMsg.PARSE_CANT_LOAD); } if (!permissionMap.containsKey(disguisePerm)) { - throw new DisguiseParseException( - TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use " + "this disguise.")); + throw new DisguiseParseException(LibsMsg.NO_PERM_DISGUISE); } optionPermissions = permissionMap.get(disguisePerm); @@ -538,13 +528,11 @@ public class DisguiseParser { // If he is doing a player disguise if (args.length == 1) { // He needs to give the player name - throw new DisguiseParseException(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! You need " + "to give a player name!")); + throw new DisguiseParseException(LibsMsg.PARSE_SUPPLY_PLAYER); } else { - if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey( - args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) { - throw new DisguiseParseException(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! You don't have permission to use that name!")); + if (!disguiseOptions.isEmpty() && (!disguiseOptions + .containsKey(args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) { + throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_NAME); } args[1] = args[1].replace("\\_", " "); @@ -587,7 +575,8 @@ public class DisguiseParser { if (isInteger(args[1])) { miscId = Integer.parseInt(args[1]); } else { - if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK || disguisePerm.getType() == DisguiseType.DROPPED_ITEM) { + if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK || disguisePerm + .getType() == DisguiseType.DROPPED_ITEM) { for (Material mat : Material.values()) { if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) { miscId = mat.getId(); @@ -611,9 +600,8 @@ public class DisguiseParser { case WITHER_SKULL: break; default: - throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! %s doesn't know" + " " + "what to do with %s!"), - disguisePerm.toReadable(), args[1])); + throw new DisguiseParseException(LibsMsg.PARSE_TOO_MANY_ARGS, + disguisePerm.toReadable(), args[1]); } toSkip++; // If they also defined a data value @@ -622,11 +610,11 @@ public class DisguiseParser { toSkip++; } if (secondArg != null) { - if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm.getType() != DisguiseType.DROPPED_ITEM) { - throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!"), + if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm + .getType() != DisguiseType.DROPPED_ITEM) { + throw new DisguiseParseException(LibsMsg.PARSE_USE_SECOND_NUM, DisguiseType.FALLING_BLOCK.toReadable(), - DisguiseType.DROPPED_ITEM.toReadable())); + DisguiseType.DROPPED_ITEM.toReadable()); } miscData = Integer.parseInt(secondArg); } @@ -645,9 +633,8 @@ public class DisguiseParser { } if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { - throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get( - ChatColor.RED + "Error! You do not have permission to use the parameter %s on the" + " %s disguise!"), - toCheck, disguisePerm.toReadable())); + throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_PARAM, toCheck, + disguisePerm.toReadable()); } } @@ -760,12 +747,7 @@ public class DisguiseParser { } } else if (param == ItemStack.class) { // Parse to itemstack - try { - value = parseToItemstack(valueString); - } - catch (Exception ex) { - throw new DisguiseParseException(String.format(ex.getMessage(), methodName)); - } + value = parseToItemstack(methodName, valueString); } else if (param == ItemStack[].class) { // Parse to itemstack array ItemStack[] items = new ItemStack[4]; @@ -775,7 +757,7 @@ public class DisguiseParser { if (split.length == 4) { for (int a = 0; a < 4; a++) { try { - items[a] = parseToItemstack(split[a]); + items[a] = parseToItemstack(methodName, split[a]); } catch (Exception ex) { throw parseToException( @@ -858,8 +840,8 @@ public class DisguiseParser { } else if (param == RabbitType.class) { try { for (RabbitType type : RabbitType.values()) { - if (type.name().replace("_", "").equalsIgnoreCase( - valueString.replace("_", "").replace(" ", ""))) { + if (type.name().replace("_", "") + .equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) { value = type; break; @@ -927,10 +909,10 @@ public class DisguiseParser { throw storedEx; } - throw new DisguiseParseException(ChatColor.RED + "Cannot find the option " + methodName); + throw new DisguiseParseException(LibsMsg.PARSE_OPTION_NA, methodName); } if (value == null) { - throw new DisguiseParseException(ChatColor.RED + "No value was given for the option " + methodName); + throw new DisguiseParseException(LibsMsg.PARSE_NO_OPTION_VALUE, methodName); } if (!usedOptions.contains(methodName.toLowerCase())) { @@ -949,11 +931,10 @@ public class DisguiseParser { private static DisguiseParseException parseToException(String expectedValue, String receivedInstead, String methodName) { - return new DisguiseParseException( - ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received " + ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName); + return new DisguiseParseException(LibsMsg.PARSE_EXPECTED_RECEIVED, expectedValue, receivedInstead, methodName); } - private static ItemStack parseToItemstack(String string) throws Exception { + private static ItemStack parseToItemstack(String method, String string) throws DisguiseParseException { String[] split = string.split(":", -1); int itemId = -1; @@ -1000,13 +981,13 @@ public class DisguiseParser { boolean myPerms = true; for (String option : usedOptions) { - if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase( - "setInvisible") && DisguiseConfig.isDisabledInvisibility()) { + if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase("setInvisible") && DisguiseConfig + .isDisabledInvisibility()) { myPerms = false; } - if (!(theirPermissions.get(list) && list.contains("*")) && (list.contains( - option) != theirPermissions.get(list))) { + if (!(theirPermissions.get(list) && list.contains("*")) && (list.contains(option) != theirPermissions + .get(list))) { myPerms = false; break; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index f25d05d3..ac0aba3b 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -121,12 +121,10 @@ public class DisguiseUtilities { if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) { String entityName = DisguiseType.getType(toClone).toReadable(); - player.sendMessage( - ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference); - player.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference); + player.sendMessage(LibsMsg.MADE_REF.get(entityName, reference)); + player.sendMessage(LibsMsg.MADE_REF_EXAMPLE.get(reference)); } else { - player.sendMessage( - ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the " + "maximum cloned disguises, or lower the time they last"); + player.sendMessage(LibsMsg.REF_TOO_MANY.get()); } } @@ -247,7 +245,8 @@ public class DisguiseUtilities { checkConflicts(disguise, null); - if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) { + if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise + .isModifyBoundingBox()) { doBoundingBox(disguise); } } @@ -385,8 +384,8 @@ public class DisguiseUtilities { if (entityTrackerEntry == null) return; - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry); + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); // If the tracker exists. Remove himself from his tracker trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent @@ -418,7 +417,9 @@ public class DisguiseUtilities { FakeBoundingBox disguiseBox = disguiseValues.getAdultBox(); if (disguiseValues.getBabyBox() != null) { - if ((disguise.getWatcher() instanceof AgeableWatcher && ((AgeableWatcher) disguise.getWatcher()).isBaby()) || (disguise.getWatcher() instanceof ZombieWatcher && ((ZombieWatcher) disguise.getWatcher()).isBaby())) { + if ((disguise.getWatcher() instanceof AgeableWatcher && ((AgeableWatcher) disguise.getWatcher()) + .isBaby()) || (disguise.getWatcher() instanceof ZombieWatcher && ((ZombieWatcher) disguise + .getWatcher()).isBaby())) { disguiseBox = disguiseValues.getBabyBox(); } } @@ -430,7 +431,8 @@ public class DisguiseUtilities { FakeBoundingBox entityBox = entityValues.getAdultBox(); if (entityValues.getBabyBox() != null) { - if ((entity instanceof Ageable && !((Ageable) entity).isAdult()) || (entity instanceof Zombie && ((Zombie) entity).isBaby())) { + if ((entity instanceof Ageable && !((Ageable) entity) + .isAdult()) || (entity instanceof Zombie && ((Zombie) entity).isBaby())) { entityBox = entityValues.getBabyBox(); } } @@ -622,8 +624,8 @@ public class DisguiseUtilities { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (entityTrackerEntry != null) { - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry); + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException for (Object p : trackedPlayers) { @@ -649,9 +651,9 @@ public class DisguiseUtilities { @Override public void onLookup(WrappedGameProfile gameProfile) { - if (DisguiseAPI.isDisguiseInUse(disguise) && (!gameProfile.getName().equals( - disguise.getSkin() != null ? disguise.getSkin() : - disguise.getName()) || !gameProfile.getProperties().isEmpty())) { + if (DisguiseAPI.isDisguiseInUse(disguise) && (!gameProfile.getName() + .equals(disguise.getSkin() != null ? disguise.getSkin() : disguise.getName()) || !gameProfile + .getProperties().isEmpty())) { disguise.setGameProfile(gameProfile); DisguiseUtilities.refreshTrackers(disguise); @@ -743,8 +745,9 @@ public class DisguiseUtilities { catch (Exception e) { runnables.remove(playerName); - System.out.print( - "[LibsDisguises] Error when fetching " + playerName + "'s uuid from mojang: " + e.getMessage()); + System.out + .print("[LibsDisguises] Error when fetching " + playerName + "'s uuid from mojang: " + e + .getMessage()); } } }); @@ -803,21 +806,22 @@ public class DisguiseUtilities { Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null); Object world = ((List) server.getClass().getField("worlds").get(server)).get(0); - Object bedChunk = ReflectionManager.getNmsClass("Chunk").getConstructor( - ReflectionManager.getNmsClass("World"), int.class, int.class).newInstance(world, 0, 0); + Object bedChunk = ReflectionManager.getNmsClass("Chunk") + .getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class) + .newInstance(world, 0, 0); Field cSection = bedChunk.getClass().getDeclaredField("sections"); cSection.setAccessible(true); - Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, - boolean.class).newInstance(0, true); + Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class) + .newInstance(0, true); - Object block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class).invoke(null, - Material.BED_BLOCK.getId()); + Object block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class) + .invoke(null, Material.BED_BLOCK.getId()); Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class); - Method setType = chunkSection.getClass().getMethod("setType", int.class, int.class, int.class, - ReflectionManager.getNmsClass("IBlockData")); + Method setType = chunkSection.getClass() + .getMethod("setType", int.class, int.class, int.class, ReflectionManager.getNmsClass("IBlockData")); Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class); Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class); @@ -835,8 +839,9 @@ public class DisguiseUtilities { cSection.set(bedChunk, array); - spawnChunk = ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, - bedChunk, 65535).createPacket(bedChunk, 65535); + spawnChunk = ProtocolLibrary.getProtocolManager() + .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, 65535) + .createPacket(bedChunk, 65535); Field threadField = ReflectionManager.getNmsField("MinecraftServer", "primaryThread"); threadField.setAccessible(true); @@ -863,9 +868,9 @@ public class DisguiseUtilities { } public static boolean isDisguiseInUse(Disguise disguise) { - return disguise.getEntity() != null && getDisguises().containsKey( - disguise.getEntity().getUniqueId()) && getDisguises().get(disguise.getEntity().getUniqueId()).contains( - disguise); + return disguise.getEntity() != null && getDisguises() + .containsKey(disguise.getEntity().getUniqueId()) && getDisguises() + .get(disguise.getEntity().getUniqueId()).contains(disguise); } /** @@ -888,8 +893,8 @@ public class DisguiseUtilities { try { PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); - if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player && disguise.getEntity().getName().equalsIgnoreCase( - player)) { + if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player && disguise.getEntity().getName() + .equalsIgnoreCase(player)) { removeSelfDisguise((Player) disguise.getEntity()); if (disguise.isSelfDisguiseVisible()) { @@ -915,11 +920,11 @@ public class DisguiseUtilities { if (entityTrackerEntry == null) return; - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry); + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); - Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", - ReflectionManager.getNmsClass("EntityPlayer")); + Method clear = ReflectionManager + .getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); @@ -975,11 +980,11 @@ public class DisguiseUtilities { final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity); if (entityTrackerEntry != null) { - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", - "trackedPlayers").get(entityTrackerEntry); + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); - Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", - ReflectionManager.getNmsClass("EntityPlayer")); + Method clear = ReflectionManager + .getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); @@ -1052,11 +1057,11 @@ public class DisguiseUtilities { final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (entityTrackerEntry != null) { - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry); + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); - final Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", - ReflectionManager.getNmsClass("EntityPlayer")); + final Method clear = ReflectionManager + .getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); @@ -1100,7 +1105,8 @@ public class DisguiseUtilities { getDisguises().remove(entityId); } - if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) { + if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise + .isModifyBoundingBox()) { doBoundingBox(disguise); } @@ -1175,16 +1181,16 @@ public class DisguiseUtilities { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player); if (entityTrackerEntry != null) { - Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry); + Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); // If the tracker exists. Remove himself from his tracker if (isHashSet(trackedPlayersObj)) { - ((Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player)); + ((Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player)); } else { - ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get( - entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player)); + ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") + .get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player)); } } } @@ -1194,10 +1200,10 @@ public class DisguiseUtilities { // Resend entity metadata else he will be invisible to himself until its resent try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, - ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.ENTITY_METADATA, - player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true).createPacket( - player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true)); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, ProtocolLibrary.getProtocolManager() + .createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), + WrappedDataWatcher.getEntityWatcher(player), true) + .createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true)); } catch (Exception ex) { ex.printStackTrace(); @@ -1214,8 +1220,8 @@ public class DisguiseUtilities { throw new IllegalStateException("Cannot modify disguises on an async thread"); try { - if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible() || !disguise.canSee( - player)) { + if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise + .isSelfDisguiseVisible() || !disguise.canSee(player)) { return; } @@ -1248,8 +1254,8 @@ public class DisguiseUtilities { String ldTeamName = "LD Pushing"; // If the player is in a team already - if (prevTeam != null && !(prevTeam.getName().equals("LD Pushing") || prevTeam.getName().endsWith( - "_LDP"))) { + if (prevTeam != null && !(prevTeam.getName().equals("LD Pushing") || prevTeam.getName() + .endsWith("_LDP"))) { // If we're creating a scoreboard if (pOption == DisguisePushing.CREATE_SCOREBOARD) { // Remember his old team so we can give him it back later @@ -1300,16 +1306,16 @@ public class DisguiseUtilities { } // Add himself to his own entity tracker - Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry); + Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); // Check for code differences in PaperSpigot vs Spigot if (isHashSet(trackedPlayersObj)) { - ((Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( - entityTrackerEntry)).add(ReflectionManager.getNmsEntity(player)); + ((Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry)).add(ReflectionManager.getNmsEntity(player)); } else { - ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get( - entityTrackerEntry)).put(ReflectionManager.getNmsEntity(player), true); + ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") + .get(entityTrackerEntry)).put(ReflectionManager.getNmsEntity(player), true); } ProtocolManager manager = ProtocolLibrary.getProtocolManager(); @@ -1320,8 +1326,8 @@ public class DisguiseUtilities { WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player); sendSelfPacket(player, - manager.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, - true).createPacket(player.getEntityId(), dataWatcher, true)); + manager.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true) + .createPacket(player.getEntityId(), dataWatcher, true)); boolean isMoving = false; @@ -1339,64 +1345,68 @@ public class DisguiseUtilities { Vector velocity = player.getVelocity(); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(), - velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(), velocity.getX(), - velocity.getY(), velocity.getZ())); + velocity.getY(), velocity.getZ()) + .createPacket(player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ())); } // Why the hell would he even need this. Meh. if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) { - sendSelfPacket(player, manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player, - player.getVehicle()).createPacket(0, player, player.getVehicle())); + sendSelfPacket(player, + manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player, player.getVehicle()) + .createPacket(0, player, player.getVehicle())); } else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) { - sendSelfPacket(player, manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player.getPassenger(), - player).createPacket(0, player.getPassenger(), player)); + sendSelfPacket(player, + manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player.getPassenger(), player) + .createPacket(0, player.getPassenger(), player)); } sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(new ItemStack(Material.STONE))).createPacket(player.getEntityId(), - ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(player.getInventory().getHelmet()))); + ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), + ReflectionManager.getNmsItem(player.getInventory().getHelmet()))); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(new ItemStack(Material.STONE))).createPacket(player.getEntityId(), - ReflectionManager.createEnumItemSlot(EquipmentSlot.CHEST), - ReflectionManager.getNmsItem(player.getInventory().getChestplate()))); + ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.CHEST), + ReflectionManager.getNmsItem(player.getInventory().getChestplate()))); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(new ItemStack(Material.STONE))).createPacket(player.getEntityId(), - ReflectionManager.createEnumItemSlot(EquipmentSlot.LEGS), - ReflectionManager.getNmsItem(player.getInventory().getLeggings()))); + ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.LEGS), + ReflectionManager.getNmsItem(player.getInventory().getLeggings()))); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(new ItemStack(Material.STONE))).createPacket(player.getEntityId(), - ReflectionManager.createEnumItemSlot(EquipmentSlot.FEET), - ReflectionManager.getNmsItem(player.getInventory().getBoots()))); + ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.FEET), + ReflectionManager.getNmsItem(player.getInventory().getBoots()))); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(new ItemStack(Material.STONE))).createPacket(player.getEntityId(), - ReflectionManager.createEnumItemSlot(EquipmentSlot.HAND), - ReflectionManager.getNmsItem(player.getInventory().getItemInMainHand()))); + ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HAND), + ReflectionManager.getNmsItem(player.getInventory().getItemInMainHand()))); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD), - ReflectionManager.getNmsItem(new ItemStack(Material.STONE))).createPacket(player.getEntityId(), - ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND), - ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand()))); + ReflectionManager.getNmsItem(new ItemStack(Material.STONE))) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND), + ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand()))); Location loc = player.getLocation(); // If the disguised is sleeping for w/e reason if (player.isSleeping()) { - sendSelfPacket(player, manager.createPacketConstructor(Server.BED, player, - ReflectionManager.getBlockPosition(0, 0, 0)).createPacket(player, - ReflectionManager.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))); + sendSelfPacket(player, + manager.createPacketConstructor(Server.BED, player, ReflectionManager.getBlockPosition(0, 0, 0)) + .createPacket(player, ReflectionManager + .getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))); } // Resend any active potion effects for (PotionEffect potionEffect : player.getActivePotionEffects()) { Object mobEffect = ReflectionManager.createMobEffect(potionEffect); - sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EFFECT, player.getEntityId(), - mobEffect).createPacket(player.getEntityId(), mobEffect)); + sendSelfPacket(player, + manager.createPacketConstructor(Server.ENTITY_EFFECT, player.getEntityId(), mobEffect) + .createPacket(player.getEntityId(), mobEffect)); } } catch (Exception ex) { @@ -1449,8 +1459,8 @@ public class DisguiseUtilities { Entity e = disguise.getEntity(); // If the disguises entity is null, or the disguised entity isn't a player return - if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) || !getDisguises().get( - e.getUniqueId()).contains(disguise)) { + if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) || !getDisguises() + .get(e.getUniqueId()).contains(disguise)) { return; } @@ -1465,7 +1475,8 @@ public class DisguiseUtilities { DisguiseUtilities.removeSelfDisguise(player); // If the disguised player can't see himself. Return - if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() || player.getVehicle() != null) { + if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() || player + .getVehicle() != null) { return; } diff --git a/src/me/libraryaddict/disguise/utilities/LibsMessages.java b/src/me/libraryaddict/disguise/utilities/LibsMessages.java deleted file mode 100644 index 86fad618..00000000 --- a/src/me/libraryaddict/disguise/utilities/LibsMessages.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.libraryaddict.disguise.utilities; - -/** - * Created by libraryaddict on 15/06/2017. - */ -public enum LibsMessages { - // Format being CLASS_STRING. So no perm = DISG_COMMAND_NO_PERM. Or DISG_PARSE_NO_PERM_OPTION - TEST("This is a test string"); - - private String string; - - LibsMessages(String string) { - this.string = string; - } - - public String get(String... strings) { - if (strings.length == 0) - return TranslateType.MESSAGE.get(string); - - return String.format(TranslateType.MESSAGE.get(string), (Object[]) strings); - } -} diff --git a/src/me/libraryaddict/disguise/utilities/LibsMsg.java b/src/me/libraryaddict/disguise/utilities/LibsMsg.java new file mode 100644 index 00000000..512099fc --- /dev/null +++ b/src/me/libraryaddict/disguise/utilities/LibsMsg.java @@ -0,0 +1,180 @@ +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. + */ +public enum LibsMsg { + // Format being CLASS_STRING. So no perm = DISG_COMMAND_NO_PERM. Or DISG_PARSE_NO_PERM_OPTION + DHELP_OPTIONS("%s options: %s"), NO_PERMS_USE_OPTIONS( + ChatColor.RED + "Ignored %s" + " options you do not have " + "permission to use. Add " + "'show' to view unusable options."), + DISG_HELP4(ChatColor.DARK_GREEN + "/disguise " + " "), + DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"), + NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for " + "that disguise!"), + DISG_ENT_HELP1(ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!"), + DISG_ENT_HELP2(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), + DISG_ENT_HELP3(ChatColor.DARK_GREEN + "/disguiseentity player "), + DISG_ENT_HELP4(ChatColor.DARK_GREEN + "/disguiseentity "), + DISG_ENT_HELP5(ChatColor.DARK_GREEN + "/disguiseentity " + ""), + DISG_ENT_CLICK(ChatColor.RED + "Right click an entity in the next %s seconds to disguise it as a %s!"), + DISG_HELP3(ChatColor.DARK_GREEN + "/disguise " + ""), + DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s" + " entities!"), + DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"), + DMODRADIUS_NOPERM(ChatColor.RED + "No " + "permission to modify " + "%s disguises!"), + DISG_HELP2(ChatColor.DARK_GREEN + "/disguise player " + ""), + DISG_HELP1(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"), + CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises: %s"), + DISGUISED(ChatColor.RED + "Now " + "disguised as a %s"), + DHELP_HELP2(ChatColor.RED + "/disguisehelp %s" + ChatColor.GREEN + " - %s"), DHELP_HELP1( + ChatColor.RED + "/disguisehelp " + " " + ChatColor.GREEN + "- View the options you can set " + "on a disguise. Add 'show' to reveal the options you don't have permission to use"), + FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"), CLONE_HELP1( + ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other " + "disguise commands!"), + CLONE_HELP2( + ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players " + "able to use disguise references."), + CLONE_HELP3( + ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"), + RELOADED_CONFIG(ChatColor.GREEN + "[LibsDisguises] Reloaded config."), + DMODIFY_NO_PERM(ChatColor.RED + "No " + "permission to modify your disguise!"), + DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"), + DMODIFY_HELP1(ChatColor.DARK_GREEN + "Modify your own disguise as you wear " + "it!"), + DMODIFY_HELP2(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"), + DMODIFY_HELP3(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), DMODIFYENT_CLICK( + ChatColor.RED + "Right click a disguised entity " + "in the next %s seconds to modify their disguise!"), + LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"), + DMODENT_HELP1(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"), + DMODENT_HELP2(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), + CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player '%s" + "'"), + PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s" + " and %s" + " uses a second number!"), + PARSE_NO_PERM_PARAM( + ChatColor.RED + "Error! You do not have permission to use the parameter %s on the" + " %s " + "disguise!"), + PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"), + PARSE_OPTION_NA(ChatColor.RED + "Cannot find the option %s"), UPDATE_READY( + ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"), + PARSE_EXPECTED_RECEIVED( + ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"), + DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), + DRADIUS_UNRECOG(ChatColor.RED + "Unrecognised " + "EntityType %s"), + PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know" + " " + "what to do with %s!"), + DISG_PLAYER_AS_DISG(ChatColor.RED + "Successfully disguised %s as a %s!"), + PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"), + DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as " + "the player"), + PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need " + "to give a player name!"), + DISG_PLAYER_AS_DISG_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"), DISABLED_LIVING_TO_MISC( + ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the" + " config!"), + DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), + DMODRADIUS_HELP2(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), DMODRADIUS_HELP3( + (ChatColor.DARK_GREEN + "/disguiseradius player ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP4( + (ChatColor.DARK_GREEN + "/disguiseradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP5( + (ChatColor.DARK_GREEN + "/disguiseradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP6( + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes"), + UND_ENTITY(ChatColor.RED + "Right click a disguised entity to " + "undisguise them!"), + UNDISG_PLAYER(ChatColor.RED + "%s is no longer disguised"), + LISTEN_ENTITY_PLAYER_DISG_PLAYER(ChatColor.RED + "Disguised the player %s as the player %s!"), + LISTEN_ENTITY_PLAYER_DISG_ENTITY(ChatColor.RED + "Disguised the player %s as a %s!"), + LISTEN_ENTITY_ENTITY_DISG_PLAYER(ChatColor.RED + "Disguised s %s as the player %s!"), + LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised s %s as a %s!"), + LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise the player %s as the player %s!"), + LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise the player %s as a %s!"), + LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise s %s as the player %s!"), + LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise s %s as a %s!"), + LISTEN_UNDISG_PLAYER(ChatColor.RED + "Undisguised %s"), LISTEN_UNDISG_ENT(ChatColor.RED + "Undisguised the %s"), + LISTEN_UNDISG_PLAYER_FAIL(ChatColor.RED + "The %s isn't disguised!"), + MADE_REF(ChatColor.RED + "Constructed a %s disguise! Your reference is %s"), + MADE_REF_EXAMPLE(ChatColor.RED + "Example usage: /disguise %s"), REF_TOO_MANY( + ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the " + "maximum " + "cloned disguises, or lower the time they last"), + LISTEN_UNDISG_ENT_FAIL(ChatColor.RED + "%s isn't disguised!"), + UNDISG_PLAYER_FAIL(ChatColor.RED + "%s not disguised!"), + UNDISG_PLAYER_HELP(ChatColor.RED + "/undisguiseplayer "), + DMODPLAYER_NODISGUISE(ChatColor.RED + "The " + "player '%s' is " + "not disguised"), + DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this " + "disguise"), + DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"), + LISTENER_MODIFIED_DISG(ChatColor.RED + "Modified the disguise!"), + DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"), + DMODPLAYER_HELP2(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), + NO_PERM(ChatColor.RED + "You are forbidden to use this command."), + NOT_DISGUISED(ChatColor.RED + "You are not disguised!"), + DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), + DRADIUS_HELP2(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), DRADIUS_HELP3( + (ChatColor.DARK_GREEN + "/disguiseradius player ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP4( + (ChatColor.DARK_GREEN + "/disguiseradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP5( + (ChatColor.DARK_GREEN + "/disguiseradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP6( + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes"), + D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"), + PARSE_NO_ARGS("No arguments defined"), + PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference " + "%s"), + PARSE_NO_PERM_REF(ChatColor.RED + "You do not have perimssion to use disguise references!"), PARSE_DISG_NO_EXIST( + ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " " + "doesn't exist!"), + PARSE_CANT_DISG_UNKNOWN(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"), + PARSE_CANT_LOAD(ChatColor.RED + "Error! This disguise " + "couldn't be loaded!"), + D_HELP1(ChatColor.DARK_GREEN + "Disguise another player!"), + D_HELP2(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), + DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable " + "are: %s" + ChatColor.DARK_GREEN + "."), + D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer player " + ""), + D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer " + " "), + D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer " + ""), + DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised " + "EntityType %s"), + DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"), + DRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply a disguise as well as the radius"), + DRADIUS_NEEDOPTIONS_ENTITY(ChatColor.RED + "You need to supply a disguise as well as the radius and EntityType"), + NOT_NUMBER(ChatColor.RED + "Error! %s is not a " + "number"), DRADIUS_MISCDISG( + ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity " + "as" + " a non-living has been disabled in the config"), + LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), + DISRADIUS(ChatColor.RED + "Successfully disguised %s" + " entities!"), + DISRADIUS_FAIL(ChatColor.RED + "Couldn't find any entities to disguise!"), DMODRADIUS_NEEDOPTIONS_ENTITY( + ChatColor.RED + "You need to " + "supply" + " the disguise options as well as the radius" + " and EntityType"), + NO_CONSOLE(ChatColor.RED + "You may not use this command from the console!"), CLICK_TIMER( + ChatColor.RED + "Right click a entity in the next %s" + " " + "seconds " + "to " + "grab " + "the disguise reference!"), + UNDISRADIUS(ChatColor.RED + "Successfully undisguised %s entities!"), + UNDISG(ChatColor.RED + "You are no longer disguised"), UNDISG_FAIL(ChatColor.RED + "You are not disguised!"), + VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise off!"), + BLOWN_DISGUISE(ChatColor.RED + "Your disguise" + " was blown!"), + VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise on!"), INVALID_CLONE( + ChatColor.DARK_RED + "Unknown " + "option '%s" + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); + + static { + for (LibsMsg msg : values()) { + for (LibsMsg msg1 : values()) { + if (msg == msg1) + continue; + + if (!msg.getRaw().equalsIgnoreCase(msg1.getRaw())) + continue; + + System.out.println(msg.name() + " and " + msg1.name() + " conflict"); + } + } + + System.out.println("Alright dont forget to delete this libraryaddict!!!!!!!!!!!!!!!!!!"); + } + + private String string; + + LibsMsg(String string) { + this.string = string; + } + + public String getRaw() { + return string; + } + + public String get(Object... strings) { + if (strings.length == 0) + return TranslateType.MESSAGE.get(getRaw()); + + return String.format(TranslateType.MESSAGE.get(getRaw()), (Object[]) strings); + } + + public String toString() { + throw new RuntimeException("Dont call this"); + } +} diff --git a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java index d6c8a9a2..cd5386be 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java @@ -47,5 +47,9 @@ public class TranslateFiller { "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s")); } } + + for (LibsMsg msg : LibsMsg.values()) { + TranslateType.MESSAGE.get(msg.getRaw()); + } } } diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java index b6f99e4b..7b64fcca 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateType.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -2,6 +2,7 @@ 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; @@ -56,7 +57,7 @@ public enum TranslateType { if (value == null) System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'"); else - translated.put(key, value); + translated.put(key, ChatColor.translateAlternateColorCodes('&', value)); } } catch (Exception e) { @@ -74,7 +75,7 @@ public enum TranslateType { translated.put(message, message); - message = StringEscapeUtils.escapeJava(message); + message = StringEscapeUtils.escapeJava(message.replaceAll(ChatColor.COLOR_CHAR + "", "&")); try { boolean exists = file.exists(); @@ -112,26 +113,24 @@ public enum TranslateType { return translated; } - public String get(String message) { + public String get(String msg) { if (this != TranslateType.MESSAGE) - throw new IllegalArgumentException("Can't set no comment for '" + message + "'"); + throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); - return get(message, null); + return get(msg, null); } - public String get(String message, String comment) { + public String get(String msg, String comment) { if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) - return message; - System.out.println("1"); - - String msg = translated.get(message); - - if (msg != null) return msg; - System.out.println("2"); - save(message, comment); + String toReturn = translated.get(msg); - return message; + if (toReturn != null) + return toReturn; + + save(msg, comment); + + return msg; } } From 245faf1803c80d529b9410cb5f7982a783184a19 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 20 Jun 2017 05:19:46 +1200 Subject: [PATCH 4/7] Fix up the last of the errors --- .../commands/DisguiseEntityCommand.java | 2 +- .../commands/DisguiseModifyEntityCommand.java | 2 +- .../commands/DisguiseModifyPlayerCommand.java | 2 +- .../commands/DisguiseModifyRadiusCommand.java | 4 +- .../commands/DisguisePlayerCommand.java | 2 +- .../commands/DisguiseRadiusCommand.java | 4 +- .../disguise/commands/UndisguiseCommand.java | 2 +- .../disguise/utilities/LibsMsg.java | 131 ++++++++---------- .../disguise/utilities/TranslateType.java | 1 - 9 files changed, 63 insertions(+), 87 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index 716deefb..b06e0e6c 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -159,7 +159,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(LibsMsg.DISG_ENT_HELP1.get()); - sender.sendMessage(LibsMsg.DISG_ENT_HELP2 + sender.sendMessage(LibsMsg.CAN_USE_DISGS .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java index ab0dbfe8..d4cb0d43 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java @@ -109,7 +109,7 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(LibsMsg.DMODENT_HELP1.get()); - sender.sendMessage(LibsMsg.DMODENT_HELP2 + sender.sendMessage(LibsMsg.DMODIFY_HELP3 .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java index cb81322d..86332a17 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java @@ -189,7 +189,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(LibsMsg.DMODPLAYER_HELP1.get()); - sender.sendMessage(LibsMsg.DMODPLAYER_HELP2 + sender.sendMessage(LibsMsg.DMODIFY_HELP3 .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); } } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java index 33e8d88a..6cc2462e 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java @@ -297,13 +297,13 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(LibsMsg.DMODRADIUS_HELP1.get(maxRadius)); - sender.sendMessage(LibsMsg.DMODRADIUS_HELP2 + sender.sendMessage(LibsMsg.DMODIFY_HELP3 .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; if (allowedDisguises.contains("player")) { - sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get()); + sender.sendMessage(LibsMsg.DRADIUS_HELP3.get()); } sender.sendMessage(LibsMsg.DMODRADIUS_HELP4.get()); diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 15e8628e..cf6cc0df 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -190,7 +190,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(LibsMsg.D_HELP1.get()); - sender.sendMessage(LibsMsg.D_HELP2 + sender.sendMessage(LibsMsg.CAN_USE_DISGS .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 6730c124..1225f998 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -92,7 +92,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (type == null) { - sender.sendMessage(LibsMsg.DRADIUS_UNRECOG.get(args[0])); + sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); return true; } } @@ -305,7 +305,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom ArrayList allowedDisguises = getAllowedDisguises(map); sender.sendMessage(LibsMsg.DRADIUS_HELP1.get(maxRadius)); - sender.sendMessage(LibsMsg.DRADIUS_HELP2 + sender.sendMessage(LibsMsg.CAN_USE_DISGS .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); if (allowedDisguises.contains("player")) { diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java b/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java index 10d27d33..62d000f9 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java @@ -24,7 +24,7 @@ public class UndisguiseCommand implements CommandExecutor { DisguiseAPI.undisguiseToAll((Player) sender); sender.sendMessage(LibsMsg.UNDISG.get()); } else { - sender.sendMessage(LibsMsg.UNDISG_FAIL.get()); + sender.sendMessage(LibsMsg.NOT_DISGUISED.get()); } } else { sender.sendMessage(LibsMsg.NO_PERM.get()); diff --git a/src/me/libraryaddict/disguise/utilities/LibsMsg.java b/src/me/libraryaddict/disguise/utilities/LibsMsg.java index 512099fc..35b21397 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsMsg.java +++ b/src/me/libraryaddict/disguise/utilities/LibsMsg.java @@ -11,70 +11,66 @@ import java.util.ArrayList; public enum LibsMsg { // Format being CLASS_STRING. So no perm = DISG_COMMAND_NO_PERM. Or DISG_PARSE_NO_PERM_OPTION DHELP_OPTIONS("%s options: %s"), NO_PERMS_USE_OPTIONS( - ChatColor.RED + "Ignored %s" + " options you do not have " + "permission to use. Add " + "'show' to view unusable options."), - DISG_HELP4(ChatColor.DARK_GREEN + "/disguise " + " "), + ChatColor.RED + "Ignored %s options you do not have permission to use. Add 'show' to view unusable options."), + DISG_HELP4(ChatColor.DARK_GREEN + "/disguise "), DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"), - NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for " + "that disguise!"), + NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"), DISG_ENT_HELP1(ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!"), - DISG_ENT_HELP2(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), DISG_ENT_HELP3(ChatColor.DARK_GREEN + "/disguiseentity player "), DISG_ENT_HELP4(ChatColor.DARK_GREEN + "/disguiseentity "), - DISG_ENT_HELP5(ChatColor.DARK_GREEN + "/disguiseentity " + ""), + DISG_ENT_HELP5(ChatColor.DARK_GREEN + "/disguiseentity "), DISG_ENT_CLICK(ChatColor.RED + "Right click an entity in the next %s seconds to disguise it as a %s!"), - DISG_HELP3(ChatColor.DARK_GREEN + "/disguise " + ""), - DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s" + " entities!"), + DISG_HELP3(ChatColor.DARK_GREEN + "/disguise "), + DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s entities!"), DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"), - DMODRADIUS_NOPERM(ChatColor.RED + "No " + "permission to modify " + "%s disguises!"), - DISG_HELP2(ChatColor.DARK_GREEN + "/disguise player " + ""), + DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"), + DISG_HELP2(ChatColor.DARK_GREEN + "/disguise player "), DISG_HELP1(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"), CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises: %s"), - DISGUISED(ChatColor.RED + "Now " + "disguised as a %s"), + DISGUISED(ChatColor.RED + "Now disguised as a %s"), DHELP_HELP2(ChatColor.RED + "/disguisehelp %s" + ChatColor.GREEN + " - %s"), DHELP_HELP1( - ChatColor.RED + "/disguisehelp " + " " + ChatColor.GREEN + "- View the options you can set " + "on a disguise. Add 'show' to reveal the options you don't have permission to use"), + ChatColor.RED + "/disguisehelp " + ChatColor.GREEN + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"), FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"), CLONE_HELP1( - ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other " + "disguise commands!"), + ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other disguise commands!"), CLONE_HELP2( - ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players " + "able to use disguise references."), + ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players able to use disguise references."), CLONE_HELP3( ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"), RELOADED_CONFIG(ChatColor.GREEN + "[LibsDisguises] Reloaded config."), - DMODIFY_NO_PERM(ChatColor.RED + "No " + "permission to modify your disguise!"), + DMODIFY_NO_PERM(ChatColor.RED + "No permission to modify your disguise!"), DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"), - DMODIFY_HELP1(ChatColor.DARK_GREEN + "Modify your own disguise as you wear " + "it!"), + DMODIFY_HELP1(ChatColor.DARK_GREEN + "Modify your own disguise as you wear it!"), DMODIFY_HELP2(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"), - DMODIFY_HELP3(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), DMODIFYENT_CLICK( - ChatColor.RED + "Right click a disguised entity " + "in the next %s seconds to modify their disguise!"), + DMODIFY_HELP3(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), + DMODIFYENT_CLICK(ChatColor.RED + "Right click a disguised entity in the next %s seconds to modify their disguise!"), LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"), DMODENT_HELP1(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"), - DMODENT_HELP2(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), - CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player '%s" + "'"), - PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s" + " and %s" + " uses a second number!"), + CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player '%s'"), + PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s and %s uses a second number!"), PARSE_NO_PERM_PARAM( - ChatColor.RED + "Error! You do not have permission to use the parameter %s on the" + " %s " + "disguise!"), + ChatColor.RED + "Error! You do not have permission to use the parameter %s on the %s disguise!"), PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"), PARSE_OPTION_NA(ChatColor.RED + "Cannot find the option %s"), UPDATE_READY( ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"), PARSE_EXPECTED_RECEIVED( ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"), DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), - DRADIUS_UNRECOG(ChatColor.RED + "Unrecognised " + "EntityType %s"), - PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know" + " " + "what to do with %s!"), + PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"), DISG_PLAYER_AS_DISG(ChatColor.RED + "Successfully disguised %s as a %s!"), PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"), - DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as " + "the player"), - PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need " + "to give a player name!"), + DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player"), + PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"), DISG_PLAYER_AS_DISG_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"), DISABLED_LIVING_TO_MISC( - ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the" + " config!"), - DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), - DMODRADIUS_HELP2(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), DMODRADIUS_HELP3( - (ChatColor.DARK_GREEN + "/disguiseradius player ") + ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"), + DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), DMODRADIUS_HELP3( + (ChatColor.DARK_GREEN + "/disguisemodifyradius player ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP4( - (ChatColor.DARK_GREEN + "/disguiseradius ") + (ChatColor.DARK_GREEN + "/disguisemodifyradius ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP5( - (ChatColor.DARK_GREEN + "/disguiseradius ") + (ChatColor.DARK_GREEN + "/disguisemodifyradius ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP6( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes"), - UND_ENTITY(ChatColor.RED + "Right click a disguised entity to " + "undisguise them!"), + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguisemodifyradius EntityTypes"), + UND_ENTITY(ChatColor.RED + "Right click a disguised entity to undisguise them!"), UNDISG_PLAYER(ChatColor.RED + "%s is no longer disguised"), LISTEN_ENTITY_PLAYER_DISG_PLAYER(ChatColor.RED + "Disguised the player %s as the player %s!"), LISTEN_ENTITY_PLAYER_DISG_ENTITY(ChatColor.RED + "Disguised the player %s as a %s!"), @@ -88,74 +84,55 @@ public enum LibsMsg { LISTEN_UNDISG_PLAYER_FAIL(ChatColor.RED + "The %s isn't disguised!"), MADE_REF(ChatColor.RED + "Constructed a %s disguise! Your reference is %s"), MADE_REF_EXAMPLE(ChatColor.RED + "Example usage: /disguise %s"), REF_TOO_MANY( - ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the " + "maximum " + "cloned disguises, or lower the time they last"), + ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the maximum cloned disguises, or lower the time they last"), LISTEN_UNDISG_ENT_FAIL(ChatColor.RED + "%s isn't disguised!"), UNDISG_PLAYER_FAIL(ChatColor.RED + "%s not disguised!"), UNDISG_PLAYER_HELP(ChatColor.RED + "/undisguiseplayer "), - DMODPLAYER_NODISGUISE(ChatColor.RED + "The " + "player '%s' is " + "not disguised"), - DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this " + "disguise"), + DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"), + DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this disguise"), DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"), LISTENER_MODIFIED_DISG(ChatColor.RED + "Modified the disguise!"), DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"), - DMODPLAYER_HELP2(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"), NO_PERM(ChatColor.RED + "You are forbidden to use this command."), NOT_DISGUISED(ChatColor.RED + "You are not disguised!"), - DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), - DRADIUS_HELP2(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), DRADIUS_HELP3( - (ChatColor.DARK_GREEN + "/disguiseradius player ") + DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), DRADIUS_HELP3( + (ChatColor.DARK_GREEN + "/disguiseradius player ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP4( - (ChatColor.DARK_GREEN + "/disguiseradius ") + (ChatColor.DARK_GREEN + "/disguiseradius ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP5( - (ChatColor.DARK_GREEN + "/disguiseradius ") + (ChatColor.DARK_GREEN + "/disguiseradius ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP6( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes"), + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"), D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"), PARSE_NO_ARGS("No arguments defined"), - PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference " + "%s"), + PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference %s"), PARSE_NO_PERM_REF(ChatColor.RED + "You do not have perimssion to use disguise references!"), PARSE_DISG_NO_EXIST( - ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " " + "doesn't exist!"), + ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " doesn't exist!"), PARSE_CANT_DISG_UNKNOWN(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"), - PARSE_CANT_LOAD(ChatColor.RED + "Error! This disguise " + "couldn't be loaded!"), + PARSE_CANT_LOAD(ChatColor.RED + "Error! This disguise couldn't be loaded!"), D_HELP1(ChatColor.DARK_GREEN + "Disguise another player!"), - D_HELP2(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"), - DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable " + "are: %s" + ChatColor.DARK_GREEN + "."), - D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer player " + ""), - D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer " + " "), - D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer " + ""), - DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised " + "EntityType %s"), + DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable are: %s" + ChatColor.DARK_GREEN + "."), + D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer player "), + D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer "), + D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer "), + DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised EntityType %s"), DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"), DRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply a disguise as well as the radius"), DRADIUS_NEEDOPTIONS_ENTITY(ChatColor.RED + "You need to supply a disguise as well as the radius and EntityType"), - NOT_NUMBER(ChatColor.RED + "Error! %s is not a " + "number"), DRADIUS_MISCDISG( - ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity " + "as" + " a non-living has been disabled in the config"), + NOT_NUMBER(ChatColor.RED + "Error! %s is not a number"), DRADIUS_MISCDISG( + ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as a non-living has been disabled in the config"), LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), - DISRADIUS(ChatColor.RED + "Successfully disguised %s" + " entities!"), + DISRADIUS(ChatColor.RED + "Successfully disguised %s entities!"), DISRADIUS_FAIL(ChatColor.RED + "Couldn't find any entities to disguise!"), DMODRADIUS_NEEDOPTIONS_ENTITY( - ChatColor.RED + "You need to " + "supply" + " the disguise options as well as the radius" + " and EntityType"), - NO_CONSOLE(ChatColor.RED + "You may not use this command from the console!"), CLICK_TIMER( - ChatColor.RED + "Right click a entity in the next %s" + " " + "seconds " + "to " + "grab " + "the disguise reference!"), + ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"), + NO_CONSOLE(ChatColor.RED + "You may not use this command from the console!"), + CLICK_TIMER(ChatColor.RED + "Right click a entity in the next %s seconds to grab the disguise reference!"), UNDISRADIUS(ChatColor.RED + "Successfully undisguised %s entities!"), - UNDISG(ChatColor.RED + "You are no longer disguised"), UNDISG_FAIL(ChatColor.RED + "You are not disguised!"), + UNDISG(ChatColor.RED + "You are no longer disguised"), VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise off!"), - BLOWN_DISGUISE(ChatColor.RED + "Your disguise" + " was blown!"), + BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"), VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise on!"), INVALID_CLONE( - ChatColor.DARK_RED + "Unknown " + "option '%s" + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); - - static { - for (LibsMsg msg : values()) { - for (LibsMsg msg1 : values()) { - if (msg == msg1) - continue; - - if (!msg.getRaw().equalsIgnoreCase(msg1.getRaw())) - continue; - - System.out.println(msg.name() + " and " + msg1.name() + " conflict"); - } - } - - System.out.println("Alright dont forget to delete this libraryaddict!!!!!!!!!!!!!!!!!!"); - } + ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); private String string; diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java index 7b64fcca..91b643d4 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateType.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -24,7 +24,6 @@ public enum TranslateType { TranslateType(String fileName) { file = new File("plugins/LibsDisguises/Translations", fileName + ".yml"); - reload(); } public static void reloadTranslations() { From eda46398a9c075eec5ace20bb1df5fbab5f83db1 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 20 Jun 2017 05:44:31 +1200 Subject: [PATCH 5/7] Force everyone to use translations, THEN TAKE IT AWAY --- plugin.yml | 8 +- .../disguise/utilities/LibsMsg.java | 234 ++++++++++-------- .../disguise/utilities/TranslateFiller.java | 22 +- .../disguise/utilities/TranslateType.java | 35 ++- 4 files changed, 175 insertions(+), 124 deletions(-) diff --git a/plugin.yml b/plugin.yml index e4d73461..4b161982 100644 --- a/plugin.yml +++ b/plugin.yml @@ -54,19 +54,19 @@ commands: permission: libsdisguises.seecmd.viewself description: Toggle seeing your own disguise on or off. disguisemodify: - aliases: [dmodify] + aliases: [dmodify, dmod] permission: libsdisguises.seecmd.disguisemodify description: Modify your own disguise disguisemodifyplayer: - aliases: [dmodifyplayer] + aliases: [dmodifyplayer, dmodplayer] permission: libsdisguises.seecmd.disguisemodifyplayer description: Modify the disguise of a player disguisemodifyradius: - aliases: [dmodifyradius] + aliases: [dmodifyradius, dmodradius] permission: libsdisguises.seecmd.disguisemodifyradius description: Modify disguises in a radius disguisemodifyentity: - aliases: [dmodifyentity] + aliases: [dmodifyentity, dmodentity] permission: libsdisguises.seecmd.disguisemodifyentity description: Modify a disguise by right clicking them diff --git a/src/me/libraryaddict/disguise/utilities/LibsMsg.java b/src/me/libraryaddict/disguise/utilities/LibsMsg.java index 35b21397..3725a882 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsMsg.java +++ b/src/me/libraryaddict/disguise/utilities/LibsMsg.java @@ -9,130 +9,148 @@ import java.util.ArrayList; * Created by libraryaddict on 15/06/2017. */ public enum LibsMsg { - // Format being CLASS_STRING. So no perm = DISG_COMMAND_NO_PERM. Or DISG_PARSE_NO_PERM_OPTION - DHELP_OPTIONS("%s options: %s"), NO_PERMS_USE_OPTIONS( - ChatColor.RED + "Ignored %s options you do not have permission to use. Add 'show' to view unusable options."), - DISG_HELP4(ChatColor.DARK_GREEN + "/disguise "), - DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"), - NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"), - DISG_ENT_HELP1(ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!"), - DISG_ENT_HELP3(ChatColor.DARK_GREEN + "/disguiseentity player "), - DISG_ENT_HELP4(ChatColor.DARK_GREEN + "/disguiseentity "), - DISG_ENT_HELP5(ChatColor.DARK_GREEN + "/disguiseentity "), - DISG_ENT_CLICK(ChatColor.RED + "Right click an entity in the next %s seconds to disguise it as a %s!"), - DISG_HELP3(ChatColor.DARK_GREEN + "/disguise "), - DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s entities!"), - DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"), - DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"), - DISG_HELP2(ChatColor.DARK_GREEN + "/disguise player "), - DISG_HELP1(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"), + BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"), CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises: %s"), - DISGUISED(ChatColor.RED + "Now disguised as a %s"), - DHELP_HELP2(ChatColor.RED + "/disguisehelp %s" + ChatColor.GREEN + " - %s"), DHELP_HELP1( - ChatColor.RED + "/disguisehelp " + ChatColor.GREEN + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"), - FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"), CLONE_HELP1( + CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player '%s'"), + CLICK_TIMER(ChatColor.RED + "Right click a entity in the next %s seconds to grab the disguise reference!"), + CLONE_HELP1( ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other disguise commands!"), CLONE_HELP2( ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players able to use disguise references."), CLONE_HELP3( ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"), - RELOADED_CONFIG(ChatColor.GREEN + "[LibsDisguises] Reloaded config."), - DMODIFY_NO_PERM(ChatColor.RED + "No permission to modify your disguise!"), - DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"), - DMODIFY_HELP1(ChatColor.DARK_GREEN + "Modify your own disguise as you wear it!"), - DMODIFY_HELP2(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"), - DMODIFY_HELP3(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), - DMODIFYENT_CLICK(ChatColor.RED + "Right click a disguised entity in the next %s seconds to modify their disguise!"), - LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"), - DMODENT_HELP1(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"), - CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player '%s'"), - PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s and %s uses a second number!"), - PARSE_NO_PERM_PARAM( - ChatColor.RED + "Error! You do not have permission to use the parameter %s on the %s disguise!"), - PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"), - PARSE_OPTION_NA(ChatColor.RED + "Cannot find the option %s"), UPDATE_READY( - ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"), - PARSE_EXPECTED_RECEIVED( - ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"), - DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), - PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"), - DISG_PLAYER_AS_DISG(ChatColor.RED + "Successfully disguised %s as a %s!"), - PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"), - DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player"), - PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"), - DISG_PLAYER_AS_DISG_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"), DISABLED_LIVING_TO_MISC( - ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"), - DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), DMODRADIUS_HELP3( - (ChatColor.DARK_GREEN + "/disguisemodifyradius player ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP4( - (ChatColor.DARK_GREEN + "/disguisemodifyradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP5( - (ChatColor.DARK_GREEN + "/disguisemodifyradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP6( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguisemodifyradius EntityTypes"), - UND_ENTITY(ChatColor.RED + "Right click a disguised entity to undisguise them!"), - UNDISG_PLAYER(ChatColor.RED + "%s is no longer disguised"), - LISTEN_ENTITY_PLAYER_DISG_PLAYER(ChatColor.RED + "Disguised the player %s as the player %s!"), - LISTEN_ENTITY_PLAYER_DISG_ENTITY(ChatColor.RED + "Disguised the player %s as a %s!"), - LISTEN_ENTITY_ENTITY_DISG_PLAYER(ChatColor.RED + "Disguised s %s as the player %s!"), - LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised s %s as a %s!"), - LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise the player %s as the player %s!"), - LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise the player %s as a %s!"), - LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise s %s as the player %s!"), - LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise s %s as a %s!"), - LISTEN_UNDISG_PLAYER(ChatColor.RED + "Undisguised %s"), LISTEN_UNDISG_ENT(ChatColor.RED + "Undisguised the %s"), - LISTEN_UNDISG_PLAYER_FAIL(ChatColor.RED + "The %s isn't disguised!"), - MADE_REF(ChatColor.RED + "Constructed a %s disguise! Your reference is %s"), - MADE_REF_EXAMPLE(ChatColor.RED + "Example usage: /disguise %s"), REF_TOO_MANY( - ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the maximum cloned disguises, or lower the time they last"), - LISTEN_UNDISG_ENT_FAIL(ChatColor.RED + "%s isn't disguised!"), - UNDISG_PLAYER_FAIL(ChatColor.RED + "%s not disguised!"), - UNDISG_PLAYER_HELP(ChatColor.RED + "/undisguiseplayer "), - DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"), - DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this disguise"), - DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"), - LISTENER_MODIFIED_DISG(ChatColor.RED + "Modified the disguise!"), - DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"), - NO_PERM(ChatColor.RED + "You are forbidden to use this command."), - NOT_DISGUISED(ChatColor.RED + "You are not disguised!"), - DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), DRADIUS_HELP3( - (ChatColor.DARK_GREEN + "/disguiseradius player ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP4( - (ChatColor.DARK_GREEN + "/disguiseradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP5( - (ChatColor.DARK_GREEN + "/disguiseradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DRADIUS_HELP6( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"), - D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"), - PARSE_NO_ARGS("No arguments defined"), - PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference %s"), - PARSE_NO_PERM_REF(ChatColor.RED + "You do not have perimssion to use disguise references!"), PARSE_DISG_NO_EXIST( - ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " doesn't exist!"), - PARSE_CANT_DISG_UNKNOWN(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"), - PARSE_CANT_LOAD(ChatColor.RED + "Error! This disguise couldn't be loaded!"), D_HELP1(ChatColor.DARK_GREEN + "Disguise another player!"), - DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable are: %s" + ChatColor.DARK_GREEN + "."), D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer player "), D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer "), D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer "), - DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised EntityType %s"), + D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"), + DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"), + DHELP_HELP1( + ChatColor.RED + "/disguisehelp " + ChatColor.GREEN + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"), + DHELP_HELP2(ChatColor.RED + "/disguisehelp %s" + ChatColor.GREEN + " - %s"), + DHELP_OPTIONS("%s options: %s"), + DISABLED_LIVING_TO_MISC( + ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"), + DISG_ENT_CLICK(ChatColor.RED + "Right click an entity in the next %s seconds to disguise it as a %s!"), + DISG_ENT_HELP1(ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!"), + DISG_ENT_HELP3(ChatColor.DARK_GREEN + "/disguiseentity player "), + DISG_ENT_HELP4(ChatColor.DARK_GREEN + "/disguiseentity "), + DISG_ENT_HELP5(ChatColor.DARK_GREEN + "/disguiseentity "), + DISG_HELP1(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"), + DISG_HELP2(ChatColor.DARK_GREEN + "/disguise player "), + DISG_HELP3(ChatColor.DARK_GREEN + "/disguise "), + DISG_HELP4(ChatColor.DARK_GREEN + "/disguise "), + DISG_PLAYER_AS_DISG(ChatColor.RED + "Successfully disguised %s as a %s!"), + DISG_PLAYER_AS_DISG_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"), + DISGUISED(ChatColor.RED + "Now disguised as a %s"), + DISRADIUS(ChatColor.RED + "Successfully disguised %s entities!"), + DISRADIUS_FAIL(ChatColor.RED + "Couldn't find any entities to disguise!"), + DMODENT_HELP1(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"), + DMODIFY_HELP1(ChatColor.DARK_GREEN + "Modify your own disguise as you wear it!"), + DMODIFY_HELP2(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"), + DMODIFY_HELP3(ChatColor.DARK_GREEN + "You can modify the disguises: %s"), + DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"), + DMODIFY_NO_PERM(ChatColor.RED + "No permission to modify your disguise!"), + DMODIFYENT_CLICK(ChatColor.RED + "Right click a disguised entity in the next %s seconds to modify their disguise!"), + DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"), + DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"), + DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"), + DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this disguise"), + DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s entities!"), + DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), + DMODRADIUS_HELP3( + (ChatColor.DARK_GREEN + "/disguisemodifyradius player ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), + DMODRADIUS_HELP4( + (ChatColor.DARK_GREEN + "/disguisemodifyradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), + DMODRADIUS_HELP5( + (ChatColor.DARK_GREEN + "/disguisemodifyradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), + DMODRADIUS_HELP6( + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguisemodifyradius EntityTypes"), DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"), + DMODRADIUS_NEEDOPTIONS_ENTITY( + ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"), + DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"), + DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"), + DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised EntityType %s"), + DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable are: %s" + ChatColor.DARK_GREEN + "."), + DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player"), + DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), + DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), + DRADIUS_HELP3( + (ChatColor.DARK_GREEN + "/disguiseradius player ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), + DRADIUS_HELP4( + (ChatColor.DARK_GREEN + "/disguiseradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), + DRADIUS_HELP5( + (ChatColor.DARK_GREEN + "/disguiseradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), + DRADIUS_HELP6( + ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"), + DRADIUS_MISCDISG( + ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as a non-living has been disabled in the config"), DRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply a disguise as well as the radius"), DRADIUS_NEEDOPTIONS_ENTITY(ChatColor.RED + "You need to supply a disguise as well as the radius and EntityType"), - NOT_NUMBER(ChatColor.RED + "Error! %s is not a number"), DRADIUS_MISCDISG( - ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as a non-living has been disabled in the config"), + FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"), + INVALID_CLONE( + ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " + "'DoSneak' 'DoSprint'"), + LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"), LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), - DISRADIUS(ChatColor.RED + "Successfully disguised %s entities!"), - DISRADIUS_FAIL(ChatColor.RED + "Couldn't find any entities to disguise!"), DMODRADIUS_NEEDOPTIONS_ENTITY( - ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"), + LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised s %s as a %s!"), + LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise s %s as a %s!"), + LISTEN_ENTITY_ENTITY_DISG_PLAYER(ChatColor.RED + "Disguised s %s as the player %s!"), + LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise s %s as the player %s!"), + LISTEN_ENTITY_PLAYER_DISG_ENTITY(ChatColor.RED + "Disguised the player %s as a %s!"), + LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise the player %s as a %s!"), + LISTEN_ENTITY_PLAYER_DISG_PLAYER(ChatColor.RED + "Disguised the player %s as the player %s!"), + LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise the player %s as the player %s!"), + LISTEN_UNDISG_ENT(ChatColor.RED + "Undisguised the %s"), + LISTEN_UNDISG_ENT_FAIL(ChatColor.RED + "%s isn't disguised!"), + LISTEN_UNDISG_PLAYER(ChatColor.RED + "Undisguised %s"), + LISTEN_UNDISG_PLAYER_FAIL(ChatColor.RED + "The %s isn't disguised!"), + LISTENER_MODIFIED_DISG(ChatColor.RED + "Modified the disguise!"), + MADE_REF(ChatColor.RED + "Constructed a %s disguise! Your reference is %s"), + MADE_REF_EXAMPLE(ChatColor.RED + "Example usage: /disguise %s"), NO_CONSOLE(ChatColor.RED + "You may not use this command from the console!"), - CLICK_TIMER(ChatColor.RED + "Right click a entity in the next %s seconds to grab the disguise reference!"), - UNDISRADIUS(ChatColor.RED + "Successfully undisguised %s entities!"), + NO_PERM(ChatColor.RED + "You are forbidden to use this command."), + NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"), + NO_PERMS_USE_OPTIONS( + ChatColor.RED + "Ignored %s options you do not have permission to use. Add 'show' to view unusable options."), + NOT_DISGUISED(ChatColor.RED + "You are not disguised!"), + NOT_NUMBER(ChatColor.RED + "Error! %s is not a number"), + PARSE_CANT_DISG_UNKNOWN(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"), + PARSE_CANT_LOAD(ChatColor.RED + "Error! This disguise couldn't be loaded!"), + PARSE_DISG_NO_EXIST( + ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " doesn't exist!"), + PARSE_EXPECTED_RECEIVED( + ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"), + PARSE_NO_ARGS("No arguments defined"), + PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"), + PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"), + PARSE_NO_PERM_PARAM( + ChatColor.RED + "Error! You do not have permission to use the parameter %s on the %s disguise!"), + PARSE_NO_PERM_REF(ChatColor.RED + "You do not have perimssion to use disguise references!"), + PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference %s"), + PARSE_OPTION_NA(ChatColor.RED + "Cannot find the option %s"), + PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"), + PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"), + PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s and %s uses a second number!"), + REF_TOO_MANY( + ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please raise the maximum cloned disguises, or lower the time they last"), + RELOADED_CONFIG(ChatColor.GREEN + "[LibsDisguises] Reloaded config."), + UND_ENTITY(ChatColor.RED + "Right click a disguised entity to undisguise them!"), UNDISG(ChatColor.RED + "You are no longer disguised"), - VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise off!"), - BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"), - VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise on!"), INVALID_CLONE( - ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); + UNDISG_PLAYER(ChatColor.RED + "%s is no longer disguised"), + UNDISG_PLAYER_FAIL(ChatColor.RED + "%s not disguised!"), + UNDISG_PLAYER_HELP(ChatColor.RED + "/undisguiseplayer "), + UNDISRADIUS(ChatColor.RED + "Successfully undisguised %s entities!"), + UPDATE_READY( + ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"), + VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise on!"), + VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise off!"); private String string; diff --git a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java index cd5386be..6cad9a74 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java @@ -1,6 +1,8 @@ package me.libraryaddict.disguise.utilities; +import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import org.apache.commons.lang.StringUtils; import org.bukkit.inventory.ItemStack; import java.lang.reflect.Method; @@ -20,12 +22,18 @@ public class TranslateFiller { continue; for (String e : info.getEnums("")) { - TranslateType.METHOD_PARAM.get(e, "Used as a disguise option for " + info.getName()); + TranslateType.METHOD_PARAM.save(e, "Used as a disguise option for " + info.getName()); } } for (DisguiseType type : DisguiseType.values()) { - type.toReadable(); + String[] split = type.name().split("_"); + + for (int i = 0; i < split.length; i++) { + split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); + } + + TranslateType.DISGUISE.save(StringUtils.join(split, " "), "Name for the " + type.name() + " disguise"); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) { Class para = method.getParameterTypes()[0]; @@ -42,14 +50,20 @@ public class TranslateFiller { else if (className.equals("IllagerWizard")) className = "Illager"; - TranslateType.METHOD.get(method.getName(), + TranslateType.METHOD.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.get(msg.getRaw()); + TranslateType.MESSAGE.save(msg.getRaw()); + } + + if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) { + for (TranslateType type : TranslateType.values()) { + type.wipeTranslations(); + } } } } diff --git a/src/me/libraryaddict/disguise/utilities/TranslateType.java b/src/me/libraryaddict/disguise/utilities/TranslateType.java index 91b643d4..c4adbcbf 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateType.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateType.java @@ -18,7 +18,10 @@ 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"); + DISGUISE("disguises"), + MESSAGE("messages"), + METHOD_PARAM("disguise_options"), + METHOD("disguise_option_parameters"); private File file; private HashMap translated = new HashMap<>(); @@ -34,16 +37,20 @@ public enum TranslateType { TranslateFiller.fillConfigs(); } - private void reload() { - if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) - return; - + public void wipeTranslations() { translated.clear(); + } + + private void reload() { + translated.clear(); + + if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) { + System.out.println("[LibsDisguises] Loading translations: " + name()); + } if (!file.exists()) return; - System.out.println("[LibsDisguises] Loading translations: " + name()); YamlConfiguration config = new YamlConfiguration(); config.options().pathSeparator(Character.toChars(0)[0]); @@ -68,7 +75,14 @@ public enum TranslateType { return file; } - private void save(String message, String comment) { + public void save(String msg) { + if (this != TranslateType.MESSAGE) + throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); + + save(msg, null); + } + + public void save(String message, String comment) { if (translated.containsKey(message)) return; @@ -86,9 +100,14 @@ public enum TranslateType { FileWriter writer = new FileWriter(getFile(), true); - if (!exists) + if (!exists) { writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n"); + if (this == TranslateType.MESSAGE) { + writer.write("# %s is where text is inserted, look up printf format codes if you're interested\n"); + } + } + writer.write("\n" + (comment != null ? "# " + comment + "\n" : "") + "\"" + message + "\": \"" + message + "\"\n"); From 9a258670a3cd6be98ea9900cd8b3c0e65ca2046d Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 20 Jun 2017 05:48:58 +1200 Subject: [PATCH 6/7] Um. What the hell? Why unregister this --- src/me/libraryaddict/disguise/LibsDisguises.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 5d44e530..d156fa60 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -133,8 +133,6 @@ public class LibsDisguises extends JavaPlugin { * Reloads the config with new config options. */ public void reload() { - HandlerList.unregisterAll(listener); - reloadConfig(); DisguiseConfig.initConfig(getConfig()); } From 4fe484dc10acbb870535d5a242db7f4561ebd58b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 20 Jun 2017 06:11:08 +1200 Subject: [PATCH 7/7] 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);