From b93f5d3ea4503add2470fd72bb713a76059c16ee Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 23 Nov 2013 04:21:03 +1300 Subject: [PATCH] Change disguisehelp to use reflection for watcher values and a new EnumHelp thingy --- .../commands/DisguiseHelpCommand.java | 155 ++++++++++++------ 1 file changed, 103 insertions(+), 52 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index b75ab5a9..152a9715 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -10,14 +10,98 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; 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.potion.PotionEffectType; 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 = new ArrayList(); + + 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 enumReturns = new ArrayList(); + 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 public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { @@ -29,40 +113,16 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { return true; // sender.sendMessage(ChatColor.RED + "/disguisehelp