Fix enum values on disguise options
This commit is contained in:
		| @@ -43,7 +43,7 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|         if (ReflectionManager.getMinecraftVersion().startsWith("1.13")) { |         if (ReflectionManager.getMinecraftVersion().startsWith("1.13")) { | ||||||
|             if (!LibsPremium.isPremium()) { |             if (!LibsPremium.isPremium()) { | ||||||
|                 getLogger().severe("You must purchase the plugin to use 1.13!"); |                 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 " + |                 getLogger().severe("If you've already purchased the plugin, place the purchased jar inside the " + | ||||||
|                         "Lib's Disguises plugin folder"); |                         "Lib's Disguises plugin folder"); | ||||||
|                 getPluginLoader().disablePlugin(this); |                 getPluginLoader().disablePlugin(this); | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ public abstract class ParamInfo { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ParamInfo(Class paramClass, String name, String description, Enum[] possibleValues) { |     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) { |     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) { |     public ParamInfo(Class paramClass, String name, String description, Map<String,Object> possibleValues) { | ||||||
|         this(paramClass, name, name, description); |         this(paramClass, name, name, description, possibleValues); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ParamInfo(Class paramClass, String name, String descriptiveName, String description, |     public ParamInfo(Class paramClass, String name, String descriptiveName, String description, | ||||||
|             String[] possibleValues) { |             Map<String,Object> possibleValues) { | ||||||
|         this(paramClass, name, descriptiveName, description); |         this(paramClass, name, descriptiveName, description); | ||||||
|  |  | ||||||
|         this.possibleValues = new HashMap<>(); |         this.possibleValues = new HashMap<>(); | ||||||
|  |         this.possibleValues.putAll(possibleValues); | ||||||
|         for (String value : possibleValues) { |  | ||||||
|             getValues().put(value, value); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean canTranslateValues() { |     public boolean canTranslateValues() { | ||||||
|   | |||||||
| @@ -17,9 +17,7 @@ import org.bukkit.potion.PotionEffectType; | |||||||
| import org.bukkit.util.EulerAngle; | import org.bukkit.util.EulerAngle; | ||||||
|  |  | ||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
| import java.util.ArrayList; | import java.util.*; | ||||||
| import java.util.Arrays; |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by libraryaddict on 7/09/2018. |  * Created by libraryaddict on 7/09/2018. | ||||||
| @@ -65,7 +63,7 @@ public class ParamInfoTypes { | |||||||
|         // Register custom types |         // Register custom types | ||||||
|         paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", |         paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", | ||||||
|                 "Set the X,Y,Z directions on an armorstand")); |                 "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())); |                 getColors())); | ||||||
|         paramInfos.add(new ParamInfoEnum(Material.class, "Material", "A material used for blocks and items", |         paramInfos.add(new ParamInfoEnum(Material.class, "Material", "A material used for blocks and items", | ||||||
|                 getMaterials())); |                 getMaterials())); | ||||||
| @@ -74,7 +72,7 @@ public class ParamInfoTypes { | |||||||
|         paramInfos.add(new ParamInfoItemStackArray(ItemStack[].class, "ItemStack[]", |         paramInfos.add(new ParamInfoItemStackArray(ItemStack[].class, "ItemStack[]", | ||||||
|                 "Four ItemStacks (Material:Amount?:Glow?,Material:Amount?:Glow?..)", |                 "Four ItemStacks (Material:Amount?:Glow?,Material:Amount?:Glow?..)", | ||||||
|                 "Four ItemStacks separated by a comma", getMaterials())); |                 "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())); |                 "View all the potion effects you can add", getPotions())); | ||||||
|  |  | ||||||
|         paramInfos.add(new ParamInfoBlockPosition(BlockPosition.class, "Block Position", "Block Position (num,num,num)", |         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")); |                         ".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false")); | ||||||
|  |  | ||||||
|         // Register base types |         // Register base types | ||||||
|         paramInfos.add(new ParamInfoBoolean("Boolean", "True/False", "True or False", new String[]{"true", "false"})); |         Map<String, Object> 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 ParamInfoString(String.class, "Text", "A line of text")); | ||||||
|         paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals")); |         paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals")); | ||||||
|         paramInfos.add(new ParamInfoFloat("Number.0", "A number which can have decimal places")); |         paramInfos.add(new ParamInfoFloat("Number.0", "A number which can have decimal places")); | ||||||
| @@ -93,9 +95,9 @@ public class ParamInfoTypes { | |||||||
|         return paramInfos; |         return paramInfos; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private String[] getColors() { |     private Map<String, Object> getColors() { | ||||||
|         try { |         try { | ||||||
|             List<String> colors = new ArrayList<>(); |             Map<String, Object> map = new HashMap<>(); | ||||||
|             Class cl = Class.forName("org.bukkit.Color"); |             Class cl = Class.forName("org.bukkit.Color"); | ||||||
|  |  | ||||||
|             for (Field field : cl.getFields()) { |             for (Field field : cl.getFields()) { | ||||||
| @@ -103,12 +105,12 @@ public class ParamInfoTypes { | |||||||
|                     continue; |                     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(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -137,17 +139,17 @@ public class ParamInfoTypes { | |||||||
|         return list.toArray(new Material[0]); |         return list.toArray(new Material[0]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private String[] getPotions() { |     private Map<String, Object> getPotions() { | ||||||
|         List<String> potionEnums = new ArrayList<>(); |         Map<String, Object> map = new HashMap<>(); | ||||||
|  |  | ||||||
|         for (PotionEffectType effectType : PotionEffectType.values()) { |         for (PotionEffectType effectType : PotionEffectType.values()) { | ||||||
|             if (effectType == null) |             if (effectType == null) | ||||||
|                 continue; |                 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) { |     private String toReadable(String string) { | ||||||
|   | |||||||
| @@ -13,15 +13,15 @@ public class ParamInfoEnum extends ParamInfo { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ParamInfoEnum(Class paramClass, String name, String valueType, String description, Enum[] possibleValues) { |     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) { |     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) { |     public ParamInfoEnum(Class paramClass, String name, String description, Map<String,Object> possibleValues) { | ||||||
|         super(paramClass, name, name, description); |         super(paramClass, name, name, description, possibleValues); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -4,12 +4,13 @@ import me.libraryaddict.disguise.utilities.TranslateType; | |||||||
| import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; | import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; | ||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by libraryaddict on 7/09/2018. |  * Created by libraryaddict on 7/09/2018. | ||||||
|  */ |  */ | ||||||
| public class ParamInfoBoolean extends ParamInfo { | public class ParamInfoBoolean extends ParamInfo { | ||||||
|     public ParamInfoBoolean(String name, String valueType, String description, String[] possibleValues) { |     public ParamInfoBoolean(String name, String valueType, String description, Map<String, Object> possibleValues) { | ||||||
|         super(Boolean.class, name, valueType, description, possibleValues); |         super(Boolean.class, name, valueType, description, possibleValues); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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<String, Object> 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -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); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user