Give getDisguise a perf boost

This commit is contained in:
libraryaddict 2020-08-11 11:03:12 +12:00
parent 2efda17935
commit 50022ee13a

View File

@ -2807,39 +2807,46 @@ public class DisguiseUtilities {
} }
public static Disguise getDisguise(Player observer, int entityId) { public static Disguise getDisguise(Player observer, int entityId) {
Entity entity = null;
// If the entity ID is the same as self disguises id, then it needs to be set to the observers id // If the entity ID is the same as self disguises id, then it needs to be set to the observers id
if (entityId == DisguiseAPI.getSelfDisguiseId()) { if (entityId == DisguiseAPI.getSelfDisguiseId()) {
entityId = observer.getEntityId(); entity = observer;
} else {
for (Entity e : observer.getWorld().getEntities()) {
if (e.getEntityId() != entityId) {
continue;
}
entity = e;
break;
}
if (entity == null) {
return null;
}
} }
if (getFutureDisguises().containsKey(entityId)) { if (getFutureDisguises().containsKey(entityId)) {
for (World world : Bukkit.getWorlds()) { onFutureDisguise(entity);
for (Entity entity : world.getEntities()) {
if (entity.getEntityId() != entityId) {
continue;
}
onFutureDisguise(entity);
}
}
} }
for (Set<TargetedDisguise> disguises : getDisguises().values()) { TargetedDisguise[] disguises = getDisguises(entity.getUniqueId());
for (TargetedDisguise dis : disguises) {
if (dis.getEntity() == null || !dis.isDisguiseInUse()) {
continue;
}
if (dis.getEntity().getEntityId() != entityId) { if (disguises == null) {
continue; return null;
} }
if (!dis.canSee(observer)) { for (TargetedDisguise dis : disguises) {
continue; if (!dis.isDisguiseInUse()) {
} continue;
return dis;
} }
if (!dis.canSee(observer)) {
continue;
}
return dis;
} }
return null; return null;