Read desc

Added boolean to disguise which tells you simply if the disguise is in
use or not.
In use means that the plugin stores a reference, doesn't nessercerily
mean there is a entity.

Added method startDisguise() to disguise and cleaned up setEntity().
Helps counter the idiots who hate DisguiseAPI
This commit is contained in:
libraryaddict 2014-06-05 00:30:12 +12:00
parent f894b34264
commit 7cde5b755e
2 changed files with 36 additions and 11 deletions

View File

@ -167,12 +167,7 @@ public class DisguiseAPI {
// Set the disguise's entity // Set the disguise's entity
disguise.setEntity(entity); disguise.setEntity(entity);
} }
// Stick the disguise in the disguises bin disguise.startDisguise();
DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) disguise);
// Resend the disguised entity's packet
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
// If he is a player, then self disguise himself
DisguiseUtilities.setupFakeDisguise(disguise);
} }
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) { public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) {
@ -326,7 +321,7 @@ public class DisguiseAPI {
} }
public static boolean isDisguiseInUse(Disguise disguise) { public static boolean isDisguiseInUse(Disguise disguise) {
return DisguiseUtilities.isDisguiseInUse(disguise); return disguise.isDisguiseInUse();
} }
/** /**

View File

@ -33,6 +33,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
public abstract class Disguise { public abstract class Disguise {
private static JavaPlugin plugin; private static JavaPlugin plugin;
private boolean disguiseInUse;
private DisguiseType disguiseType; private DisguiseType disguiseType;
private Entity entity; private Entity entity;
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced(); private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
@ -326,6 +327,14 @@ public abstract class Disguise {
return watcher; return watcher;
} }
/**
* In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to the disguise.
* getEntity() can still return null if this disguise is active after despawn, logout, etc.
*/
public boolean isDisguiseInUse() {
return disguiseInUse;
}
public boolean isHidingArmorFromSelf() { public boolean isHidingArmorFromSelf() {
return hideArmorFromSelf; return hideArmorFromSelf;
} }
@ -398,9 +407,12 @@ 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() {
if (disguiseInUse) {
disguiseInUse = false;
if (taskId != -1) { if (taskId != -1) {
Bukkit.getScheduler().cancelTask(taskId); Bukkit.getScheduler().cancelTask(taskId);
taskId = -1; taskId = -1;
}
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) {
@ -461,7 +473,6 @@ public abstract class Disguise {
} }
this.entity = entity; this.entity = entity;
setupWatcher(); setupWatcher();
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, velocityRunnable, 1, 1);
} }
public void setHearSelfDisguise(boolean hearSelfDisguise) { public void setHearSelfDisguise(boolean hearSelfDisguise) {
@ -640,5 +651,24 @@ public abstract class Disguise {
+ getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name()); + getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name());
} }
watcher = newWatcher; watcher = newWatcher;
if (getEntity() != null) {
setupWatcher();
}
}
public void startDisguise() {
if (!isDisguiseInUse()) {
if (getEntity() == null) {
throw new RuntimeException("No entity is assigned to this disguise!");
}
disguiseInUse = true;
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, velocityRunnable, 1, 1);
// Stick the disguise in the disguises bin
DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this);
// Resend the disguised entity's packet
DisguiseUtilities.refreshTrackers((TargetedDisguise) this);
// If he is a player, then self disguise himself
DisguiseUtilities.setupFakeDisguise(this);
}
} }
} }