Changed disguise entity command to do better messages

This commit is contained in:
libraryaddict 2014-05-13 22:32:15 +12:00
parent 720c4f3c66
commit b7dfb2c66b

View File

@ -10,6 +10,7 @@ import me.libraryaddict.disguise.utilities.UpdateChecker;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -62,10 +63,11 @@ public class DisguiseListener implements Listener {
} }
} }
}, 0, (20 * 60 * 60 * 6)); // Check every 6 hours }, 0, (20 * 60 * 60 * 6)); // Check every 6 hours
// 20 ticks * 60 seconds * 60 minutes * 6 hours
} }
} }
private void checkPlayer(Player entity) { private void checkPlayerCanBlowDisguise(Player entity) {
Disguise[] disguises = DisguiseAPI.getDisguises(entity); Disguise[] disguises = DisguiseAPI.getDisguises(entity);
if (disguises.length > 0) { if (disguises.length > 0) {
DisguiseAPI.undisguiseToAll(entity); DisguiseAPI.undisguiseToAll(entity);
@ -79,10 +81,10 @@ public class DisguiseListener implements Listener {
public void onAttack(EntityDamageByEntityEvent event) { public void onAttack(EntityDamageByEntityEvent event) {
if (DisguiseConfig.isDisguiseBlownOnAttack()) { if (DisguiseConfig.isDisguiseBlownOnAttack()) {
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
checkPlayer((Player) event.getEntity()); checkPlayerCanBlowDisguise((Player) event.getEntity());
} }
if (event.getDamager() instanceof Player) { if (event.getDamager() instanceof Player) {
checkPlayer((Player) event.getDamager()); checkPlayerCanBlowDisguise((Player) event.getDamager());
} }
} }
} }
@ -120,27 +122,35 @@ public class DisguiseListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
Disguise disguise = disguiseSlap.remove(event.getPlayer().getName()); Disguise disguise = disguiseSlap.remove(event.getPlayer().getName());
disguiseRunnable.remove(event.getPlayer().getName()).cancel(); disguiseRunnable.remove(event.getPlayer().getName()).cancel();
String entityName = event.getRightClicked().getType().name().toLowerCase().replace("_", " "); Entity entity = event.getRightClicked();
String entityName = entity.getType().name().toLowerCase().replace("_", " ");
if (entity instanceof Player) {
entityName = ((Player) entity).getName();
} else {
String[] split = entity.getType().name().split("_");
entityName = split[0].substring(1).toLowerCase() + " " + split[1].substring(1).toLowerCase();
}
if (disguise != null) { if (disguise != null) {
if (event.getRightClicked() instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) { if (disguise.getWatcher() instanceof LivingWatcher) {
((LivingWatcher) disguise.getWatcher()) ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName());
.setCustomName(((Player) event.getRightClicked()).getDisplayName());
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
} }
} }
} }
DisguiseAPI.disguiseToAll(event.getRightClicked(), disguise); DisguiseAPI.disguiseToAll(entity, disguise);
event.getPlayer().sendMessage( event.getPlayer().sendMessage(
ChatColor.RED + "Disguised the " + entityName + " as a " ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as a "
+ disguise.getType().name().toLowerCase().replace("_", " ") + "!"); + disguise.getType().name().toLowerCase().replace("_", " ") + "!");
} else { } else {
if (DisguiseAPI.isDisguised(event.getRightClicked())) { if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(event.getRightClicked()); DisguiseAPI.undisguiseToAll(entity);
event.getPlayer().sendMessage(ChatColor.RED + "Undisguised the " + entityName); event.getPlayer().sendMessage(
ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
} else } else
event.getPlayer().sendMessage(ChatColor.RED + entityName + " isn't disguised!"); event.getPlayer().sendMessage(
ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
} }
} }
} }