Give getDisguise a perf boost

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

@ -2807,30 +2807,38 @@ 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()) {
for (Entity entity : world.getEntities()) {
if (entity.getEntityId() != entityId) {
continue;
}
onFutureDisguise(entity); onFutureDisguise(entity);
} }
}
TargetedDisguise[] disguises = getDisguises(entity.getUniqueId());
if (disguises == null) {
return null;
} }
for (Set<TargetedDisguise> disguises : getDisguises().values()) {
for (TargetedDisguise dis : disguises) { for (TargetedDisguise dis : disguises) {
if (dis.getEntity() == null || !dis.isDisguiseInUse()) { if (!dis.isDisguiseInUse()) {
continue;
}
if (dis.getEntity().getEntityId() != entityId) {
continue; continue;
} }
@ -2840,7 +2848,6 @@ public class DisguiseUtilities {
return dis; return dis;
} }
}
return null; return null;
} }