From bd317b4cce1a83c43dec2d3ce941ca933c1d747e Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 21 Jun 2014 07:29:34 +1200 Subject: [PATCH] Don't silently fail when a disguisetype has a null entitytype --- .../commands/DisguiseHelpCommand.java | 3 --- .../utilities/BaseDisguiseCommand.java | 19 ++++++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index b33bbef9..2a878496 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -138,9 +138,6 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { } DisguiseType type = null; for (DisguiseType disguiseType : DisguiseType.values()) { - if (disguiseType.getEntityType() == null) { - continue; - } if (args[0].equalsIgnoreCase(disguiseType.name()) || disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) { type = disguiseType; diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index 12d259f5..d33d0f2c 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -17,6 +17,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Ageable; import org.bukkit.entity.Animals; +import org.bukkit.entity.Entity; import org.bukkit.entity.Monster; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; @@ -66,8 +67,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { String disguiseType = perm.split("\\.")[0]; try { DisguiseType type = DisguiseType.valueOf(disguiseType.toUpperCase()); - if (type.getEntityType() == null) - continue; HashMap, Boolean> list; if (singleDisguises.containsKey(type)) { list = singleDisguises.get(type); @@ -79,11 +78,8 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { list.put(map1.keySet().iterator().next(), map1.values().iterator().next()); } catch (Exception ex) { for (DisguiseType type : DisguiseType.values()) { - if (type.getEntityType() == null) { - continue; - } HashMap, Boolean> options = null; - Class entityClass = type.getEntityType().getEntityClass(); + Class entityClass = type.getEntityType() == null ? Entity.class : type.getEntityType().getEntityClass(); if (disguiseType.equals("mob")) { if (type.isMob()) { options = getOptions(perm); @@ -131,11 +127,8 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { singleDisguises.remove(type); } catch (Exception ex) { for (DisguiseType type : DisguiseType.values()) { - if (type.getEntityType() == null) { - continue; - } boolean foundHim = false; - Class entityClass = type.getEntityType().getEntityClass(); + Class entityClass = type.getEntityType() == null ? Entity.class : type.getEntityType().getEntityClass(); if (disguiseType.equals("mob")) { if (type.isMob()) { foundHim = true; @@ -258,9 +251,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { disguiseType = DisguiseType.PLAYER; } else { for (DisguiseType type : DisguiseType.values()) { - if (type.getEntityType() == null) { - continue; - } if (args[0].equalsIgnoreCase(type.name()) || args[0].equalsIgnoreCase(type.name().replace("_", ""))) { disguiseType = type; break; @@ -271,6 +261,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { throw new Exception(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0] + ChatColor.RED + " doesn't exist!"); } + if (disguiseType.getEntityType() == null) { + throw new Exception(ChatColor.RED + "Error! This version of minecraft does not have that disguise!"); + } if (!map.containsKey(disguiseType)) { throw new Exception(ChatColor.RED + "You are forbidden to use this disguise."); }