Read desc
Added animal colors to the list of settable options. Added itemstack and itemstack[] to the list of settable options Added /disguisehelp colors to get the list of usable colors Colored in the errors when constructing a disguise options
This commit is contained in:
parent
9b72086796
commit
03dcdb9c61
@ -3,6 +3,8 @@ package me.libraryaddict.disguise;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||||
@ -11,6 +13,7 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public abstract class BaseDisguiseCommand implements CommandExecutor {
|
public abstract class BaseDisguiseCommand implements CommandExecutor {
|
||||||
protected ArrayList<String> getAllowedDisguises(CommandSender sender, String permissionNode) {
|
protected ArrayList<String> getAllowedDisguises(CommandSender sender, String permissionNode) {
|
||||||
@ -152,23 +155,51 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
value = (double) obj;
|
value = (double) obj;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(ChatColor.RED + "Expected a number, received " + valueString
|
throw parseString("number", valueString, methodName);
|
||||||
+ " instead for " + methodName);
|
|
||||||
}
|
}
|
||||||
} else if (boolean.class == param) {
|
} else if (boolean.class == param) {
|
||||||
if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString)))
|
if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString)))
|
||||||
throw new Exception(ChatColor.RED + "Expected true/false, received " + valueString
|
throw parseString("true/false", valueString, methodName);
|
||||||
+ " instead for " + methodName);
|
|
||||||
value = (boolean) "true".equalsIgnoreCase(valueString);
|
value = (boolean) "true".equalsIgnoreCase(valueString);
|
||||||
} else if (param == String.class) {
|
} else if (param == String.class) {
|
||||||
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
||||||
|
} else if (param == AnimalColor.class) {
|
||||||
|
try {
|
||||||
|
value = AnimalColor.valueOf(valueString.toUpperCase());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseString("animal color", valueString, methodName);
|
||||||
|
}
|
||||||
|
} else if (param == ItemStack.class) {
|
||||||
|
try {
|
||||||
|
value = parseString(valueString);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new Exception(String.format(ex.getMessage(), methodName));
|
||||||
|
}
|
||||||
|
} else if (param == ItemStack[].class) {
|
||||||
|
ItemStack[] items = new ItemStack[4];
|
||||||
|
String[] split = valueString.split(",");
|
||||||
|
if (split.length == 4) {
|
||||||
|
for (int a = 0; a < 4; a++) {
|
||||||
|
try {
|
||||||
|
ItemStack item = parseString(split[a]);
|
||||||
|
items[a] = item;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseString("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
||||||
|
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw parseString("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
||||||
|
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
||||||
|
}
|
||||||
|
value = items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (methodToUse == null) {
|
if (methodToUse == null) {
|
||||||
throw new Exception(ChatColor.RED + "Cannot find option " + methodName);
|
throw new Exception(ChatColor.RED + "Cannot find the option " + methodName);
|
||||||
}
|
}
|
||||||
methodToUse.invoke(disguise.getWatcher(), value);
|
methodToUse.invoke(disguise.getWatcher(), value);
|
||||||
}
|
}
|
||||||
@ -176,5 +207,32 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Exception parseString(String expectedValue, String receivedInstead, String methodName) {
|
||||||
|
return new Exception(ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received "
|
||||||
|
+ ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack parseString(String string) throws Exception {
|
||||||
|
String[] split = string.split(":", -1);
|
||||||
|
if (isNumeric(split[0])) {
|
||||||
|
int itemId = Integer.parseInt(split[0]);
|
||||||
|
short itemDura = 0;
|
||||||
|
if (split.length > 1) {
|
||||||
|
if (isNumeric(split[1])) {
|
||||||
|
itemDura = Short.parseShort(split[1]);
|
||||||
|
} else {
|
||||||
|
throw parseString("item ID:Durability combo", string, "%s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ItemStack(itemId, 1, itemDura);
|
||||||
|
} else {
|
||||||
|
if (split.length == 1) {
|
||||||
|
throw parseString("item ID", string, "%s");
|
||||||
|
} else {
|
||||||
|
throw parseString("item ID:Durability combo", string, "%s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract void sendCommandUsage(CommandSender sender);
|
protected abstract void sendCommandUsage(CommandSender sender);
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
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;
|
||||||
|
|
||||||
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||||
|
|
||||||
@ -19,10 +21,19 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, node);
|
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, node);
|
||||||
if (!allowedDisguises.isEmpty()) {
|
if (!allowedDisguises.isEmpty()) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "/disguisehelp <Disguise>");
|
|
||||||
return true;
|
return true;
|
||||||
// sender.sendMessage(ChatColor.RED + "/disguisehelp <Disguise> <Option>");
|
// sender.sendMessage(ChatColor.RED + "/disguisehelp <Disguise> <Option>");
|
||||||
} else {
|
} else {
|
||||||
|
if (args[0].equalsIgnoreCase("colors")) {
|
||||||
|
ArrayList<String> colors = new ArrayList<String>();
|
||||||
|
for (AnimalColor color : AnimalColor.values()) {
|
||||||
|
colors.add(color.name().substring(0, 1)
|
||||||
|
+ color.name().toLowerCase().substring(1, color.name().length()));
|
||||||
|
}
|
||||||
|
sender.sendMessage(ChatColor.RED + "Animal colors: " + ChatColor.GREEN
|
||||||
|
+ StringUtils.join(colors, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
DisguiseType type = null;
|
DisguiseType type = null;
|
||||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||||
if (args[0].equalsIgnoreCase(disguiseType.name())
|
if (args[0].equalsIgnoreCase(disguiseType.name())
|
||||||
@ -48,6 +59,12 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
valueType = "True/False";
|
valueType = "True/False";
|
||||||
else if (float.class == c || double.class == c || int.class == c) {
|
else if (float.class == c || double.class == c || int.class == c) {
|
||||||
valueType = "Number";
|
valueType = "Number";
|
||||||
|
} else if (AnimalColor.class == c) {
|
||||||
|
valueType = "Color";
|
||||||
|
} else if (ItemStack.class == c) {
|
||||||
|
valueType = "Item ID with optional :Durability";
|
||||||
|
} else if (ItemStack[].class == c) {
|
||||||
|
valueType = "Item ID,ID,ID,ID with optional :Durability";
|
||||||
}
|
}
|
||||||
if (valueType != null) {
|
if (valueType != null) {
|
||||||
methods.add(ChatColor.RED + method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN
|
methods.add(ChatColor.RED + method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN
|
||||||
@ -72,5 +89,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
* Send the player the information
|
* Send the player the information
|
||||||
*/
|
*/
|
||||||
protected void sendCommandUsage(CommandSender sender) {
|
protected void sendCommandUsage(CommandSender sender) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> - View the options you can set on a disguise");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp Colors - View all the colors you can use for a disguise color");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
public enum AnimalColor {
|
public enum AnimalColor {
|
||||||
BLACK(15), BLUE(11), BROWN(
|
BLACK(15), BLUE(11), BROWN(12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(
|
||||||
12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(10), RED(14), SILVER(8), WHITE(0), YELLOW(4);
|
10), RED(14), SILVER(8), WHITE(0), YELLOW(4);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user