Change disguisehelp to use reflection for watcher values and a new EnumHelp thingy
This commit is contained in:
parent
e41b80ebc0
commit
b93f5d3ea4
@ -10,14 +10,98 @@ 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;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||||
|
private class EnumHelp {
|
||||||
|
private String enumName;
|
||||||
|
private String enumDescription;
|
||||||
|
private String[] enums;
|
||||||
|
private String readableEnum;
|
||||||
|
|
||||||
|
public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) {
|
||||||
|
String[] strings = new String[enums.length];
|
||||||
|
for (int i = 0; i < strings.length; i++) {
|
||||||
|
strings[i] = toReadable(enums[i].name());
|
||||||
|
}
|
||||||
|
this.enumName = enumName;
|
||||||
|
this.enumDescription = enumDescription;
|
||||||
|
this.enums = strings;
|
||||||
|
this.readableEnum = enumReadable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) {
|
||||||
|
this.enumName = enumName;
|
||||||
|
this.enumDescription = enumDescription;
|
||||||
|
this.enums = enums;
|
||||||
|
this.readableEnum = enumReadable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnumName() {
|
||||||
|
return enumName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReadableEnum() {
|
||||||
|
return readableEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnumDescription() {
|
||||||
|
return enumDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getEnums() {
|
||||||
|
return enums;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<EnumHelp> enumHelp = new ArrayList<EnumHelp>();
|
||||||
|
|
||||||
|
public DisguiseHelpCommand() {
|
||||||
|
try {
|
||||||
|
enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors "
|
||||||
|
+ ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
enumHelp.add(new EnumHelp("HorseColor", "Horse colors", ChatColor.RED + "/disguisehelp HorseColors "
|
||||||
|
+ ChatColor.GREEN + "- View all the colors you can use for a horses color", (Enum[]) Class.forName(
|
||||||
|
"org.bukkit.entity.Horse$Color").getEnumConstants()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
enumHelp.add(new EnumHelp("HorseStyle", "Horse styles", ChatColor.RED + "/disguisehelp HorseStyles "
|
||||||
|
+ ChatColor.GREEN + "- View all the styles you can use for a horses style", (Enum[]) Class.forName(
|
||||||
|
"org.bukkit.entity.Horse$Style").getEnumConstants()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
enumHelp.add(new EnumHelp("OcelotType", "Ocelot types", ChatColor.RED + "/disguisehelp OcelotTypes "
|
||||||
|
+ ChatColor.GREEN + "- View all the ocelot types you can use for ocelots", (Enum[]) Class.forName(
|
||||||
|
"org.bukkit.entity.Ocelot$Type").getEnumConstants()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
enumHelp.add(new EnumHelp("Profession", "Villager professions", ChatColor.RED + "/disguisehelp Professions "
|
||||||
|
+ ChatColor.GREEN + "- View all the professions you can set on a villager", (Enum[]) Class.forName(
|
||||||
|
"org.bukkit.entity.Villager$Profession").getEnumConstants()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ArrayList<String> enumReturns = new ArrayList<String>();
|
||||||
|
for (PotionEffectType potionType : PotionEffectType.values()) {
|
||||||
|
if (potionType != null)
|
||||||
|
enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId()
|
||||||
|
+ ChatColor.RED + ")");
|
||||||
|
}
|
||||||
|
enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect", ChatColor.RED + "/disguisehelp PotionEffect "
|
||||||
|
+ ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns
|
||||||
|
.size()])));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
@ -29,40 +113,16 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
return true;
|
return true;
|
||||||
// sender.sendMessage(ChatColor.RED + "/disguisehelp <Disguise> <Option>");
|
// sender.sendMessage(ChatColor.RED + "/disguisehelp <Disguise> <Option>");
|
||||||
} else {
|
} else {
|
||||||
Enum[] enums = null;
|
EnumHelp help = null;
|
||||||
String enumName = null;
|
for (EnumHelp s : enumHelp) {
|
||||||
ArrayList<String> enumReturns = new ArrayList<String>();
|
if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) {
|
||||||
if (args[0].equalsIgnoreCase("AnimalColor") || args[0].equalsIgnoreCase("AnimalColors")) {
|
help = s;
|
||||||
enums = AnimalColor.values();
|
break;
|
||||||
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")) {
|
|
||||||
enumName = "PotionEffect";
|
|
||||||
for (PotionEffectType potionType : PotionEffectType.values()) {
|
|
||||||
if (potionType != null)
|
|
||||||
enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN
|
|
||||||
+ potionType.getId() + ChatColor.RED + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enums != null) {
|
if (help != null) {
|
||||||
for (Enum enumType : enums) {
|
sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN
|
||||||
enumReturns.add(toReadable(enumType.name()));
|
+ StringUtils.join(help.getEnums(), ChatColor.RED + ", " + ChatColor.GREEN));
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!enumReturns.isEmpty()) {
|
|
||||||
sender.sendMessage(ChatColor.RED + enumName + ": " + ChatColor.GREEN
|
|
||||||
+ StringUtils.join(enumReturns, ChatColor.RED + ", " + ChatColor.GREEN));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DisguiseType type = null;
|
DisguiseType type = null;
|
||||||
@ -102,13 +162,13 @@ 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) {
|
} else if (c.getSimpleName().equals("Style")) {
|
||||||
valueType = "Horse Style";
|
valueType = "Horse Style";
|
||||||
} else if (Color.class == c) {
|
} else if (c.getSimpleName().equals("Color")) {
|
||||||
valueType = "Horse Color";
|
valueType = "Horse Color";
|
||||||
} else if (Type.class == c) {
|
} else if (c.getSimpleName().equals("Type")) {
|
||||||
valueType = "Ocelot type";
|
valueType = "Ocelot type";
|
||||||
} else if (Profession.class == c) {
|
} else if (c.getSimpleName().equals("Profession")) {
|
||||||
valueType = "Villager Profession";
|
valueType = "Villager Profession";
|
||||||
} else if (PotionEffectType.class == c) {
|
} else if (PotionEffectType.class == c) {
|
||||||
valueType = "Potioneffect";
|
valueType = "Potioneffect";
|
||||||
@ -139,18 +199,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
protected void sendCommandUsage(CommandSender sender) {
|
protected void sendCommandUsage(CommandSender sender) {
|
||||||
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN
|
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN
|
||||||
+ "- View the options you can set on a disguise");
|
+ "- View the options you can set on a disguise");
|
||||||
sender.sendMessage(ChatColor.RED + "/disguisehelp AnimalColors " + ChatColor.GREEN
|
for (EnumHelp s : enumHelp) {
|
||||||
+ "- View all the colors you can use for a animal color");
|
sender.sendMessage(s.getEnumDescription());
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toReadable(String string) {
|
public String toReadable(String string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user