Give errors when they attempt to use misc disguise on living entities with commands
This commit is contained in:
parent
72d07e7f62
commit
b44aba87d4
@ -12,6 +12,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.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
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;
|
||||||
@ -120,9 +121,10 @@ public class DisguiseListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRightClick(PlayerInteractEntityEvent event) {
|
public void onRightClick(PlayerInteractEntityEvent event) {
|
||||||
if (disguiseSlap.containsKey(event.getPlayer().getName())) {
|
if (disguiseSlap.containsKey(event.getPlayer().getName())) {
|
||||||
|
Player p = event.getPlayer();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Disguise disguise = disguiseSlap.remove(event.getPlayer().getName());
|
Disguise disguise = disguiseSlap.remove(p.getName());
|
||||||
disguiseRunnable.remove(event.getPlayer().getName()).cancel();
|
disguiseRunnable.remove(p.getName()).cancel();
|
||||||
Entity entity = event.getRightClicked();
|
Entity entity = event.getRightClicked();
|
||||||
String entityName = "";
|
String entityName = "";
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
@ -137,6 +139,11 @@ public class DisguiseListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (disguise != null) {
|
if (disguise != null) {
|
||||||
|
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 {
|
||||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName());
|
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName());
|
||||||
@ -158,17 +165,15 @@ public class DisguiseListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.getPlayer().sendMessage(
|
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as "
|
||||||
ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as "
|
|
||||||
+ disguiseName + "!");
|
+ disguiseName + "!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DisguiseAPI.isDisguised(entity)) {
|
if (DisguiseAPI.isDisguised(entity)) {
|
||||||
DisguiseAPI.undisguiseToAll(entity);
|
DisguiseAPI.undisguiseToAll(entity);
|
||||||
event.getPlayer().sendMessage(
|
p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
|
||||||
ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
|
|
||||||
} else
|
} else
|
||||||
event.getPlayer().sendMessage(
|
p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
|
||||||
ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,11 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
|||||||
}
|
}
|
||||||
return true;
|
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 (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) player).getDisplayName());
|
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) player).getDisplayName());
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
||||||
@ -66,9 +67,14 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
|||||||
return true;
|
return true;
|
||||||
} // Time to use it!
|
} // Time to use it!
|
||||||
int disguisedEntitys = 0;
|
int disguisedEntitys = 0;
|
||||||
|
int miscDisguises = 0;
|
||||||
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
|
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
|
||||||
if (entity == sender)
|
if (entity == sender)
|
||||||
continue;
|
continue;
|
||||||
|
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
|
||||||
|
miscDisguises++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
disguise = disguise.clone();
|
disguise = disguise.clone();
|
||||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
@ -81,7 +87,15 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
|||||||
DisguiseAPI.disguiseToAll(entity, disguise);
|
DisguiseAPI.disguiseToAll(entity, disguise);
|
||||||
disguisedEntitys++;
|
disguisedEntitys++;
|
||||||
}
|
}
|
||||||
|
if (disguisedEntitys > 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user