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 (!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); | ||||
|   | ||||
| @@ -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<String,Object> possibleValues) { | ||||
|         this(paramClass, name, name, description, possibleValues); | ||||
|     } | ||||
|  | ||||
|     public ParamInfo(Class paramClass, String name, String descriptiveName, String description, | ||||
|             String[] possibleValues) { | ||||
|             Map<String,Object> 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() { | ||||
|   | ||||
| @@ -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<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 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<String, Object> getColors() { | ||||
|         try { | ||||
|             List<String> colors = new ArrayList<>(); | ||||
|             Map<String, Object> 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<String> potionEnums = new ArrayList<>(); | ||||
|     private Map<String, Object> getPotions() { | ||||
|         Map<String, Object> 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) { | ||||
|   | ||||
| @@ -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<String,Object> possibleValues) { | ||||
|         super(paramClass, name, name, description, possibleValues); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -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<String, Object> 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