From cfaaa9f421a63652606d9f6d719fb9f318c523e9 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 7 Apr 2014 02:04:41 +0200 Subject: [PATCH] Improved AREntityType --- .../mcore/cmd/arg/AREntityType.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/mcore/cmd/arg/AREntityType.java b/src/com/massivecraft/mcore/cmd/arg/AREntityType.java index 79855fb3..3088a0af 100644 --- a/src/com/massivecraft/mcore/cmd/arg/AREntityType.java +++ b/src/com/massivecraft/mcore/cmd/arg/AREntityType.java @@ -26,23 +26,38 @@ public class AREntityType extends ARAbstractSelect return "entity type"; } - @SuppressWarnings("deprecation") @Override public EntityType select(String arg, CommandSender sender) { - return EntityType.fromName(arg); + arg = getComparable(arg); + + // Custom Detection + if (arg.contains("pig") && (arg.contains("man") || arg.contains("zombie"))) return EntityType.PIG_ZOMBIE; + + // Algorithmic General Detection + for (EntityType entityType : EntityType.values()) + { + if (getComparable(entityType.toString()).equals(arg)) return entityType; + } + + // Nothing found + return null; } - @SuppressWarnings("deprecation") @Override public Collection altNames(CommandSender sender) { List ret = new ArrayList(); for (EntityType entityType : EntityType.values()) { - ret.add(entityType.getName()); + ret.add(getComparable(entityType.toString())); } return ret; } + public static String getComparable(String string) + { + return string.toLowerCase().replaceAll("[_-\\s]+", ""); + } + }