Add BlockFace aka direction to disguise options
This commit is contained in:
parent
9f72a3940e
commit
babe5554ab
@ -2,6 +2,7 @@ package me.libraryaddict.disguise.commands;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -112,6 +114,8 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
"org.bukkit.entity.Villager$Profession").getEnumConstants()));
|
"org.bukkit.entity.Villager$Profession").getEnumConstants()));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
|
enumHelp.add(new EnumHelp("Direction", "Directions", ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN
|
||||||
|
+ "- View the four directions usable on player setsleeping disguise", Arrays.copyOf(BlockFace.values(), 4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -206,6 +210,8 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
valueType = "Potion effect";
|
valueType = "Potion effect";
|
||||||
} else if (c == int[].class) {
|
} else if (c == int[].class) {
|
||||||
valueType = "number,number,number...";
|
valueType = "number,number,number...";
|
||||||
|
} else if (c == BlockFace.class) {
|
||||||
|
valueType = "direction";
|
||||||
}
|
}
|
||||||
if (valueType != null) {
|
if (valueType != null) {
|
||||||
ChatColor methodColor = ChatColor.YELLOW;
|
ChatColor methodColor = ChatColor.YELLOW;
|
||||||
|
@ -16,6 +16,7 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
|||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.Ageable;
|
||||||
@ -467,113 +468,120 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
methodName = methodToUse.getName();
|
methodName = methodToUse.getName();
|
||||||
Class<?>[] types = methodToUse.getParameterTypes();
|
Class<?>[] types = methodToUse.getParameterTypes();
|
||||||
if (types.length == 1) {
|
Class param = types[0];
|
||||||
Class param = types[0];
|
if (boolean.class == param) {
|
||||||
if (boolean.class == param) {
|
// Parse to boolean
|
||||||
// Parse to boolean
|
if (valueString == null || !("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) {
|
||||||
if (valueString == null || !("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) {
|
value = true;
|
||||||
value = true;
|
i--;
|
||||||
i--;
|
|
||||||
} else {
|
|
||||||
value = "true".equalsIgnoreCase(valueString);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (valueString == null) {
|
value = "true".equalsIgnoreCase(valueString);
|
||||||
throw new Exception(ChatColor.RED + "No value was given for the option " + methodName);
|
}
|
||||||
|
} else {
|
||||||
|
if (valueString == null) {
|
||||||
|
throw new Exception(ChatColor.RED + "No value was given for the option " + methodName);
|
||||||
|
}
|
||||||
|
if (int.class == param) {
|
||||||
|
// Parse to integer
|
||||||
|
if (isNumeric(valueString)) {
|
||||||
|
value = (int) Integer.parseInt(valueString);
|
||||||
|
} else {
|
||||||
|
throw parseToException("number", valueString, methodName);
|
||||||
}
|
}
|
||||||
if (int.class == param) {
|
} else if (float.class == param || double.class == param) {
|
||||||
// Parse to integer
|
// Parse to number
|
||||||
if (isNumeric(valueString)) {
|
if (isDouble(valueString)) {
|
||||||
value = (int) Integer.parseInt(valueString);
|
float obj = Float.parseFloat(valueString);
|
||||||
} else {
|
if (param == float.class) {
|
||||||
throw parseToException("number", valueString, methodName);
|
value = (float) obj;
|
||||||
|
} else if (param == double.class) {
|
||||||
|
value = (double) obj;
|
||||||
}
|
}
|
||||||
} else if (float.class == param || double.class == param) {
|
} else {
|
||||||
// Parse to number
|
throw parseToException("number.0", valueString, methodName);
|
||||||
if (isDouble(valueString)) {
|
}
|
||||||
float obj = Float.parseFloat(valueString);
|
} else if (param == String.class) {
|
||||||
if (param == float.class) {
|
// Parse to string
|
||||||
value = (float) obj;
|
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
||||||
} else if (param == double.class) {
|
} else if (param == AnimalColor.class) {
|
||||||
value = (double) obj;
|
// Parse to animal color
|
||||||
}
|
try {
|
||||||
} else {
|
value = AnimalColor.valueOf(valueString.toUpperCase());
|
||||||
throw parseToException("number.0", valueString, methodName);
|
} catch (Exception ex) {
|
||||||
}
|
throw parseToException("animal color", valueString, methodName);
|
||||||
} else if (param == String.class) {
|
}
|
||||||
// Parse to string
|
} else if (param == ItemStack.class) {
|
||||||
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
// Parse to itemstack
|
||||||
} else if (param == AnimalColor.class) {
|
try {
|
||||||
// Parse to animal color
|
value = parseToItemstack(valueString);
|
||||||
try {
|
} catch (Exception ex) {
|
||||||
value = AnimalColor.valueOf(valueString.toUpperCase());
|
throw new Exception(String.format(ex.getMessage(), methodName));
|
||||||
} catch (Exception ex) {
|
}
|
||||||
throw parseToException("animal color", valueString, methodName);
|
} else if (param == ItemStack[].class) {
|
||||||
}
|
// Parse to itemstack array
|
||||||
} else if (param == ItemStack.class) {
|
ItemStack[] items = new ItemStack[4];
|
||||||
// Parse to itemstack
|
String[] split = valueString.split(",");
|
||||||
try {
|
if (split.length == 4) {
|
||||||
value = parseToItemstack(valueString);
|
for (int a = 0; a < 4; a++) {
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new Exception(String.format(ex.getMessage(), methodName));
|
|
||||||
}
|
|
||||||
} else if (param == ItemStack[].class) {
|
|
||||||
// Parse to itemstack array
|
|
||||||
ItemStack[] items = new ItemStack[4];
|
|
||||||
String[] split = valueString.split(",");
|
|
||||||
if (split.length == 4) {
|
|
||||||
for (int a = 0; a < 4; a++) {
|
|
||||||
try {
|
|
||||||
items[a] = parseToItemstack(split[a]);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
|
||||||
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
|
||||||
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
|
||||||
}
|
|
||||||
value = items;
|
|
||||||
} else if (param.getSimpleName().equals("Color")) {
|
|
||||||
// Parse to horse color
|
|
||||||
value = callValueOf(param, valueString, methodName, "a horse color");
|
|
||||||
} else if (param.getSimpleName().equals("Style")) {
|
|
||||||
// Parse to horse style
|
|
||||||
value = callValueOf(param, valueString, methodName, "a horse style");
|
|
||||||
} else if (param.getSimpleName().equals("Profession")) {
|
|
||||||
// Parse to villager profession
|
|
||||||
value = callValueOf(param, valueString, methodName, "a villager profession");
|
|
||||||
} else if (param.getSimpleName().equals("Art")) {
|
|
||||||
// Parse to art type
|
|
||||||
value = callValueOf(param, valueString, methodName, "a painting art");
|
|
||||||
} else if (param.getSimpleName().equals("Type")) {
|
|
||||||
// Parse to ocelot type
|
|
||||||
value = callValueOf(param, valueString, methodName, "a ocelot type");
|
|
||||||
} else if (param == PotionEffectType.class) {
|
|
||||||
// Parse to potion effect
|
|
||||||
try {
|
|
||||||
PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
|
|
||||||
if (potionType == null && isNumeric(valueString)) {
|
|
||||||
potionType = PotionEffectType.getById(Integer.parseInt(valueString));
|
|
||||||
}
|
|
||||||
if (potionType == null)
|
|
||||||
throw new Exception();
|
|
||||||
value = potionType;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw parseToException("a potioneffect type", valueString, methodName);
|
|
||||||
}
|
|
||||||
} else if (param == int[].class) {
|
|
||||||
String[] split = valueString.split(",");
|
|
||||||
int[] values = new int[split.length];
|
|
||||||
for (int b = 0; b < values.length; b++) {
|
|
||||||
try {
|
try {
|
||||||
values[b] = Integer.parseInt(split[b]);
|
items[a] = parseToItemstack(split[a]);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (Exception ex) {
|
||||||
throw parseToException("Number,Number,Number...", valueString, methodName);
|
throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
||||||
|
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = values;
|
} else {
|
||||||
|
throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
||||||
|
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
||||||
|
}
|
||||||
|
value = items;
|
||||||
|
} else if (param.getSimpleName().equals("Color")) {
|
||||||
|
// Parse to horse color
|
||||||
|
value = callValueOf(param, valueString, methodName, "a horse color");
|
||||||
|
} else if (param.getSimpleName().equals("Style")) {
|
||||||
|
// Parse to horse style
|
||||||
|
value = callValueOf(param, valueString, methodName, "a horse style");
|
||||||
|
} else if (param.getSimpleName().equals("Profession")) {
|
||||||
|
// Parse to villager profession
|
||||||
|
value = callValueOf(param, valueString, methodName, "a villager profession");
|
||||||
|
} else if (param.getSimpleName().equals("Art")) {
|
||||||
|
// Parse to art type
|
||||||
|
value = callValueOf(param, valueString, methodName, "a painting art");
|
||||||
|
} else if (param.getSimpleName().equals("Type")) {
|
||||||
|
// Parse to ocelot type
|
||||||
|
value = callValueOf(param, valueString, methodName, "a ocelot type");
|
||||||
|
} else if (param == PotionEffectType.class) {
|
||||||
|
// Parse to potion effect
|
||||||
|
try {
|
||||||
|
PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
|
||||||
|
if (potionType == null && isNumeric(valueString)) {
|
||||||
|
potionType = PotionEffectType.getById(Integer.parseInt(valueString));
|
||||||
|
}
|
||||||
|
if (potionType == null)
|
||||||
|
throw new Exception();
|
||||||
|
value = potionType;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("a potioneffect type", valueString, methodName);
|
||||||
|
}
|
||||||
|
} else if (param == int[].class) {
|
||||||
|
String[] split = valueString.split(",");
|
||||||
|
int[] values = new int[split.length];
|
||||||
|
for (int b = 0; b < values.length; b++) {
|
||||||
|
try {
|
||||||
|
values[b] = Integer.parseInt(split[b]);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw parseToException("Number,Number,Number...", valueString, methodName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = values;
|
||||||
|
} else if (param == BlockFace.class) {
|
||||||
|
try {
|
||||||
|
BlockFace face = BlockFace.valueOf(valueString.toUpperCase());
|
||||||
|
if (face.ordinal() > 3)
|
||||||
|
throw new Exception();
|
||||||
|
value = face;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("a direction (north, east, south, west)", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user