mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-08-22 22:53:01 +02:00
Move Disguise and Undisguise events into the Disguise methods instead of the api calls
This commit is contained in:
parent
264b2ef8a2
commit
7c5a7b0225
|
@ -18,7 +18,6 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
|
||||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||||
|
@ -149,13 +148,6 @@ public class DisguiseAPI {
|
||||||
// Just return.
|
// Just return.
|
||||||
if (entity == null || disguise == null)
|
if (entity == null || disguise == null)
|
||||||
return;
|
return;
|
||||||
// Fire a disguise event
|
|
||||||
DisguiseEvent event = new DisguiseEvent(entity, disguise);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
// If they cancelled this disguise event. No idea why.
|
|
||||||
// Just return.
|
|
||||||
if (event.isCancelled())
|
|
||||||
return;
|
|
||||||
// The event wasn't cancelled.
|
// The event wasn't cancelled.
|
||||||
// If the disguise entity isn't the same as the one we are disguising
|
// If the disguise entity isn't the same as the one we are disguising
|
||||||
if (disguise.getEntity() != entity) {
|
if (disguise.getEntity() != entity) {
|
||||||
|
@ -331,10 +323,6 @@ public class DisguiseAPI {
|
||||||
public static void undisguiseToAll(Entity entity) {
|
public static void undisguiseToAll(Entity entity) {
|
||||||
Disguise[] disguises = getDisguises(entity);
|
Disguise[] disguises = getDisguises(entity);
|
||||||
for (Disguise disguise : disguises) {
|
for (Disguise disguise : disguises) {
|
||||||
UndisguiseEvent event = new UndisguiseEvent(entity, disguise);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if (event.isCancelled())
|
|
||||||
continue;
|
|
||||||
disguise.removeDisguise();
|
disguise.removeDisguise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||||
|
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||||
|
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||||
|
@ -404,6 +406,10 @@ public abstract class Disguise {
|
||||||
*/
|
*/
|
||||||
public void removeDisguise() {
|
public void removeDisguise() {
|
||||||
if (disguiseInUse) {
|
if (disguiseInUse) {
|
||||||
|
UndisguiseEvent event = new UndisguiseEvent(entity, this);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled())
|
||||||
|
return;
|
||||||
disguiseInUse = false;
|
disguiseInUse = false;
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
task.cancel();
|
task.cancel();
|
||||||
|
@ -657,6 +663,13 @@ public abstract class Disguise {
|
||||||
if (getEntity() == null) {
|
if (getEntity() == null) {
|
||||||
throw new RuntimeException("No entity is assigned to this disguise!");
|
throw new RuntimeException("No entity is assigned to this disguise!");
|
||||||
}
|
}
|
||||||
|
// Fire a disguise event
|
||||||
|
DisguiseEvent event = new DisguiseEvent(entity, this);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
// If they cancelled this disguise event. No idea why.
|
||||||
|
// Just return.
|
||||||
|
if (event.isCancelled())
|
||||||
|
return;
|
||||||
disguiseInUse = true;
|
disguiseInUse = true;
|
||||||
task = Bukkit.getScheduler().runTaskTimer(plugin, velocityRunnable, 1, 1);
|
task = Bukkit.getScheduler().runTaskTimer(plugin, velocityRunnable, 1, 1);
|
||||||
// Stick the disguise in the disguises bin
|
// Stick the disguise in the disguises bin
|
||||||
|
|
Loading…
Reference in New Issue
Block a user