From 030c8e59d7d75827c52e3174327dbd6cafdd0487 Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 22 May 2013 00:01:19 -0400 Subject: [PATCH] The other way leaks memory like a sieve. --- .../nossr50/util/skills/CombatUtils.java | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index c45759ce2..844b06fa6 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -383,38 +383,40 @@ public final class CombatUtils { int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit int damageAmount = Math.max(damage, 1); - while (numberOfTargets > 0) { - for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) { - if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) { - continue; - } - - LivingEntity livingEntity = (LivingEntity) entity; - mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(attacker)); - - switch (type) { - case SWORDS: - if (entity instanceof Player) { - ((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck")); - } - - BleedTimerTask.add(livingEntity, Swords.serratedStrikesBleedTicks); - break; - - case AXES: - if (entity instanceof Player) { - ((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck")); - } - - break; - - default: - break; - } - - dealDamage(livingEntity, damageAmount, attacker); - numberOfTargets--; + for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) { + if (numberOfTargets <= 0) { + break; } + + if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) { + continue; + } + + LivingEntity livingEntity = (LivingEntity) entity; + mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(attacker)); + + switch (type) { + case SWORDS: + if (entity instanceof Player) { + ((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck")); + } + + BleedTimerTask.add(livingEntity, Swords.serratedStrikesBleedTicks); + break; + + case AXES: + if (entity instanceof Player) { + ((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck")); + } + + break; + + default: + break; + } + + dealDamage(livingEntity, damageAmount, attacker); + numberOfTargets--; } }