From b44aba87d4c8a81e946932f69823232767b353f3 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 23 May 2014 08:22:07 +1200 Subject: [PATCH] Give errors when they attempt to use misc disguise on living entities with commands --- .../disguise/DisguiseListener.java | 57 ++++++++++--------- .../commands/DisguisePlayerCommand.java | 5 ++ .../commands/DisguiseRadiusCommand.java | 16 +++++- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 8787ac5d..aa20e320 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -12,6 +12,7 @@ import me.libraryaddict.disguise.utilities.UpdateChecker; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -120,9 +121,10 @@ public class DisguiseListener implements Listener { @EventHandler public void onRightClick(PlayerInteractEntityEvent event) { if (disguiseSlap.containsKey(event.getPlayer().getName())) { + Player p = event.getPlayer(); event.setCancelled(true); - Disguise disguise = disguiseSlap.remove(event.getPlayer().getName()); - disguiseRunnable.remove(event.getPlayer().getName()).cancel(); + Disguise disguise = disguiseSlap.remove(p.getName()); + disguiseRunnable.remove(p.getName()).cancel(); Entity entity = event.getRightClicked(); String entityName = ""; if (entity instanceof Player) { @@ -137,38 +139,41 @@ public class DisguiseListener implements Listener { } } if (disguise != null) { - if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { - if (disguise.getWatcher() instanceof LivingWatcher) { - ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName()); - if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { - ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); - } - } - } - DisguiseAPI.disguiseToAll(entity, disguise); - String disguiseName = "a "; - if (disguise instanceof PlayerDisguise) { - disguiseName = "the player " + ((PlayerDisguise) disguise).getName(); + if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() + && entity instanceof LivingEntity) { + p.sendMessage(ChatColor.RED + + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); } else { - String[] split = disguise.getType().name().split("_"); - for (int i = 0; i < split.length; i++) { - disguiseName += split[0].substring(0, 1) + split[0].substring(1).toLowerCase(); - if (i + 1 < split.length) { - disguiseName += " "; + if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { + if (disguise.getWatcher() instanceof LivingWatcher) { + ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName()); + if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { + ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); + } } } + DisguiseAPI.disguiseToAll(entity, disguise); + String disguiseName = "a "; + if (disguise instanceof PlayerDisguise) { + disguiseName = "the player " + ((PlayerDisguise) disguise).getName(); + } else { + String[] split = disguise.getType().name().split("_"); + for (int i = 0; i < split.length; i++) { + disguiseName += split[0].substring(0, 1) + split[0].substring(1).toLowerCase(); + if (i + 1 < split.length) { + disguiseName += " "; + } + } + } + p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as " + + disguiseName + "!"); } - event.getPlayer().sendMessage( - ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as " - + disguiseName + "!"); } else { if (DisguiseAPI.isDisguised(entity)) { DisguiseAPI.undisguiseToAll(entity); - event.getPlayer().sendMessage( - ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName); + p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName); } else - event.getPlayer().sendMessage( - ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!"); + p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!"); } } } diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 35d54b92..720fb188 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -52,6 +52,11 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { } return true; } + if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) { + sender.sendMessage(ChatColor.RED + + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); + return true; + } if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { if (disguise.getWatcher() instanceof LivingWatcher) { ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) player).getDisplayName()); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 330b627a..9631dd2c 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -13,6 +13,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; public class DisguiseRadiusCommand extends BaseDisguiseCommand { @@ -66,9 +67,14 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { return true; } // Time to use it! int disguisedEntitys = 0; + int miscDisguises = 0; for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { if (entity == sender) continue; + if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { + miscDisguises++; + continue; + } disguise = disguise.clone(); if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { if (disguise.getWatcher() instanceof LivingWatcher) { @@ -81,7 +87,15 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { DisguiseAPI.disguiseToAll(entity, disguise); disguisedEntitys++; } - sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); + if (disguisedEntitys > 0) { + sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); + } else { + sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!"); + } + if (miscDisguises > 0) { + sender.sendMessage(ChatColor.RED + "Failed to disguise " + miscDisguises + + " entities because the option to disguise a living entity as a non-living has been disabled in the config"); + } return true; }