Fix a performance issue, fixes #503
This commit is contained in:
		| @@ -363,7 +363,7 @@ public class DisguiseAPI { | |||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return DisguiseUtilities.getMainDisguise(disguised.getUniqueId()); |         return DisguiseUtilities.getMainDisguise(disguised.getEntityId()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String parseToString(Disguise disguise, boolean outputSkin) { |     public static String parseToString(Disguise disguise, boolean outputSkin) { | ||||||
| @@ -400,7 +400,7 @@ public class DisguiseAPI { | |||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return DisguiseUtilities.getDisguises(disguised.getUniqueId()); |         return DisguiseUtilities.getDisguises(disguised.getEntityId()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getSelfDisguiseId() { |     public static int getSelfDisguiseId() { | ||||||
|   | |||||||
| @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringEscapeUtils; | |||||||
| import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.ChatColor; | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.Material; | ||||||
| import org.bukkit.NamespacedKey; | import org.bukkit.NamespacedKey; | ||||||
| import org.bukkit.boss.BarColor; | import org.bukkit.boss.BarColor; | ||||||
| import org.bukkit.boss.BarStyle; | import org.bukkit.boss.BarStyle; | ||||||
| @@ -29,6 +30,7 @@ import org.bukkit.configuration.ConfigurationSection; | |||||||
| import org.bukkit.configuration.file.FileConfiguration; | import org.bukkit.configuration.file.FileConfiguration; | ||||||
| import org.bukkit.configuration.file.YamlConfiguration; | import org.bukkit.configuration.file.YamlConfiguration; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
| import org.bukkit.permissions.Permission; | import org.bukkit.permissions.Permission; | ||||||
| import org.bukkit.permissions.PermissionDefault; | import org.bukkit.permissions.PermissionDefault; | ||||||
| import org.bukkit.scheduler.BukkitTask; | import org.bukkit.scheduler.BukkitTask; | ||||||
| @@ -298,6 +300,7 @@ public class DisguiseConfig { | |||||||
|                     for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) { |                     for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) { | ||||||
|                         for (Disguise disguise : disguises) { |                         for (Disguise disguise : disguises) { | ||||||
|                             disguise.getWatcher().setSprinting(true); |                             disguise.getWatcher().setSprinting(true); | ||||||
|  |                             disguise.getWatcher().setHelmet(new ItemStack(Material.LEATHER_HELMET)); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -1144,7 +1144,7 @@ public abstract class Disguise { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Stick the disguise in the disguises bin |         // Stick the disguise in the disguises bin | ||||||
|         DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this); |         DisguiseUtilities.addDisguise(entity.getEntityId(), (TargetedDisguise) this); | ||||||
|  |  | ||||||
|         if (isSelfDisguiseVisible() && getEntity() instanceof Player) { |         if (isSelfDisguiseVisible() && getEntity() instanceof Player) { | ||||||
|             DisguiseUtilities.removeSelfDisguise(this); |             DisguiseUtilities.removeSelfDisguise(this); | ||||||
|   | |||||||
| @@ -129,7 +129,7 @@ public class DisguiseUtilities { | |||||||
|      * A hashmap of the uuid's of entitys, alive and dead. And their disguises in use |      * A hashmap of the uuid's of entitys, alive and dead. And their disguises in use | ||||||
|      */ |      */ | ||||||
|     @Getter |     @Getter | ||||||
|     private static final Map<UUID, Set<TargetedDisguise>> disguises = new HashMap<>(); |     private static final Map<Integer, Set<TargetedDisguise>> disguises = new HashMap<>(); | ||||||
|     /** |     /** | ||||||
|      * Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only |      * Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only | ||||||
|      * stay in for |      * stay in for | ||||||
| @@ -546,9 +546,9 @@ public class DisguiseUtilities { | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void addDisguise(UUID entityUUID, TargetedDisguise disguise) { |     public static void addDisguise(Integer entityId, TargetedDisguise disguise) { | ||||||
|         if (!getDisguises().containsKey(entityUUID)) { |         if (!getDisguises().containsKey(entityId)) { | ||||||
|             getDisguises().put(entityUUID, new HashSet<>()); |             getDisguises().put(entityId, new HashSet<>()); | ||||||
|  |  | ||||||
|             synchronized (isNoInteract) { |             synchronized (isNoInteract) { | ||||||
|                 Entity entity = disguise.getEntity(); |                 Entity entity = disguise.getEntity(); | ||||||
| @@ -586,7 +586,7 @@ public class DisguiseUtilities { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         getDisguises().get(entityUUID).add(disguise); |         getDisguises().get(entityId).add(disguise); | ||||||
|  |  | ||||||
|         checkConflicts(disguise, null); |         checkConflicts(disguise, null); | ||||||
|  |  | ||||||
| @@ -601,10 +601,8 @@ public class DisguiseUtilities { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         UUID uniqueId = entity.getUniqueId(); |  | ||||||
|  |  | ||||||
|         for (TargetedDisguise disguise : getFutureDisguises().remove(entity.getEntityId())) { |         for (TargetedDisguise disguise : getFutureDisguises().remove(entity.getEntityId())) { | ||||||
|             addDisguise(uniqueId, disguise); |             addDisguise(entity.getEntityId(), disguise); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -673,7 +671,7 @@ public class DisguiseUtilities { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getUniqueId()).iterator(); |         Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getEntityId()).iterator(); | ||||||
|  |  | ||||||
|         // Iterate through the disguises |         // Iterate through the disguises | ||||||
|         while (disguiseItel.hasNext()) { |         while (disguiseItel.hasNext()) { | ||||||
| @@ -832,11 +830,11 @@ public class DisguiseUtilities { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static TargetedDisguise getDisguise(Player observer, Entity entity) { |     public static TargetedDisguise getDisguise(Player observer, Entity entity) { | ||||||
|         UUID entityId = entity.getUniqueId(); |         int entityId = entity.getEntityId(); | ||||||
|  |  | ||||||
|         if (futureDisguises.containsKey(entity.getEntityId())) { |         if (futureDisguises.containsKey(entityId)) { | ||||||
|             for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) { |             for (TargetedDisguise disguise : futureDisguises.remove(entityId)) { | ||||||
|                 addDisguise(entityId, disguise); |                 addDisguise(entity.getEntityId(), disguise); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -853,7 +851,7 @@ public class DisguiseUtilities { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static TargetedDisguise[] getDisguises(UUID entityId) { |     public static TargetedDisguise[] getDisguises(Integer entityId) { | ||||||
|         if (getDisguises().containsKey(entityId)) { |         if (getDisguises().containsKey(entityId)) { | ||||||
|             Set<TargetedDisguise> disguises = getDisguises().get(entityId); |             Set<TargetedDisguise> disguises = getDisguises().get(entityId); | ||||||
|  |  | ||||||
| @@ -899,7 +897,7 @@ public class DisguiseUtilities { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static TargetedDisguise getMainDisguise(UUID entityId) { |     public static TargetedDisguise getMainDisguise(Integer entityId) { | ||||||
|         TargetedDisguise toReturn = null; |         TargetedDisguise toReturn = null; | ||||||
|  |  | ||||||
|         if (getDisguises().containsKey(entityId)) { |         if (getDisguises().containsKey(entityId)) { | ||||||
| @@ -1195,8 +1193,8 @@ public class DisguiseUtilities { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isDisguiseInUse(Disguise disguise) { |     public static boolean isDisguiseInUse(Disguise disguise) { | ||||||
|         return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId()) && |         return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getEntityId()) && | ||||||
|                 getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise); |                 getDisguises().get(disguise.getEntity().getEntityId()).contains(disguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -1412,7 +1410,7 @@ public class DisguiseUtilities { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean removeDisguise(TargetedDisguise disguise) { |     public static boolean removeDisguise(TargetedDisguise disguise) { | ||||||
|         UUID entityId = disguise.getEntity().getUniqueId(); |         int entityId = disguise.getEntity().getEntityId(); | ||||||
|  |  | ||||||
|         if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) { |         if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) { | ||||||
|             if (getDisguises().get(entityId).isEmpty()) { |             if (getDisguises().get(entityId).isEmpty()) { | ||||||
| @@ -2484,8 +2482,8 @@ public class DisguiseUtilities { | |||||||
|         Entity e = disguise.getEntity(); |         Entity e = disguise.getEntity(); | ||||||
|  |  | ||||||
|         // If the disguises entity is null, or the disguised entity isn't a player; return |         // If the disguises entity is null, or the disguised entity isn't a player; return | ||||||
|         if (!(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) || |         if (!(e instanceof Player) || !getDisguises().containsKey(e.getEntityId()) || | ||||||
|                 !getDisguises().get(e.getUniqueId()).contains(disguise)) { |                 !getDisguises().get(e.getEntityId()).contains(disguise)) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -2816,31 +2814,23 @@ 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()) { | ||||||
|             entity = observer; |             entityId = observer.getEntityId(); | ||||||
|         } else { |         } | ||||||
|  |  | ||||||
|  |         if (getFutureDisguises().containsKey(entityId)) { | ||||||
|             for (Entity e : observer.getWorld().getEntities()) { |             for (Entity e : observer.getWorld().getEntities()) { | ||||||
|                 if (e.getEntityId() != entityId) { |                 if (e.getEntityId() != entityId) { | ||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 entity = e; |                 onFutureDisguise(e); | ||||||
|                 break; |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (entity == null) { |  | ||||||
|                 return null; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (getFutureDisguises().containsKey(entityId)) { |         TargetedDisguise[] disguises = getDisguises(entityId); | ||||||
|             onFutureDisguise(entity); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         TargetedDisguise[] disguises = getDisguises(entity.getUniqueId()); |  | ||||||
|  |  | ||||||
|         if (disguises == null) { |         if (disguises == null) { | ||||||
|             return null; |             return null; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user