diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java index c8852328..707104ea 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java @@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.*; @@ -209,6 +210,10 @@ public class DisguiseAPI { } public static void disguiseEntity(Entity entity, Disguise disguise) { + disguiseEntity(null, entity, disguise); + } + + public static void disguiseEntity(CommandSender commandSender, Entity entity, Disguise disguise) { // If they are trying to disguise a null entity or use a null disguise // Just return. if (entity == null || disguise == null) { @@ -236,7 +241,7 @@ public class DisguiseAPI { disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); } - disguise.startDisguise(); + disguise.startDisguise(commandSender); } public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) { @@ -473,10 +478,21 @@ public class DisguiseAPI { * @param entity */ public static void undisguiseToAll(Entity entity) { + undisguiseToAll(null, entity); + } + + /** + * Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka + * removed from + * the world. + * + * @param entity + */ + public static void undisguiseToAll(CommandSender sender, Entity entity) { Disguise[] disguises = getDisguises(entity); for (Disguise disguise : disguises) { - disguise.removeDisguise(); + disguise.removeDisguise(sender); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java index 75db0fb5..abb5ff7c 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java @@ -78,7 +78,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); } - disguise.startDisguise(); + disguise.startDisguise(sender); if (disguise.isDisguiseInUse()) { LibsMsg.DISGUISED.send(sender, disguise.getDisguiseName()); diff --git a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java index 10f759a3..b71aefac 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java @@ -120,7 +120,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); } - disguise.startDisguise(); + disguise.startDisguise(sender); if (disguise.isDisguiseInUse()) { LibsMsg.DISG_PLAYER_AS_DISG.send(sender, diff --git a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java index bea36859..920e6f4a 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java @@ -200,7 +200,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); } - disguise.startDisguise(); + disguise.startDisguise(sender); if (disguise.isDisguiseInUse()) { disguisedEntitys++; diff --git a/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java b/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java index 99c1ca18..6803cc88 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java +++ b/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java @@ -65,7 +65,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract { } } - DisguiseAPI.disguiseEntity(entity, disguise); + DisguiseAPI.disguiseEntity(p, entity, disguise); String disguiseName = disguise.getDisguiseName(); diff --git a/src/main/java/me/libraryaddict/disguise/commands/interactions/UndisguiseEntityInteraction.java b/src/main/java/me/libraryaddict/disguise/commands/interactions/UndisguiseEntityInteraction.java index 56f06e3b..cc4fc154 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/interactions/UndisguiseEntityInteraction.java +++ b/src/main/java/me/libraryaddict/disguise/commands/interactions/UndisguiseEntityInteraction.java @@ -22,7 +22,7 @@ public class UndisguiseEntityInteraction implements LibsEntityInteract { } if (DisguiseAPI.isDisguised(entity)) { - DisguiseAPI.undisguiseToAll(entity); + DisguiseAPI.undisguiseToAll(p, entity); if (entity instanceof Player) LibsMsg.LISTEN_UNDISG_PLAYER.send(p, entityName); diff --git a/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java index 98eab504..edf7385b 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java @@ -27,7 +27,7 @@ public class UndisguiseCommand implements CommandExecutor { if (sender.hasPermission("libsdisguises.undisguise") && !"%%__USER__%%".equals(12345 + "")) { if (DisguiseAPI.isDisguised((Entity) sender)) { - DisguiseAPI.undisguiseToAll((Player) sender); + DisguiseAPI.undisguiseToAll(sender, (Player) sender); LibsMsg.UNDISG.send(sender); } else { LibsMsg.NOT_DISGUISED.send(sender); diff --git a/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java index 9290bd2f..0be70cdd 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java @@ -86,7 +86,7 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { } if (DisguiseAPI.isDisguised(entityTarget)) { - DisguiseAPI.undisguiseToAll(entityTarget); + DisguiseAPI.undisguiseToAll(sender, entityTarget); LibsMsg.UNDISG_PLAYER.send(sender, entityTarget instanceof Player ? entityTarget.getName() : DisguiseType.getType(entityTarget).toReadable()); diff --git a/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java index ffe3fe15..58989b27 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java @@ -70,7 +70,7 @@ public class UndisguiseRadiusCommand implements CommandExecutor { } if (DisguiseAPI.isDisguised(entity)) { - DisguiseAPI.undisguiseToAll(entity); + DisguiseAPI.undisguiseToAll(sender, entity); disguisedEntitys++; } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 26ac31b4..35a4c8c7 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -34,6 +34,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; +import org.bukkit.command.CommandSender; import org.bukkit.entity.*; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.scheduler.BukkitRunnable; @@ -857,18 +858,26 @@ public abstract class Disguise { return removeDisguise(false); } + public boolean removeDisguise(CommandSender sender) { + return removeDisguise(sender, false); + } + + public boolean removeDisguise(boolean disguiseBeingReplaced) { + return removeDisguise(null, disguiseBeingReplaced); + } + /** * Removes the disguise and undisguises the entity if it's using this disguise. * * @param disguiseBeingReplaced If the entity's disguise is being replaced with another * @return */ - public boolean removeDisguise(boolean disguiseBeingReplaced) { + public boolean removeDisguise(CommandSender sender, boolean disguiseBeingReplaced) { if (!isDisguiseInUse()) { return false; } - UndisguiseEvent event = new UndisguiseEvent(entity, this, disguiseBeingReplaced); + UndisguiseEvent event = new UndisguiseEvent(sender, entity, this, disguiseBeingReplaced); Bukkit.getPluginManager().callEvent(event); @@ -1068,6 +1077,10 @@ public abstract class Disguise { } public boolean startDisguise() { + return startDisguise(null); + } + + public boolean startDisguise(CommandSender commandSender) { if (isDisguiseInUse() || isDisguiseExpired()) { return false; } @@ -1111,7 +1124,7 @@ public abstract class Disguise { DisguiseUtilities.setPluginsUsed(); // Fire a disguise event - DisguiseEvent event = new DisguiseEvent(entity, this); + DisguiseEvent event = new DisguiseEvent(commandSender, entity, this); Bukkit.getPluginManager().callEvent(event); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index 80cae6b2..49d285e6 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -177,7 +178,7 @@ public class PlayerDisguise extends TargetedDisguise { this.nameVisible = nameVisible; sendArmorStands(isNameVisible() ? DisguiseUtilities.reverse(getMultiName()) : new String[0]); } else if (!DisguiseConfig.isScoreboardNames()) { - if (stopDisguise()) { + if (removeDisguise()) { this.nameVisible = nameVisible; if (!startDisguise()) { @@ -395,7 +396,7 @@ public class PlayerDisguise extends TargetedDisguise { } private void resendDisguise(String name, boolean updateTeams) { - if (stopDisguise()) { + if (removeDisguise()) { if (getName().isEmpty() && !name.isEmpty()) { setNameVisible(true, true); } else if (!getName().isEmpty() && name.isEmpty()) { @@ -621,6 +622,11 @@ public class PlayerDisguise extends TargetedDisguise { @Override public boolean startDisguise() { + return startDisguise(null); + } + + @Override + public boolean startDisguise(CommandSender sender) { if (isDisguiseInUse()) { return false; } @@ -666,7 +672,7 @@ public class PlayerDisguise extends TargetedDisguise { setName(name); } - boolean result = super.startDisguise(); + boolean result = super.startDisguise(sender); if (result && hasScoreboardName()) { DisguiseUtilities.registerExtendedName(this); diff --git a/src/main/java/me/libraryaddict/disguise/events/DisguiseEvent.java b/src/main/java/me/libraryaddict/disguise/events/DisguiseEvent.java index 274b130b..af13c08a 100644 --- a/src/main/java/me/libraryaddict/disguise/events/DisguiseEvent.java +++ b/src/main/java/me/libraryaddict/disguise/events/DisguiseEvent.java @@ -1,48 +1,37 @@ package me.libraryaddict.disguise.events; +import lombok.Getter; +import lombok.Setter; import me.libraryaddict.disguise.disguisetypes.Disguise; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +@Getter +@Setter public class DisguiseEvent extends Event implements Cancellable { + @Getter + private static final HandlerList handlerList = new HandlerList(); - private static final HandlerList handlers = new HandlerList(); + private final CommandSender commandSender; + private final Disguise disguise; + private final Entity entity; + private boolean cancelled; - public static HandlerList getHandlerList() { - return handlers; - } - - private Disguise disguise; - private Entity disguised; - private boolean isCancelled; - - public DisguiseEvent(Entity entity, Disguise disguise) { - this.disguised = entity; + public DisguiseEvent(CommandSender sender, Entity entity, Disguise disguise) { + commandSender = sender; + this.entity = entity; this.disguise = disguise; } - public Disguise getDisguise() { - return disguise; - } - - public Entity getEntity() { - return disguised; + public DisguiseEvent(Entity entity, Disguise disguise) { + this(null, entity, disguise); } @Override public HandlerList getHandlers() { - return handlers; - } - - @Override - public boolean isCancelled() { - return isCancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - isCancelled = cancelled; + return handlerList; } } diff --git a/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java b/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java index 63262df2..f15210e3 100644 --- a/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java +++ b/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java @@ -1,54 +1,39 @@ package me.libraryaddict.disguise.events; +import lombok.Getter; +import lombok.Setter; import me.libraryaddict.disguise.disguisetypes.Disguise; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +@Getter +@Setter public class UndisguiseEvent extends Event implements Cancellable { + @Getter + private static final HandlerList handlerList = new HandlerList(); - private static final HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - private Disguise disguise; - private Entity disguised; + private final Disguise disguise; + private final Entity disguised; + private final boolean isBeingReplaced; + private final CommandSender commandSender; private boolean isCancelled; - private boolean isBeingReplaced; public UndisguiseEvent(Entity entity, Disguise disguise, boolean beingReplaced) { + this(null, entity, disguise, beingReplaced); + } + + public UndisguiseEvent(CommandSender sender, Entity entity, Disguise disguise, boolean beingReplaced) { + this.commandSender = sender; this.disguised = entity; this.disguise = disguise; this.isBeingReplaced = beingReplaced; } - public Disguise getDisguise() { - return disguise; - } - - public Entity getEntity() { - return disguised; - } - @Override public HandlerList getHandlers() { - return handlers; - } - - @Override - public boolean isCancelled() { - return isCancelled; - } - - public boolean isBeingReplaced() { - return isBeingReplaced; - } - - @Override - public void setCancelled(boolean cancelled) { - isCancelled = cancelled; + return handlerList; } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoBlockData.java b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoBlockData.java index 56d99c3f..ddc233e5 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoBlockData.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoBlockData.java @@ -54,7 +54,7 @@ public class ParamInfoBlockData extends ParamInfo { return null; } - return Bukkit.createBlockData(string.toLowerCase()); + return Bukkit.createBlockData(string.toLowerCase(Locale.ROOT)); } @Override