Finish up

This commit is contained in:
libraryaddict 2017-06-20 06:11:08 +12:00
parent 9a258670a3
commit 4fe484dc10
7 changed files with 44 additions and 44 deletions

View File

@ -4,8 +4,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.*; import me.libraryaddict.disguise.utilities.*;
@ -20,7 +18,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
@ -81,7 +78,7 @@ public class LibsDisguises extends JavaPlugin {
PacketsManager.addPacketListeners(); PacketsManager.addPacketListeners();
TranslateType.MESSAGE.name(); // Call the static loader TranslateType.MESSAGES.name(); // Call the static loader
listener = new DisguiseListener(this); listener = new DisguiseListener(this);

View File

@ -322,6 +322,6 @@ public enum DisguiseType {
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); 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");
} }
} }

View File

@ -37,7 +37,7 @@ public class DisguiseParser {
} }
public DisguiseParseException(LibsMsg message, String... params) { 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 * Get perms for the node. Returns a hashmap of allowed disguisetypes and their options
*
* @param sender
* @param permissionNode
* @return
*/ */
public static HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> getPermissions(CommandSender sender, public static HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> getPermissions(CommandSender sender,
String permissionNode) { 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 * 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 * commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this point, the
* disguise has been feed a proper disguisetype. * 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, public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException { HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException {
@ -675,8 +664,9 @@ public class DisguiseParser {
Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass()); Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
for (int i = 0; i < args.length; i += 2) { for (int i = 0; i < args.length; i += 2) {
String methodName = args[i]; String methodName = TranslateType.DISGUISE_OPTIONS.reverseGet(args[i]);
String valueString = (args.length - 1 == i ? null : args[i + 1]); String valueString = TranslateType.DISGUISE_OPTIONS_PARAMETERS
.reverseGet(args.length - 1 == i ? null : args[i + 1]);
Method methodToUse = null; Method methodToUse = null;
Object value = null; Object value = null;
DisguiseParseException storedEx = null; DisguiseParseException storedEx = null;
@ -945,7 +935,7 @@ public class DisguiseParser {
try { try {
itemId = Material.valueOf(split[0].toUpperCase()).getId(); itemId = Material.valueOf(split[0].toUpperCase()).getId();
} }
catch (Exception ex) { catch (Exception ignored) {
} }
} }

View File

@ -1,9 +1,6 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
/** /**
* Created by libraryaddict on 15/06/2017. * Created by libraryaddict on 15/06/2017.
@ -164,9 +161,9 @@ public enum LibsMsg {
public String get(Object... strings) { public String get(Object... strings) {
if (strings.length == 0) 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() { public String toString() {

View File

@ -44,8 +44,8 @@ public class ReflectionFlagWatchers {
} }
private ParamInfo(String name, String description) { private ParamInfo(String name, String description) {
this.name = TranslateType.METHOD_PARAM.get(name, null); this.name = name;
this.description = TranslateType.METHOD_PARAM.get(description, null); this.description = description;
} }
public ParamInfo(String className, String name, String description) throws ClassNotFoundException { public ParamInfo(String className, String name, String description) throws ClassNotFoundException {
@ -81,10 +81,20 @@ public class ReflectionFlagWatchers {
} }
public String getName() { public String getName() {
return TranslateType.DISGUISE_OPTIONS_PARAMETERS
.get(getRawName(), "Used as a disguise option for " + getRawName());
}
public String getRawName() {
return name; return name;
} }
public String getDescription() { public String getDescription() {
return TranslateType.DISGUISE_OPTIONS_PARAMETERS
.get(getRawDescription(), "Used as a disguise option for " + getRawDescription());
}
public String getRawDescription() {
return description; return description;
} }
@ -143,7 +153,7 @@ public class ReflectionFlagWatchers {
new ParamInfo(Villager.Profession.class, "Villager Profession", new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a villager"); "View all the professions you can set on a villager");
new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 4), "Direction", 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(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"); new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species");

View File

@ -21,8 +21,12 @@ public class TranslateFiller {
if (info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class) if (info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class)
continue; 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("")) { 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(); 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())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) {
Class para = method.getParameterTypes()[0]; Class para = method.getParameterTypes()[0];
@ -50,14 +54,14 @@ public class TranslateFiller {
else if (className.equals("IllagerWizard")) else if (className.equals("IllagerWizard"))
className = "Illager"; className = "Illager";
TranslateType.METHOD.save(method.getName(), TranslateType.DISGUISE_OPTIONS.save(method.getName(),
"Found in the disguise options for " + className + " and uses " + (para.isArray() ? "Found in the disguise options for " + className + " and uses " + (para.isArray() ?
"multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s")); "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s"));
} }
} }
for (LibsMsg msg : LibsMsg.values()) { for (LibsMsg msg : LibsMsg.values()) {
TranslateType.MESSAGE.save(msg.getRaw()); TranslateType.MESSAGES.save(msg.getRaw());
} }
if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) { if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) {

View File

@ -3,13 +3,10 @@ package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -18,10 +15,11 @@ import java.util.Objects;
* Created by libraryaddict on 10/06/2017. * Created by libraryaddict on 10/06/2017.
*/ */
public enum TranslateType { public enum TranslateType {
DISGUISE("disguises"), DISGUISES("disguises"),
MESSAGE("messages"), MESSAGES("messages"),
METHOD_PARAM("disguise_options"), DISGUISE_OPTIONS("disguise_options"),
METHOD("disguise_option_parameters"); DISGUISE_OPTIONS_PARAMETERS("disguise_option_parameters");
private File file; private File file;
private HashMap<String, String> translated = new HashMap<>(); private HashMap<String, String> translated = new HashMap<>();
@ -63,7 +61,8 @@ public enum TranslateType {
if (value == null) if (value == null)
System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'"); System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'");
else else
translated.put(key, ChatColor.translateAlternateColorCodes('&', value)); translated.put(ChatColor.translateAlternateColorCodes('&', key),
ChatColor.translateAlternateColorCodes('&', value));
} }
} }
catch (Exception e) { catch (Exception e) {
@ -76,7 +75,7 @@ public enum TranslateType {
} }
public void save(String msg) { public void save(String msg) {
if (this != TranslateType.MESSAGE) if (this != TranslateType.MESSAGES)
throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); throw new IllegalArgumentException("Can't set no comment for '" + msg + "'");
save(msg, null); save(msg, null);
@ -103,7 +102,7 @@ public enum TranslateType {
if (!exists) { if (!exists) {
writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n"); 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"); 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) { public String reverseGet(String translated) {
if (translated == null)
return null;
translated = translated.toLowerCase(); translated = translated.toLowerCase();
for (Map.Entry<String, String> entry : this.translated.entrySet()) { for (Map.Entry<String, String> entry : this.translated.entrySet()) {
@ -132,14 +134,14 @@ public enum TranslateType {
} }
public String get(String msg) { public String get(String msg) {
if (this != TranslateType.MESSAGE) if (this != TranslateType.MESSAGES)
throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); throw new IllegalArgumentException("Can't set no comment for '" + msg + "'");
return get(msg, null); return get(msg, null);
} }
public String get(String msg, String comment) { public String get(String msg, String comment) {
if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return msg; return msg;
String toReturn = translated.get(msg); String toReturn = translated.get(msg);