From fb09d9313661af63f247e4aa32d2f160e0d2e266 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 27 Sep 2014 15:50:38 +1200 Subject: [PATCH] Add RabbitType --- .../commands/DisguiseHelpCommand.java | 3 +++ .../disguise/disguisetypes/RabbitType.java | 23 +++++++++++++++++++ .../utilities/BaseDisguiseCommand.java | 20 ++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/me/libraryaddict/disguise/disguisetypes/RabbitType.java diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index 63fd498b..f0c37dfc 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -9,6 +9,7 @@ import java.util.HashMap; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.RabbitType; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.BaseDisguiseCommand; @@ -116,6 +117,8 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { } enumHelp.add(new EnumHelp("Direction", "Directions", ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN + "- View the five directions usable on player setsleeping disguise", Arrays.copyOf(BlockFace.values(), 5))); + enumHelp.add(new EnumHelp("RabbitType", "RabbitType", ChatColor.RED + "/disguisehelp RabbitType " + ChatColor.GREEN + + "View the kinds of rabbits you can turn into", RabbitType.values())); } @Override diff --git a/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java b/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java new file mode 100644 index 00000000..6fa778a9 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java @@ -0,0 +1,23 @@ +package me.libraryaddict.disguise.disguisetypes; + +public enum RabbitType { + BLACK(2), BLACK_AND_WHITE(3), BROWN(0), GOLD(4), KILLER_BUNNY(99), PEPPER(5), WHITE(1); + public static RabbitType getType(int id) { + for (RabbitType type : values()) { + if (type.getTypeId() == id) { + return type; + } + } + return null; + } + + private int type; + + private RabbitType(int type) { + this.type = type; + } + + public int getTypeId() { + return type; + } +} diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index cfc71ce8..741f5009 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -15,6 +15,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import me.libraryaddict.disguise.disguisetypes.MobDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; +import me.libraryaddict.disguise.disguisetypes.RabbitType; import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion; import org.bukkit.ChatColor; @@ -583,11 +584,26 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { } else if (param == BlockFace.class) { try { BlockFace face = BlockFace.valueOf(valueString.toUpperCase()); - if (face.ordinal() > 3) + if (face.ordinal() > 4) throw new DisguiseParseException(); value = face; } catch (Exception ex) { - throw parseToException("a direction (north, east, south, west)", valueString, methodName); + throw parseToException("a direction (north, east, south, west, up)", valueString, methodName); + } + } else if (param == RabbitType.class) { + try { + for (RabbitType type : RabbitType.values()) { + if (type.name().replace("_", "") + .equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) { + value = type; + break; + } + } + if (value == null) { + throw new Exception(); + } + } catch (Exception ex) { + throw parseToException("rabbit type (white, brown, salt and pepper...)", valueString, methodName); } } }