From 38cd3951715b3215c9f50731f797e27c0d69dd69 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 26 Feb 2013 10:13:40 -0500 Subject: [PATCH] Clean up the bleed list a bit. --- .../nossr50/skills/runnables/BleedTimer.java | 33 ++++--------------- .../nossr50/util/ParticleEffectUtils.java | 4 +-- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/runnables/BleedTimer.java b/src/main/java/com/gmail/nossr50/skills/runnables/BleedTimer.java index ec187030d..711169d4b 100644 --- a/src/main/java/com/gmail/nossr50/skills/runnables/BleedTimer.java +++ b/src/main/java/com/gmail/nossr50/skills/runnables/BleedTimer.java @@ -6,8 +6,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.bukkit.Effect; -import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -35,7 +33,7 @@ public class BleedTimer implements Runnable { for (Entry entry : bleedList.entrySet()) { LivingEntity entity = entry.getKey(); - if (entry.getValue() <= 0 || entity.isDead()) { + if (entry.getValue() <= 0 || !entity.isValid()) { remove(entity); break; } @@ -64,7 +62,7 @@ public class BleedTimer implements Runnable { else { CombatTools.dealDamage(entity, 2); entry.setValue(entry.getValue() - 1); - entity.getWorld().playEffect(entity.getEyeLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE); + ParticleEffectUtils.playBleedEffect(entity); } } @@ -127,44 +125,27 @@ public class BleedTimer implements Runnable { if (lock) { if (bleedAddList.containsKey(entity)) { newTicks += bleedAddList.get(entity); - - if (newTicks > MAX_BLEED_TICKS) { - newTicks = MAX_BLEED_TICKS; - } - - bleedAddList.put(entity, newTicks); + bleedAddList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS)); } else { - if (newTicks > MAX_BLEED_TICKS) { - newTicks = MAX_BLEED_TICKS; - } - - bleedAddList.put(entity, newTicks); + bleedAddList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS)); } } else { if (bleedList.containsKey(entity)) { newTicks += bleedList.get(entity); - - if (newTicks > MAX_BLEED_TICKS) { - newTicks = MAX_BLEED_TICKS; - } - - bleedList.put(entity, newTicks); + bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS)); // Need to find a better way to ensure that the entity stays in bleedList // when some ticks are added but already marked for removal. // Suggestion: Why not use Iterator.remove() and drop the lock boolean? + // TODO: Actually implement this suggestion? if (bleedRemoveList.contains(entity)) { bleedRemoveList.remove(entity); } } else { - if (newTicks > MAX_BLEED_TICKS) { - newTicks = MAX_BLEED_TICKS; - } - - bleedList.put(entity, newTicks); + bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS)); } } } diff --git a/src/main/java/com/gmail/nossr50/util/ParticleEffectUtils.java b/src/main/java/com/gmail/nossr50/util/ParticleEffectUtils.java index 79f9c1cb5..56dcbdc38 100644 --- a/src/main/java/com/gmail/nossr50/util/ParticleEffectUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ParticleEffectUtils.java @@ -20,12 +20,12 @@ public final class ParticleEffectUtils { private ParticleEffectUtils() {}; - public static void playBleedEffect(Player player) { + public static void playBleedEffect(LivingEntity livingEntity) { if (!Config.getInstance().getBleedEffectEnabled()) { return; } - player.getWorld().playEffect(player.getEyeLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE); + livingEntity.getWorld().playEffect(livingEntity.getEyeLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE); } public static void playDodgeEffect(Player player) {