Use schedulers instead of BukkitRunnable. Supports re-disguising!
This commit is contained in:
parent
1b914b9c7b
commit
31252e896e
@ -43,7 +43,8 @@ public abstract class Disguise {
|
||||
private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout();
|
||||
private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox();
|
||||
private boolean replaceSounds = DisguiseConfig.isSoundEnabled();
|
||||
private BukkitRunnable velocityRunnable;
|
||||
private Runnable velocityRunnable;
|
||||
private int taskId = -1;
|
||||
private boolean velocitySent = DisguiseConfig.isVelocitySent();
|
||||
private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises();
|
||||
private FlagWatcher watcher;
|
||||
@ -178,7 +179,7 @@ public abstract class Disguise {
|
||||
final double vectorY = velocitySpeed;
|
||||
final TargetedDisguise disguise = (TargetedDisguise) this;
|
||||
// A scheduler to clean up any unused disguises.
|
||||
velocityRunnable = new BukkitRunnable() {
|
||||
velocityRunnable = new Runnable() {
|
||||
private int deadTicks = 0;
|
||||
private int refreshDisguise = 0;
|
||||
|
||||
@ -196,7 +197,8 @@ public abstract class Disguise {
|
||||
} else {
|
||||
entity = null;
|
||||
watcher = getWatcher().clone(disguise);
|
||||
cancel();
|
||||
Bukkit.getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -399,11 +401,9 @@ public abstract class Disguise {
|
||||
* Removes the disguise and undisguises the entity if its using this disguise. This doesn't fire a UndisguiseEvent
|
||||
*/
|
||||
public void removeDisguise() {
|
||||
// Why the hell can't I safely check if its running?!?!
|
||||
try {
|
||||
velocityRunnable.cancel();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
if (taskId != -1) {
|
||||
Bukkit.getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises();
|
||||
// If this disguise has a entity set
|
||||
if (getEntity() != null) {
|
||||
@ -432,6 +432,7 @@ public abstract class Disguise {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the entity of the disguise. Only used for internal things.
|
||||
@ -444,7 +445,7 @@ public abstract class Disguise {
|
||||
}
|
||||
this.entity = entity;
|
||||
setupWatcher();
|
||||
velocityRunnable.runTaskTimer(plugin, 1, 1);
|
||||
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, velocityRunnable, 1, 1);
|
||||
}
|
||||
|
||||
public void setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
|
Loading…
Reference in New Issue
Block a user