Clean up code, change ParamInfos to display better information. DisguiseHelp is more readable. Parse disguises code is more readable
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public abstract class ParamInfo {
|
||||
private Class paramClass;
|
||||
private String descriptiveName;
|
||||
private String name;
|
||||
private Map<String, Object> possibleValues;
|
||||
/**
|
||||
* Used for translations, namely ItemStack and it's 'Glowing' and 'null' counterparts
|
||||
*/
|
||||
private String[] otherValues;
|
||||
private String description;
|
||||
|
||||
public ParamInfo(Class paramClass, String name, String description) {
|
||||
this(paramClass, name, name, description);
|
||||
}
|
||||
|
||||
public ParamInfo(Class paramClass, String name, String descriptiveName, String description) {
|
||||
this.name = name;
|
||||
this.paramClass = paramClass;
|
||||
this.descriptiveName = descriptiveName;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public ParamInfo(Class paramClass, String name, String description, Enum[] possibleValues) {
|
||||
this(paramClass, name, name, description);
|
||||
}
|
||||
|
||||
public ParamInfo(Class paramClass, String name, String descriptiveName, String description, Enum[] possibleValues) {
|
||||
this(paramClass, name, descriptiveName, description);
|
||||
|
||||
this.possibleValues = new HashMap<>();
|
||||
|
||||
for (Enum anEnum : possibleValues) {
|
||||
this.getValues().put(anEnum.name(), anEnum);
|
||||
}
|
||||
}
|
||||
|
||||
public ParamInfo(Class paramClass, String name, String description, String[] possibleValues) {
|
||||
this(paramClass, name, name, description);
|
||||
}
|
||||
|
||||
public ParamInfo(Class paramClass, String name, String descriptiveName, String description,
|
||||
String[] possibleValues) {
|
||||
this(paramClass, name, descriptiveName, description);
|
||||
|
||||
this.possibleValues = new HashMap<>();
|
||||
|
||||
for (String value : possibleValues) {
|
||||
getValues().put(value, value);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canTranslateValues() {
|
||||
return getValues() != null;
|
||||
}
|
||||
|
||||
public String[] getOtherValues() {
|
||||
return this.otherValues;
|
||||
}
|
||||
|
||||
public void setOtherValues(String... otherValues) {
|
||||
this.otherValues = otherValues;
|
||||
}
|
||||
|
||||
public boolean canReturnNull() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract Object fromString(String string);
|
||||
|
||||
public Object fromString(List<String> arguments) {
|
||||
// Don't consume a string immediately, if it errors we need to check other param types
|
||||
String string = arguments.get(0);
|
||||
|
||||
Object value = fromString(string);
|
||||
|
||||
arguments.remove(0);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getMinArguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean hasValues() {
|
||||
return getValues() != null;
|
||||
}
|
||||
|
||||
private Class getParamClass() {
|
||||
return paramClass;
|
||||
}
|
||||
|
||||
public boolean isParam(Class paramClass) {
|
||||
return getParamClass() == paramClass;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawName());
|
||||
}
|
||||
|
||||
public String getDescriptiveName() {
|
||||
return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawDescriptiveName());
|
||||
}
|
||||
|
||||
public String getRawName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getRawDescriptiveName() {
|
||||
return descriptiveName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawDescription());
|
||||
}
|
||||
|
||||
public String getRawDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Map<String, Object> getValues() {
|
||||
return this.possibleValues;
|
||||
}
|
||||
|
||||
public Set<String> getEnums(String tabComplete) {
|
||||
return getValues().keySet();
|
||||
}
|
||||
}
|
@@ -0,0 +1,162 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.types.base.*;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.types.custom.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MainHand;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoTypes {
|
||||
/**
|
||||
* Constructor values are listed here for continuity
|
||||
*/
|
||||
public List<ParamInfo> getParamInfos() {
|
||||
List<ParamInfo> paramInfos = new ArrayList<>();
|
||||
|
||||
// Register enum types
|
||||
paramInfos.add(new ParamInfoEnum(AnimalColor.class, "Animal Color",
|
||||
"View all the colors you can use for an animal color"));
|
||||
paramInfos
|
||||
.add(new ParamInfoEnum(Art.class, "Art", "View all the paintings you can use for a painting disguise"));
|
||||
paramInfos.add(new ParamInfoEnum(Horse.Color.class, "Horse Color",
|
||||
"View all the colors you can use for a horses color"));
|
||||
|
||||
paramInfos.add(new ParamInfoEnum(Ocelot.Type.class, "Ocelot Type",
|
||||
"View all the ocelot types you can use for ocelots"));
|
||||
paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession",
|
||||
"View all the professions you can set on a Zombie and Normal Villager"));
|
||||
paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)",
|
||||
"View the directions usable on player setSleeping and shulker direction",
|
||||
Arrays.copyOf(BlockFace.values(), 6)));
|
||||
paramInfos
|
||||
.add(new ParamInfoEnum(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into"));
|
||||
paramInfos
|
||||
.add(new ParamInfoEnum(TreeSpecies.class, "Tree Species", "View the different types of tree species"));
|
||||
|
||||
paramInfos.add(new ParamInfoEnum(MainHand.class, "Main Hand", "Set the main hand for an entity"));
|
||||
paramInfos.add(new ParamInfoEnum(Llama.Color.class, "Llama Color",
|
||||
"View all the colors you can use for a llama color"));
|
||||
paramInfos.add(new ParamInfoEnum(Parrot.Variant.class, "Parrot Variant",
|
||||
"View the different colors a parrot can be"));
|
||||
paramInfos.add(new ParamInfoEnum(Particle.class, "Particle", "The different particles of Minecraft"));
|
||||
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(Horse.Style.class, "Horse Style",
|
||||
"Horse style which is the patterns on the horse"));
|
||||
|
||||
// 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",
|
||||
getColors()));
|
||||
paramInfos.add(new ParamInfoEnum(Material.class, "Material", "A material used for blocks and items",
|
||||
getMaterials()));
|
||||
paramInfos.add(new ParamInfoItemStack(ItemStack.class, "ItemStack", "ItemStack (Material:Amount?:Glow?)",
|
||||
"An ItemStack compromised of Material:Amount:Glow, only requires Material", getMaterials()));
|
||||
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",
|
||||
"View all the potion effects you can add", getPotions()));
|
||||
|
||||
paramInfos.add(new ParamInfoBlockPosition(BlockPosition.class, "Block Position", "Block Position (num,num,num)",
|
||||
"Three numbers separated by a ,"));
|
||||
paramInfos.add(new ParamInfoGameProfile(WrappedGameProfile.class, "GameProfile",
|
||||
"Get the gameprofile here https://sessionserver.mojang" +
|
||||
".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"}));
|
||||
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"));
|
||||
paramInfos.add(new ParamInfoDouble("Number.0", "A number which can have decimal places"));
|
||||
|
||||
return paramInfos;
|
||||
}
|
||||
|
||||
private String[] getColors() {
|
||||
try {
|
||||
List<String> colors = new ArrayList<>();
|
||||
Class cl = Class.forName("org.bukkit.Color");
|
||||
|
||||
for (Field field : cl.getFields()) {
|
||||
if (field.getType() != cl) {
|
||||
continue;
|
||||
}
|
||||
|
||||
colors.add(field.getName());
|
||||
}
|
||||
|
||||
return colors.toArray(new String[0]);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Material[] getMaterials() {
|
||||
List<Material> list = new ArrayList<>();
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
try {
|
||||
Field field = Material.class.getField(material.name());
|
||||
|
||||
// Ignore all legacies materials
|
||||
if (field.isAnnotationPresent(Deprecated.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list.add(material);
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return list.toArray(new Material[0]);
|
||||
}
|
||||
|
||||
private String[] getPotions() {
|
||||
List<String> potionEnums = new ArrayList<>();
|
||||
|
||||
for (PotionEffectType effectType : PotionEffectType.values()) {
|
||||
if (effectType == null)
|
||||
continue;
|
||||
|
||||
potionEnums.add(toReadable(effectType.getName()));
|
||||
}
|
||||
|
||||
return potionEnums.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private String toReadable(String string) {
|
||||
String[] split = string.split("_");
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return StringUtils.join(split, "_");
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoEnum extends ParamInfo {
|
||||
public ParamInfoEnum(Class<? extends Enum> paramClass, String name, String description) {
|
||||
super(paramClass, name, name, description, paramClass.getEnumConstants());
|
||||
}
|
||||
|
||||
public ParamInfoEnum(Class paramClass, String name, String valueType, String description, Enum[] possibleValues) {
|
||||
super(paramClass, name, valueType, description);
|
||||
}
|
||||
|
||||
public ParamInfoEnum(Class paramClass, String name, String description, Enum[] possibleValues) {
|
||||
super(paramClass, name, name, description);
|
||||
}
|
||||
|
||||
public ParamInfoEnum(Class paramClass, String name, String description, String[] possibleValues) {
|
||||
super(paramClass, name, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
string = string.replace("_", "");
|
||||
|
||||
for (Map.Entry<String, Object> entry : getValues().entrySet()) {
|
||||
if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.base;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoBoolean extends ParamInfo {
|
||||
public ParamInfoBoolean(String name, String valueType, String description, String[] possibleValues) {
|
||||
super(Boolean.class, name, valueType, description, possibleValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParam(Class classType) {
|
||||
return classType == Boolean.class || classType == Boolean.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromString(List<String> list) {
|
||||
if (list.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String string = list.get(0);
|
||||
|
||||
if (string.equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("true"))) {
|
||||
list.remove(0);
|
||||
} else if (string.equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("false"))) {
|
||||
list.remove(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
throw new IllegalStateException("This shouldn't be called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinArguments() {
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.base;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoDouble extends ParamInfo {
|
||||
public ParamInfoDouble(String name, String description) {
|
||||
super(null, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParam(Class classType) {
|
||||
return classType == Double.class || classType == Double.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.base;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoFloat extends ParamInfo {
|
||||
public ParamInfoFloat(String name, String description) {
|
||||
super(Number.class, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParam(Class classType) {
|
||||
return classType == Float.class || classType == Float.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
return Float.parseFloat(string);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.base;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoInteger extends ParamInfo {
|
||||
public ParamInfoInteger(String name, String description) {
|
||||
super(null, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParam(Class classType) {
|
||||
return classType == Integer.class || classType == Integer.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.base;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoString extends ParamInfo {
|
||||
public ParamInfoString(Class paramClass, String name, String description) {
|
||||
super(paramClass, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoBlockPosition extends ParamInfo {
|
||||
public ParamInfoBlockPosition(Class paramClass, String name, String valueType, String description) {
|
||||
super(paramClass, name, valueType, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
String[] split = string.split(",");
|
||||
|
||||
if (split.length != 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoEulerAngle extends ParamInfo {
|
||||
public ParamInfoEulerAngle(Class paramClass, String name, String valueType, String description) {
|
||||
super(paramClass, name, valueType, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
String[] split = string.split(",");
|
||||
|
||||
if (split.length != 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EulerAngle(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]));
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoGameProfile extends ParamInfo {
|
||||
public ParamInfoGameProfile(Class paramClass, String name, String description) {
|
||||
super(paramClass, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString( String string) {
|
||||
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoItemStack extends ParamInfoEnum {
|
||||
public ParamInfoItemStack(Class paramClass, String name, String valueType, String description,
|
||||
Enum[] possibleValues) {
|
||||
super(paramClass, name, valueType, description, possibleValues);
|
||||
|
||||
setOtherValues("null", "glow");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTranslateValues() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReturnNull() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromString(String string) {
|
||||
return parseToItemstack(string);
|
||||
}
|
||||
|
||||
protected ItemStack parseToItemstack(String string) {
|
||||
String[] split = string.split(":", -1);
|
||||
|
||||
if (split[0].isEmpty() || split[0].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("null"))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Material material = Material.getMaterial(split[0]);
|
||||
|
||||
if (material == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
Integer amount = null;
|
||||
boolean enchanted = false;
|
||||
|
||||
for (int i = 1; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
|
||||
if (!enchanted && s.equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("glow"))) {
|
||||
enchanted = true;
|
||||
} else if (s.matches("\\d+") && amount == null) {
|
||||
amount = Integer.parseInt(s);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(material, amount == null ? 1 : amount);
|
||||
|
||||
if (enchanted) {
|
||||
itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoItemStackArray extends ParamInfoItemStack {
|
||||
public ParamInfoItemStackArray(Class paramClass, String name, String valueType, String description,
|
||||
Enum[] possibleValues) {
|
||||
super(paramClass, name, valueType, description, possibleValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getEnums(String tabComplete) {
|
||||
String beginning = tabComplete.substring(0, tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
|
||||
String end = tabComplete.substring(tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
|
||||
|
||||
Set<String> toReturn = new LinkedHashSet<>();
|
||||
|
||||
for (String material : super.getEnums(null)) {
|
||||
if (!material.toLowerCase().startsWith(end.toLowerCase()))
|
||||
continue;
|
||||
|
||||
toReturn.add(beginning + material);
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromString(String string) {
|
||||
String[] split = string.split(",", -1);
|
||||
|
||||
if (split.length != 4) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Parse to itemstack array
|
||||
ItemStack[] items = new ItemStack[4];
|
||||
|
||||
for (int a = 0; a < 4; a++) {
|
||||
items[a] = parseToItemstack(split[a]);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
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