diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index d106339a..fb874901 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -43,7 +43,7 @@ public class LibsDisguises extends JavaPlugin { if (ReflectionManager.getMinecraftVersion().startsWith("1.13")) { if (!LibsPremium.isPremium()) { getLogger().severe("You must purchase the plugin to use 1.13!"); - getLogger().severe("This will be released free two weeks after all bugs have been fixed!"); + getLogger().severe("This will be released two weeks after Spigot is stable!"); getLogger().severe("If you've already purchased the plugin, place the purchased jar inside the " + "Lib's Disguises plugin folder"); getPluginLoader().disablePlugin(this); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfo.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfo.java index dc9ae682..c6c1e4d0 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfo.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfo.java @@ -33,7 +33,7 @@ public abstract class ParamInfo { } public ParamInfo(Class paramClass, String name, String description, Enum[] possibleValues) { - this(paramClass, name, name, description); + this(paramClass, name, name, description, possibleValues); } public ParamInfo(Class paramClass, String name, String descriptiveName, String description, Enum[] possibleValues) { @@ -46,19 +46,16 @@ public abstract class ParamInfo { } } - public ParamInfo(Class paramClass, String name, String description, String[] possibleValues) { - this(paramClass, name, name, description); + public ParamInfo(Class paramClass, String name, String description, Map possibleValues) { + this(paramClass, name, name, description, possibleValues); } public ParamInfo(Class paramClass, String name, String descriptiveName, String description, - String[] possibleValues) { + Map possibleValues) { this(paramClass, name, descriptiveName, description); this.possibleValues = new HashMap<>(); - - for (String value : possibleValues) { - getValues().put(value, value); - } + this.possibleValues.putAll(possibleValues); } public boolean canTranslateValues() { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java index a519951c..7e786d0a 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java @@ -17,9 +17,7 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.EulerAngle; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; /** * Created by libraryaddict on 7/09/2018. @@ -65,7 +63,7 @@ public class ParamInfoTypes { // Register custom types paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", "Set the X,Y,Z directions on an armorstand")); - paramInfos.add(new ParamInfoEnum(Color.class, "Color", "Colors that can also be defined through RGB", + paramInfos.add(new ParamInfoColor(Color.class, "Color", "Colors that can also be defined through RGB", getColors())); paramInfos.add(new ParamInfoEnum(Material.class, "Material", "A material used for blocks and items", getMaterials())); @@ -74,7 +72,7 @@ public class ParamInfoTypes { paramInfos.add(new ParamInfoItemStackArray(ItemStack[].class, "ItemStack[]", "Four ItemStacks (Material:Amount?:Glow?,Material:Amount?:Glow?..)", "Four ItemStacks separated by a comma", getMaterials())); - paramInfos.add(new ParamInfoPotionType(PotionEffectType.class, "Potion Effect", + paramInfos.add(new ParamInfoEnum(PotionEffectType.class, "Potion Effect", "View all the potion effects you can add", getPotions())); paramInfos.add(new ParamInfoBlockPosition(BlockPosition.class, "Block Position", "Block Position (num,num,num)", @@ -84,7 +82,11 @@ public class ParamInfoTypes { ".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false")); // Register base types - paramInfos.add(new ParamInfoBoolean("Boolean", "True/False", "True or False", new String[]{"true", "false"})); + Map booleanMap = new HashMap<>(); + booleanMap.put("true", true); + booleanMap.put("false", false); + + paramInfos.add(new ParamInfoBoolean("Boolean", "True/False", "True or False", booleanMap)); paramInfos.add(new ParamInfoString(String.class, "Text", "A line of text")); paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals")); paramInfos.add(new ParamInfoFloat("Number.0", "A number which can have decimal places")); @@ -93,9 +95,9 @@ public class ParamInfoTypes { return paramInfos; } - private String[] getColors() { + private Map getColors() { try { - List colors = new ArrayList<>(); + Map map = new HashMap<>(); Class cl = Class.forName("org.bukkit.Color"); for (Field field : cl.getFields()) { @@ -103,12 +105,12 @@ public class ParamInfoTypes { continue; } - colors.add(field.getName()); + map.put(field.getName(), field.get(null)); } - return colors.toArray(new String[0]); + return map; } - catch (ClassNotFoundException e) { + catch (ClassNotFoundException | IllegalAccessException e) { e.printStackTrace(); } @@ -137,17 +139,17 @@ public class ParamInfoTypes { return list.toArray(new Material[0]); } - private String[] getPotions() { - List potionEnums = new ArrayList<>(); + private Map getPotions() { + Map map = new HashMap<>(); for (PotionEffectType effectType : PotionEffectType.values()) { if (effectType == null) continue; - potionEnums.add(toReadable(effectType.getName())); + map.put(toReadable(effectType.getName()), effectType); } - return potionEnums.toArray(new String[0]); + return map; } private String toReadable(String string) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/ParamInfoEnum.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/ParamInfoEnum.java index e4153e7f..60451323 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/ParamInfoEnum.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/ParamInfoEnum.java @@ -13,15 +13,15 @@ public class ParamInfoEnum extends ParamInfo { } public ParamInfoEnum(Class paramClass, String name, String valueType, String description, Enum[] possibleValues) { - super(paramClass, name, valueType, description); + super(paramClass, name, valueType, description, possibleValues); } public ParamInfoEnum(Class paramClass, String name, String description, Enum[] possibleValues) { - super(paramClass, name, name, description); + super(paramClass, name, name, description, possibleValues); } - public ParamInfoEnum(Class paramClass, String name, String description, String[] possibleValues) { - super(paramClass, name, name, description); + public ParamInfoEnum(Class paramClass, String name, String description, Map possibleValues) { + super(paramClass, name, name, description, possibleValues); } @Override diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/base/ParamInfoBoolean.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/base/ParamInfoBoolean.java index 684470fc..22cb51f3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/base/ParamInfoBoolean.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/base/ParamInfoBoolean.java @@ -4,12 +4,13 @@ import me.libraryaddict.disguise.utilities.TranslateType; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import java.util.List; +import java.util.Map; /** * Created by libraryaddict on 7/09/2018. */ public class ParamInfoBoolean extends ParamInfo { - public ParamInfoBoolean(String name, String valueType, String description, String[] possibleValues) { + public ParamInfoBoolean(String name, String valueType, String description, Map possibleValues) { super(Boolean.class, name, valueType, description, possibleValues); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/custom/ParamInfoColor.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/custom/ParamInfoColor.java new file mode 100644 index 00000000..8f4f962b --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/custom/ParamInfoColor.java @@ -0,0 +1,34 @@ +package me.libraryaddict.disguise.utilities.parser.params.types.custom; + +import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; +import org.bukkit.Color; + +import java.util.Map; + +/** + * Created by libraryaddict on 19/09/2018. + */ +public class ParamInfoColor extends ParamInfoEnum { + public ParamInfoColor(Class paramClass, String name, String description, Map possibleValues) { + super(paramClass, name, description, possibleValues); + } + + @Override + protected Object fromString(String string) { + Object enumValue = super.fromString(string); + + if (enumValue != null) { + return enumValue; + } + + String[] split = string.split(","); + + if (split.length == 1) { + return Color.fromRGB(Integer.parseInt(split[0])); + } else if (split.length == 3) { + return Color.fromRGB(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); + } + + return null; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/custom/ParamInfoPotionType.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/custom/ParamInfoPotionType.java deleted file mode 100644 index d65be9e5..00000000 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/types/custom/ParamInfoPotionType.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.libraryaddict.disguise.utilities.parser.params.types.custom; - -import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; -import org.bukkit.potion.PotionEffectType; - -/** - * Created by libraryaddict on 7/09/2018. - */ -public class ParamInfoPotionType extends ParamInfoEnum { - public ParamInfoPotionType(Class paramClass, String name, String description, String[] possibleValues) { - super(paramClass, name, description, possibleValues); - } - - @Override - public Object fromString(String string) { - return PotionEffectType.getByName(string); - } -}