From 1edc05d9ffd0d1c221119b071bad1d12b602ccaf Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 15 Jun 2014 19:33:59 +1200 Subject: [PATCH] Loop over entities with numbers instead of iterator (CraftBook needs to improve their coding) --- .../disguise/utilities/PacketsManager.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index e805d9b1..af2fa981 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -518,7 +518,9 @@ public class PacketsManager { Entity disguisedEntity = null; DisguiseSound entitySound = null; Disguise disguise = null; - for (Entity entity : soundLoc.getChunk().getEntities()) { + Entity[] entities = soundLoc.getChunk().getEntities(); + for (int i = 0; i < entities.length; i++) { + Entity entity = entities[i]; Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); if (entityDisguise != null) { Location loc = entity.getLocation(); @@ -546,10 +548,12 @@ public class PacketsManager { Object nmsEntity = ReflectionManager.getNmsEntity(entity); try { if (entity instanceof LivingEntity) { - hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt(nmsEntity) == - ReflectionManager.getNmsField("EntityLiving", "maxNoDamageTicks").getInt(nmsEntity); + hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt( + nmsEntity) == ReflectionManager.getNmsField("EntityLiving", + "maxNoDamageTicks").getInt(nmsEntity); } else { - hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable").invoke(nmsEntity); + hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable") + .invoke(nmsEntity); } } catch (Exception ex) { ex.printStackTrace(); @@ -583,13 +587,15 @@ public class PacketsManager { Object block; if (LibVersion.is1_7()) { block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class) - .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId); + .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), + typeId); } else { block = ((Object[]) ReflectionManager.getNmsField("Block", "byId").get(null))[typeId]; } if (block != null) { Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); - mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step)); + mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound") + .invoke(step)); } } catch (Exception ex) { ex.printStackTrace();