Read desc
Added option types profession, ocelot type, potion effect, horse style, horse color and related help commands
This commit is contained in:
parent
b4c7f8e30d
commit
9b8279e981
@ -13,7 +13,13 @@ 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.entity.Horse.Color;
|
||||||
|
import org.bukkit.entity.Horse.Style;
|
||||||
|
import org.bukkit.entity.Ocelot.Type;
|
||||||
|
import org.bukkit.entity.Villager.Profession;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
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) {
|
||||||
@ -144,6 +150,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
Class<?>[] types = method.getParameterTypes();
|
Class<?>[] types = method.getParameterTypes();
|
||||||
if (types.length == 1) {
|
if (types.length == 1) {
|
||||||
Class param = types[0];
|
Class param = types[0];
|
||||||
|
// Parse to number
|
||||||
if (float.class == param || double.class == param || int.class == param) {
|
if (float.class == param || double.class == param || int.class == param) {
|
||||||
if (isDouble(valueString)) {
|
if (isDouble(valueString)) {
|
||||||
float obj = Float.parseFloat(valueString);
|
float obj = Float.parseFloat(valueString);
|
||||||
@ -157,24 +164,29 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
throw parseToException("number", valueString, methodName);
|
throw parseToException("number", valueString, methodName);
|
||||||
}
|
}
|
||||||
|
// Parse to boolean
|
||||||
} 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 parseToException("true/false", valueString, methodName);
|
throw parseToException("true/false", valueString, methodName);
|
||||||
value = (boolean) "true".equalsIgnoreCase(valueString);
|
value = (boolean) "true".equalsIgnoreCase(valueString);
|
||||||
|
// Parse to string
|
||||||
} else if (param == String.class) {
|
} else if (param == String.class) {
|
||||||
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
||||||
|
// Parse to animal color
|
||||||
} else if (param == AnimalColor.class) {
|
} else if (param == AnimalColor.class) {
|
||||||
try {
|
try {
|
||||||
value = AnimalColor.valueOf(valueString.toUpperCase());
|
value = AnimalColor.valueOf(valueString.toUpperCase());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw parseToException("animal color", valueString, methodName);
|
throw parseToException("animal color", valueString, methodName);
|
||||||
}
|
}
|
||||||
|
// Parse to itemstack
|
||||||
} else if (param == ItemStack.class) {
|
} else if (param == ItemStack.class) {
|
||||||
try {
|
try {
|
||||||
value = parseToItemstack(valueString);
|
value = parseToItemstack(valueString);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new Exception(String.format(ex.getMessage(), methodName));
|
throw new Exception(String.format(ex.getMessage(), methodName));
|
||||||
}
|
}
|
||||||
|
// Parse to itemstack array
|
||||||
} else if (param == ItemStack[].class) {
|
} else if (param == ItemStack[].class) {
|
||||||
ItemStack[] items = new ItemStack[4];
|
ItemStack[] items = new ItemStack[4];
|
||||||
String[] split = valueString.split(",");
|
String[] split = valueString.split(",");
|
||||||
@ -193,6 +205,46 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
||||||
}
|
}
|
||||||
value = items;
|
value = items;
|
||||||
|
// Parse to horse color
|
||||||
|
} else if (param == Color.class) {
|
||||||
|
try {
|
||||||
|
value = Color.valueOf(valueString.toUpperCase());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("horse color", valueString, methodName);
|
||||||
|
}
|
||||||
|
// Parse to horse style
|
||||||
|
} else if (param == Style.class) {
|
||||||
|
try {
|
||||||
|
value = Style.valueOf(valueString.toUpperCase());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("horse style", valueString, methodName);
|
||||||
|
}
|
||||||
|
// Parse to villager profession
|
||||||
|
} else if (param == Profession.class) {
|
||||||
|
try {
|
||||||
|
value = Profession.valueOf(valueString.toUpperCase());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("villager profession", valueString, methodName);
|
||||||
|
}
|
||||||
|
// Parse to ocelot type
|
||||||
|
} else if (param == Type.class) {
|
||||||
|
try {
|
||||||
|
value = Type.valueOf(valueString.toUpperCase());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("ocelot type", valueString, methodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse to potion effect
|
||||||
|
} else if (param == PotionEffect.class) {
|
||||||
|
try {
|
||||||
|
PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
|
||||||
|
if (potionType == null && isNumeric(valueString)) {
|
||||||
|
potionType = PotionEffectType.getById(Integer.parseInt(valueString));
|
||||||
|
}
|
||||||
|
value = new PotionEffect(potionType, 0, 0);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw parseToException("potioneffect type", valueString, methodName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3,6 +3,8 @@ 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.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||||
@ -11,7 +13,12 @@ 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.entity.Horse.Color;
|
||||||
|
import org.bukkit.entity.Horse.Style;
|
||||||
|
import org.bukkit.entity.Ocelot.Type;
|
||||||
|
import org.bukkit.entity.Villager.Profession;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||||
|
|
||||||
@ -21,17 +28,45 @@ 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) {
|
||||||
|
sendCommandUsage(sender);
|
||||||
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")) {
|
Enum[] enums = null;
|
||||||
ArrayList<String> colors = new ArrayList<String>();
|
String enumName = null;
|
||||||
for (AnimalColor color : AnimalColor.values()) {
|
if (args[0].equalsIgnoreCase("animalcolor") || args[0].equalsIgnoreCase("animalcolors")) {
|
||||||
colors.add(color.name().substring(0, 1)
|
enums = AnimalColor.values();
|
||||||
+ color.name().toLowerCase().substring(1, color.name().length()));
|
enumName = "Animal colors";
|
||||||
|
} else if (args[0].equalsIgnoreCase("horsecolor") || args[0].equalsIgnoreCase("horsecolors")) {
|
||||||
|
enums = Color.values();
|
||||||
|
enumName = "Horse colors";
|
||||||
|
} else if (args[0].equalsIgnoreCase("horsestyle") || args[0].equalsIgnoreCase("horsestyles")) {
|
||||||
|
enums = Style.values();
|
||||||
|
enumName = "Horse styles";
|
||||||
|
} else if (args[0].equalsIgnoreCase("OcelotType") || args[0].equalsIgnoreCase("OcelotTypes")) {
|
||||||
|
enums = Type.values();
|
||||||
|
enumName = "Ocelot types";
|
||||||
|
} else if (args[0].equalsIgnoreCase("Profession") || args[0].equalsIgnoreCase("Professions")) {
|
||||||
|
enums = Profession.values();
|
||||||
|
enumName = "Villager professions";
|
||||||
|
} else if (args[0].equalsIgnoreCase("PotionEffect") || args[0].equalsIgnoreCase("PotionEffects")) {
|
||||||
|
ArrayList<String> potionTypes = new ArrayList<String>();
|
||||||
|
for (PotionEffectType potionType : PotionEffectType.values()) {
|
||||||
|
if (potionType != null)
|
||||||
|
potionTypes.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN
|
||||||
|
+ potionType.getId() + ChatColor.RED + ")");
|
||||||
}
|
}
|
||||||
sender.sendMessage(ChatColor.RED + "Animal colors: " + ChatColor.GREEN
|
sender.sendMessage(ChatColor.RED + "Potioneffect types: " + ChatColor.GREEN
|
||||||
+ StringUtils.join(colors, ChatColor.RED + ", " + ChatColor.GREEN));
|
+ StringUtils.join(potionTypes, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (enums != null) {
|
||||||
|
ArrayList<String> enumReturns = new ArrayList<String>();
|
||||||
|
for (Enum enumType : enums) {
|
||||||
|
enumReturns.add(toReadable(enumType.name()));
|
||||||
|
}
|
||||||
|
sender.sendMessage(ChatColor.RED + enumName + ": " + ChatColor.GREEN
|
||||||
|
+ StringUtils.join(enumReturns, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DisguiseType type = null;
|
DisguiseType type = null;
|
||||||
@ -65,6 +100,14 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
valueType = "Item ID with optional :Durability";
|
valueType = "Item ID with optional :Durability";
|
||||||
} else if (ItemStack[].class == c) {
|
} else if (ItemStack[].class == c) {
|
||||||
valueType = "Item ID,ID,ID,ID with optional :Durability";
|
valueType = "Item ID,ID,ID,ID with optional :Durability";
|
||||||
|
} else if (Style.class == c) {
|
||||||
|
valueType = "Horse Style";
|
||||||
|
} else if (Color.class == c) {
|
||||||
|
valueType = "Horse Color";
|
||||||
|
} else if (Type.class == c) {
|
||||||
|
valueType = "Ocelot type";
|
||||||
|
} else if (Profession.class == c) {
|
||||||
|
valueType = "Villager Profession";
|
||||||
}
|
}
|
||||||
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
|
||||||
@ -85,11 +128,30 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public 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, "_");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 <DisguiseType> " + ChatColor.GREEN
|
||||||
sender.sendMessage(ChatColor.RED + "/disguisehelp Colors - View all the colors you can use for a disguise color");
|
+ "- View the options you can set on a disguise");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp AnimalColors " + ChatColor.GREEN
|
||||||
|
+ "- View all the colors you can use for a animal color");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp HorseColors " + ChatColor.GREEN
|
||||||
|
+ "- View all the colors you can use for a horses color");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp HorseStyles " + ChatColor.GREEN
|
||||||
|
+ "- View all the styles you can use for a horses style");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp OcelotTypes " + ChatColor.GREEN
|
||||||
|
+ "- View all the ocelot types you can use for ocelots");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp Professions " + ChatColor.GREEN
|
||||||
|
+ "- View all the professions you can set on a villager");
|
||||||
|
sender.sendMessage(ChatColor.RED + "/disguisehelp PotionEffect " + ChatColor.GREEN
|
||||||
|
+ "- View all the potion effects you can set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user