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