Add command sender in the disguise event
This commit is contained in:
		| @@ -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); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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++; | ||||
|   | ||||
| @@ -65,7 +65,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract { | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             DisguiseAPI.disguiseEntity(entity, disguise); | ||||
|             DisguiseAPI.disguiseEntity(p, entity, disguise); | ||||
|  | ||||
|             String disguiseName = disguise.getDisguiseName(); | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -70,7 +70,7 @@ public class UndisguiseRadiusCommand implements CommandExecutor { | ||||
|                 } | ||||
|  | ||||
|                 if (DisguiseAPI.isDisguised(entity)) { | ||||
|                     DisguiseAPI.undisguiseToAll(entity); | ||||
|                     DisguiseAPI.undisguiseToAll(sender, entity); | ||||
|                     disguisedEntitys++; | ||||
|                 } | ||||
|             } | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -54,7 +54,7 @@ public class ParamInfoBlockData extends ParamInfo { | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         return Bukkit.createBlockData(string.toLowerCase()); | ||||
|         return Bukkit.createBlockData(string.toLowerCase(Locale.ROOT)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
		Reference in New Issue
	
	Block a user