Add isBeingReplaced() to UndisguiseEvent. Fixes #309

This commit is contained in:
libraryaddict 2018-10-14 11:26:17 +13:00
parent b42cf5cc43
commit e4d66e36df
3 changed files with 20 additions and 5 deletions

View File

@ -442,10 +442,20 @@ public abstract class Disguise {
* @return removeDiguise * @return removeDiguise
*/ */
public boolean removeDisguise() { 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()) if (!isDisguiseInUse())
return false; return false;
UndisguiseEvent event = new UndisguiseEvent(entity, this); UndisguiseEvent event = new UndisguiseEvent(entity, this, disguiseBeingReplaced);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);

View File

@ -1,12 +1,11 @@
package me.libraryaddict.disguise.events; package me.libraryaddict.disguise.events;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class UndisguiseEvent extends Event implements Cancellable { public class UndisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@ -18,10 +17,12 @@ public class UndisguiseEvent extends Event implements Cancellable {
private Disguise disguise; private Disguise disguise;
private Entity disguised; private Entity disguised;
private boolean isCancelled; private boolean isCancelled;
private boolean isBeingReplaced;
public UndisguiseEvent(Entity entity, Disguise disguise) { public UndisguiseEvent(Entity entity, Disguise disguise, boolean beingReplaced) {
this.disguised = entity; this.disguised = entity;
this.disguise = disguise; this.disguise = disguise;
this.isBeingReplaced = beingReplaced;
} }
public Disguise getDisguise() { public Disguise getDisguise() {
@ -42,6 +43,10 @@ public class UndisguiseEvent extends Event implements Cancellable {
return isCancelled; return isCancelled;
} }
public boolean isBeingReplaced() {
return isBeingReplaced;
}
@Override @Override
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancelled) {
isCancelled = cancelled; isCancelled = cancelled;

View File

@ -407,7 +407,7 @@ public class DisguiseUtilities {
// But the rest of the time.. Its going to conflict. // But the rest of the time.. Its going to conflict.
disguiseItel.remove(); disguiseItel.remove();
d.removeDisguise(); d.removeDisguise(true);
} }
} }
} }