Disguise params extra information
This commit is contained in:
		| @@ -1,10 +1,7 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes; | package me.libraryaddict.disguise.disguisetypes; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.BlockPosition; | import com.comphenix.protocol.wrappers.*; | ||||||
| import com.comphenix.protocol.wrappers.EnumWrappers.Direction; | import com.comphenix.protocol.wrappers.EnumWrappers.Direction; | ||||||
| import com.comphenix.protocol.wrappers.Vector3F; |  | ||||||
| import com.comphenix.protocol.wrappers.WrappedBlockData; |  | ||||||
| import com.comphenix.protocol.wrappers.WrappedChatComponent; |  | ||||||
| import com.comphenix.protocol.wrappers.nbt.NbtBase; | import com.comphenix.protocol.wrappers.nbt.NbtBase; | ||||||
| import com.comphenix.protocol.wrappers.nbt.NbtFactory; | import com.comphenix.protocol.wrappers.nbt.NbtFactory; | ||||||
| import com.comphenix.protocol.wrappers.nbt.NbtType; | import com.comphenix.protocol.wrappers.nbt.NbtType; | ||||||
| @@ -42,8 +39,8 @@ public class MetaIndex<Y> { | |||||||
|     /** |     /** | ||||||
|      * The type of particle to display |      * The type of particle to display | ||||||
|      */ |      */ | ||||||
|     public static MetaIndex<Particle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, |     public static MetaIndex<WrappedParticle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, | ||||||
|             Particle.SPELL_MOB); |             WrappedParticle.create(Particle.SPELL_MOB, null)); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * The size of the area |      * The size of the area | ||||||
| @@ -607,7 +604,7 @@ public class MetaIndex<Y> { | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param watcherClass - A FlagWatcher class |      * @param watcherClass - A FlagWatcher class | ||||||
|      * @param flagNo - The meta index number |      * @param flagNo       - The meta index number | ||||||
|      * @return The MetaIndex which corresponds to that FlagWatcher at that index |      * @return The MetaIndex which corresponds to that FlagWatcher at that index | ||||||
|      */ |      */ | ||||||
|     public static MetaIndex getMetaIndex(Class<? extends FlagWatcher> watcherClass, int flagNo) { |     public static MetaIndex getMetaIndex(Class<? extends FlagWatcher> watcherClass, int flagNo) { | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedParticle; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
| @@ -49,12 +50,24 @@ public class AreaEffectCloudWatcher extends FlagWatcher { | |||||||
|         sendData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); |         sendData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setParticleType(Particle particle) { |     public void setParticle(WrappedParticle particle) { | ||||||
|         setData(MetaIndex.AREA_EFFECT_PARTICLE, particle); |         setData(MetaIndex.AREA_EFFECT_PARTICLE, particle); | ||||||
|         sendData(MetaIndex.AREA_EFFECT_PARTICLE); |         sendData(MetaIndex.AREA_EFFECT_PARTICLE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Particle getParticleType() { |     public void setParticle(Particle particle) { | ||||||
|  |         setParticle(WrappedParticle.create(particle, null)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public <T> void setParticle(Particle particle, T particleData) { | ||||||
|  |         setParticle(WrappedParticle.create(particle, particleData)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public WrappedParticle getParticle() { | ||||||
|         return getData(MetaIndex.AREA_EFFECT_PARTICLE); |         return getData(MetaIndex.AREA_EFFECT_PARTICLE); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public Particle getParticleType() { | ||||||
|  |         return getParticle().getParticle(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,15 +1,14 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
| import org.bukkit.Material; |  | ||||||
| import org.bukkit.inventory.ItemStack; |  | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import org.bukkit.Material; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| public class FallingBlockWatcher extends FlagWatcher { | public class FallingBlockWatcher extends FlagWatcher { | ||||||
|     private ItemStack block; |     private ItemStack block = new ItemStack(Material.STONE); | ||||||
|  |  | ||||||
|     public FallingBlockWatcher(Disguise disguise) { |     public FallingBlockWatcher(Disguise disguise) { | ||||||
|         super(disguise); |         super(disguise); | ||||||
| @@ -18,7 +17,7 @@ public class FallingBlockWatcher extends FlagWatcher { | |||||||
|     @Override |     @Override | ||||||
|     public FallingBlockWatcher clone(Disguise disguise) { |     public FallingBlockWatcher clone(Disguise disguise) { | ||||||
|         FallingBlockWatcher watcher = (FallingBlockWatcher) super.clone(disguise); |         FallingBlockWatcher watcher = (FallingBlockWatcher) super.clone(disguise); | ||||||
|         watcher.setBlock(getBlock()); |         watcher.setBlock(getBlock().clone()); | ||||||
|  |  | ||||||
|         return watcher; |         return watcher; | ||||||
|     } |     } | ||||||
| @@ -28,12 +27,12 @@ public class FallingBlockWatcher extends FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setBlock(ItemStack block) { |     public void setBlock(ItemStack block) { | ||||||
|         this.block = block; |  | ||||||
|  |  | ||||||
|         if (block == null || block.getType() == null || block.getType() == Material.AIR) { |         if (block == null || block.getType() == null || block.getType() == Material.AIR) { | ||||||
|             block.setType(Material.STONE); |             block = new ItemStack(Material.STONE); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         this.block = block; | ||||||
|  |  | ||||||
|         if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { |         if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { | ||||||
|             DisguiseUtilities.refreshTrackers(getDisguise()); |             DisguiseUtilities.refreshTrackers(getDisguise()); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -137,6 +137,13 @@ public enum LibsMsg { | |||||||
|     PARSE_EXPECTED_RECEIVED( |     PARSE_EXPECTED_RECEIVED( | ||||||
|             ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + |             ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN + | ||||||
|                     "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"), |                     "%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"), | ||||||
|  |     PARSE_PARTICLE_BLOCK(ChatColor.RED + "Expected " + ChatColor.GREEN + "%s:Material" + ChatColor.RED + ", received " + | ||||||
|  |             ChatColor.GREEN + "%s" + ChatColor.RED + " instead"), | ||||||
|  |     PARSE_PARTICLE_ITEM(ChatColor.RED + "Expected " + ChatColor.GREEN + "%s:Material,Amount?,Glow?" + ChatColor.RED + | ||||||
|  |             ", received " + ChatColor.GREEN + "%s" + ChatColor.RED + " instead"), | ||||||
|  |     PARSE_PARTICLE_REDSTONE( | ||||||
|  |             ChatColor.RED + "Expected " + ChatColor.GREEN + "%s:Color,Size.0?" + ChatColor.RED + ", received " + | ||||||
|  |                     ChatColor.GREEN + "%s" + ChatColor.RED + " instead"), | ||||||
|     PARSE_NO_ARGS("No arguments defined"), |     PARSE_NO_ARGS("No arguments defined"), | ||||||
|     PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"), |     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_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"), | ||||||
|   | |||||||
| @@ -615,8 +615,9 @@ public class DisguiseParser { | |||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     // Construct the disguise |                     // Construct the disguise | ||||||
|                     if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM) { |                     if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM || | ||||||
|                         disguise = new MiscDisguise(itemStack); |                             disguisePerm.getType() == DisguiseType.FALLING_BLOCK) { | ||||||
|  |                         disguise = new MiscDisguise(disguisePerm.getType(), itemStack); | ||||||
|                     } else { |                     } else { | ||||||
|                         disguise = new MiscDisguise(disguisePerm.getType(), miscId, miscData); |                         disguise = new MiscDisguise(disguisePerm.getType(), miscId, miscData); | ||||||
|                     } |                     } | ||||||
| @@ -682,6 +683,9 @@ public class DisguiseParser { | |||||||
|                     // We've found a method which will accept a valid value, break |                     // We've found a method which will accept a valid value, break | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|  |                 catch (DisguiseParseException ex) { | ||||||
|  |                     parseException = ex; | ||||||
|  |                 } | ||||||
|                 catch (Exception ignored) { |                 catch (Exception ignored) { | ||||||
|                     parseException = new DisguiseParseException(LibsMsg.PARSE_EXPECTED_RECEIVED, |                     parseException = new DisguiseParseException(LibsMsg.PARSE_EXPECTED_RECEIVED, | ||||||
|                             paramInfo.getDescriptiveName(), list.isEmpty() ? null : list.get(0), |                             paramInfo.getDescriptiveName(), list.isEmpty() ? null : list.get(0), | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package me.libraryaddict.disguise.utilities.parser.params; | package me.libraryaddict.disguise.utilities.parser.params; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.utilities.TranslateType; | import me.libraryaddict.disguise.utilities.TranslateType; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; | ||||||
|  |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @@ -74,9 +75,9 @@ public abstract class ParamInfo { | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected abstract Object fromString(String string); |     protected abstract Object fromString(String string) throws DisguiseParseException; | ||||||
|  |  | ||||||
|     public Object fromString(List<String> arguments) { |     public Object fromString(List<String> arguments) throws DisguiseParseException { | ||||||
|         // Don't consume a string immediately, if it errors we need to check other param types |         // Don't consume a string immediately, if it errors we need to check other param types | ||||||
|         String string = arguments.get(0); |         String string = arguments.get(0); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities.parser.params; | |||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.BlockPosition; | import com.comphenix.protocol.wrappers.BlockPosition; | ||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedParticle; | ||||||
| import me.libraryaddict.disguise.disguisetypes.AnimalColor; | import me.libraryaddict.disguise.disguisetypes.AnimalColor; | ||||||
| import me.libraryaddict.disguise.disguisetypes.RabbitType; | import me.libraryaddict.disguise.disguisetypes.RabbitType; | ||||||
| import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | ||||||
| @@ -54,7 +55,8 @@ public class ParamInfoTypes { | |||||||
|                 "View all the colors you can use for a llama color")); |                 "View all the colors you can use for a llama color")); | ||||||
|         paramInfos.add(new ParamInfoEnum(Parrot.Variant.class, "Parrot Variant", |         paramInfos.add(new ParamInfoEnum(Parrot.Variant.class, "Parrot Variant", | ||||||
|                 "View the different colors a parrot can be")); |                 "View the different colors a parrot can be")); | ||||||
|         paramInfos.add(new ParamInfoEnum(Particle.class, "Particle", "The different particles of Minecraft")); |         paramInfos.add(new ParamInfoParticle(WrappedParticle.class, "Particle", "The different particles of Minecraft", | ||||||
|  |                 Particle.values(), getMaterials())); | ||||||
|         paramInfos.add(new ParamInfoEnum(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish")); |         paramInfos.add(new ParamInfoEnum(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish")); | ||||||
|         paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors")); |         paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors")); | ||||||
|         paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style", |         paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style", | ||||||
| @@ -67,8 +69,8 @@ public class ParamInfoTypes { | |||||||
|                 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())); | ||||||
|         paramInfos.add(new ParamInfoItemStack(ItemStack.class, "ItemStack", "ItemStack (Material:Amount?:Glow?)", |         paramInfos.add(new ParamInfoItemStack(ItemStack.class, "ItemStack", "ItemStack (Material,Amount?,Glow?)", | ||||||
|                 "An ItemStack compromised of Material:Amount:Glow, only requires Material", getMaterials())); |                 "An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials())); | ||||||
|         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())); | ||||||
| @@ -121,6 +123,10 @@ public class ParamInfoTypes { | |||||||
|         List<Material> list = new ArrayList<>(); |         List<Material> list = new ArrayList<>(); | ||||||
|  |  | ||||||
|         for (Material material : Material.values()) { |         for (Material material : Material.values()) { | ||||||
|  |             if (material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
|                 Field field = Material.class.getField(material.name()); |                 Field field = Material.class.getField(material.name()); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package me.libraryaddict.disguise.utilities.parser.params.types; | package me.libraryaddict.disguise.utilities.parser.params.types; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; | ||||||
| import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; | import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; | ||||||
|  |  | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| @@ -25,7 +26,7 @@ public class ParamInfoEnum extends ParamInfo { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) throws DisguiseParseException { | ||||||
|         string = string.replace("_", ""); |         string = string.replace("_", ""); | ||||||
|  |  | ||||||
|         for (Map.Entry<String, Object> entry : getValues().entrySet()) { |         for (Map.Entry<String, Object> entry : getValues().entrySet()) { | ||||||
|   | |||||||
| @@ -9,16 +9,23 @@ import java.util.Map; | |||||||
|  * Created by libraryaddict on 19/09/2018. |  * Created by libraryaddict on 19/09/2018. | ||||||
|  */ |  */ | ||||||
| public class ParamInfoColor extends ParamInfoEnum { | public class ParamInfoColor extends ParamInfoEnum { | ||||||
|  |     private static Map<String, Object> staticColors; | ||||||
|  |  | ||||||
|     public ParamInfoColor(Class paramClass, String name, String description, Map<String, Object> possibleValues) { |     public ParamInfoColor(Class paramClass, String name, String description, Map<String, Object> possibleValues) { | ||||||
|         super(paramClass, name, description, possibleValues); |         super(paramClass, name, description, possibleValues); | ||||||
|  |  | ||||||
|  |         staticColors = possibleValues; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     protected static Color parseToColor(String string) { | ||||||
|     protected Object fromString(String string) { |         string = string.replace("_", ""); | ||||||
|         Object enumValue = super.fromString(string); |  | ||||||
|  |  | ||||||
|         if (enumValue != null) { |         for (Map.Entry<String, Object> entry : staticColors.entrySet()) { | ||||||
|             return enumValue; |             if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return (Color) entry.getValue(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         String[] split = string.split(","); |         String[] split = string.split(","); | ||||||
| @@ -31,4 +38,9 @@ public class ParamInfoColor extends ParamInfoEnum { | |||||||
|  |  | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     protected Object fromString(String string) { | ||||||
|  |         return parseToColor(string); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -32,9 +32,11 @@ public class ParamInfoItemStack extends ParamInfoEnum { | |||||||
|         return parseToItemstack(string); |         return parseToItemstack(string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected ItemStack parseToItemstack(String string) { |     protected static ItemStack parseToItemstack(String string) { | ||||||
|         String[] split = string.split(":", -1); |         return parseToItemstack(string.split("[:,]")); // Split on colon or comma | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     protected static ItemStack parseToItemstack(String[] split) { | ||||||
|         if (split[0].isEmpty() || split[0].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("null"))) { |         if (split[0].isEmpty() || split[0].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("null"))) { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -43,7 +43,7 @@ public class ParamInfoItemStackArray extends ParamInfoItemStack { | |||||||
|         ItemStack[] items = new ItemStack[4]; |         ItemStack[] items = new ItemStack[4]; | ||||||
|  |  | ||||||
|         for (int a = 0; a < 4; a++) { |         for (int a = 0; a < 4; a++) { | ||||||
|             items[a] = parseToItemstack(split[a]); |             items[a] = parseToItemstack(split[a].split(":")); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return items; |         return items; | ||||||
|   | |||||||
| @@ -0,0 +1,129 @@ | |||||||
|  | package me.libraryaddict.disguise.utilities.parser.params.types.custom; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedBlockData; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedParticle; | ||||||
|  | import me.libraryaddict.disguise.utilities.LibsMsg; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; | ||||||
|  | import org.apache.commons.lang3.StringUtils; | ||||||
|  | import org.bukkit.Color; | ||||||
|  | import org.bukkit.Material; | ||||||
|  | import org.bukkit.Particle; | ||||||
|  |  | ||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.Set; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Created by libraryaddict on 19/09/2018. | ||||||
|  |  */ | ||||||
|  | public class ParamInfoParticle extends ParamInfoEnum { | ||||||
|  |     private Material[] materials; | ||||||
|  |  | ||||||
|  |     public ParamInfoParticle(Class paramClass, String name, String description, Enum[] possibleValues, | ||||||
|  |             Material[] materials) { | ||||||
|  |         super(paramClass, name, description, possibleValues); | ||||||
|  |  | ||||||
|  |         this.materials = materials; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Set<String> getEnums(String tabComplete) { | ||||||
|  |         Set<String> enums = getValues().keySet(); | ||||||
|  |  | ||||||
|  |         if (tabComplete.isEmpty()) { | ||||||
|  |             return enums; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         enums = new HashSet<>(enums); | ||||||
|  |  | ||||||
|  |         tabComplete = tabComplete.toUpperCase(); | ||||||
|  |  | ||||||
|  |         for (Particle particle : new Particle[]{Particle.BLOCK_CRACK, Particle.BLOCK_DUST, Particle.ITEM_CRACK}) { | ||||||
|  |             for (Material mat : materials) { | ||||||
|  |                 if (particle != Particle.ITEM_CRACK && !mat.isBlock()) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 String name = particle.name() + ":" + mat.name(); | ||||||
|  |  | ||||||
|  |                 if (!name.startsWith(tabComplete)) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 enums.add(name); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return enums; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Object fromString(String string) throws DisguiseParseException { | ||||||
|  |         String[] split = string.split("[:,]"); // Split on comma or colon | ||||||
|  |         Particle particle = (Particle) super.fromString(split[0]); | ||||||
|  |  | ||||||
|  |         if (particle == null) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         Object data = null; | ||||||
|  |  | ||||||
|  |         switch (particle) { | ||||||
|  |             case BLOCK_CRACK: | ||||||
|  |             case BLOCK_DUST: | ||||||
|  |             case FALLING_DUST: | ||||||
|  |                 Material material; | ||||||
|  |  | ||||||
|  |                 if (split.length != 2 || (material = Material.getMaterial(split[1])) == null || !material.isBlock()) { | ||||||
|  |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_BLOCK, particle.name(), string); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 data = WrappedBlockData.createData(material); | ||||||
|  |                 break; | ||||||
|  |             case ITEM_CRACK: | ||||||
|  |                 if (split.length != 1) { | ||||||
|  |                     data = ParamInfoItemStack.parseToItemstack(Arrays.copyOfRange(split, 1, split.length)); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 if (data == null) { | ||||||
|  |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_ITEM, particle.name(), string); | ||||||
|  |                 } | ||||||
|  |                 break; | ||||||
|  |             case REDSTONE: | ||||||
|  |                 // If it can't be a RGB color or color name | ||||||
|  |                 // REDSTONE:BLUE - 2 args | ||||||
|  |                 // REDSTONE:BLUE,4 - 3 args | ||||||
|  |                 // REDSTONE:3,5,2 - 4 args | ||||||
|  |                 // REDSTONE:3,5,6,2 - 5 args | ||||||
|  |                 if (split.length < 2 || split.length > 5) { | ||||||
|  |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 Color color = ParamInfoColor.parseToColor( | ||||||
|  |                         StringUtils.join(Arrays.copyOfRange(split, 1, split.length - (split.length % 2)), ",")); | ||||||
|  |  | ||||||
|  |                 if (color == null) { | ||||||
|  |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 float size; | ||||||
|  |  | ||||||
|  |                 if (split.length % 2 == 0) { | ||||||
|  |                     size = 1; | ||||||
|  |                 } else if (!split[split.length - 1].matches("[0-9.]+")) { | ||||||
|  |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); | ||||||
|  |                 } else { | ||||||
|  |                     size = Math.max(0.2f, Float.parseFloat(split[split.length - 1])); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 data = new Particle.DustOptions(color, size); | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (data == null && split.length > 1) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return WrappedParticle.create(particle, data); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user