From e4d66e36dff6a7b1974b033ca06fb94cc19ab9b6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 14 Oct 2018 11:26:17 +1300 Subject: [PATCH] Add isBeingReplaced() to UndisguiseEvent. Fixes #309 --- .../disguise/disguisetypes/Disguise.java | 12 +++++++++++- .../disguise/events/UndisguiseEvent.java | 11 ++++++++--- .../disguise/utilities/DisguiseUtilities.java | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 56d1ca1d..77a0d10a 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -442,10 +442,20 @@ public abstract class Disguise { * @return removeDiguise */ public boolean removeDisguise() { + return removeDisguise(false); + } + + /** + * 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) { if (!isDisguiseInUse()) return false; - UndisguiseEvent event = new UndisguiseEvent(entity, this); + UndisguiseEvent event = new UndisguiseEvent(entity, this, disguiseBeingReplaced); Bukkit.getPluginManager().callEvent(event); diff --git a/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java b/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java index 4296f55f..63262df2 100644 --- a/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java +++ b/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java @@ -1,12 +1,11 @@ package me.libraryaddict.disguise.events; +import me.libraryaddict.disguise.disguisetypes.Disguise; import org.bukkit.entity.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import me.libraryaddict.disguise.disguisetypes.Disguise; - public class UndisguiseEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); @@ -18,10 +17,12 @@ public class UndisguiseEvent extends Event implements Cancellable { private Disguise disguise; private Entity disguised; private boolean isCancelled; + private boolean isBeingReplaced; - public UndisguiseEvent(Entity entity, Disguise disguise) { + public UndisguiseEvent(Entity entity, Disguise disguise, boolean beingReplaced) { this.disguised = entity; this.disguise = disguise; + this.isBeingReplaced = beingReplaced; } public Disguise getDisguise() { @@ -42,6 +43,10 @@ public class UndisguiseEvent extends Event implements Cancellable { return isCancelled; } + public boolean isBeingReplaced() { + return isBeingReplaced; + } + @Override public void setCancelled(boolean cancelled) { isCancelled = cancelled; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index b9a95b7b..0fdf5ea3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -407,7 +407,7 @@ public class DisguiseUtilities { // But the rest of the time.. Its going to conflict. disguiseItel.remove(); - d.removeDisguise(); + d.removeDisguise(true); } } }