mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-28 03:27:39 +01:00
Clean up the bleed list a bit.
This commit is contained in:
parent
3aec0e5ef4
commit
38cd395171
@ -6,8 +6,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -35,7 +33,7 @@ public class BleedTimer implements Runnable {
|
|||||||
for (Entry<LivingEntity, Integer> entry : bleedList.entrySet()) {
|
for (Entry<LivingEntity, Integer> entry : bleedList.entrySet()) {
|
||||||
LivingEntity entity = entry.getKey();
|
LivingEntity entity = entry.getKey();
|
||||||
|
|
||||||
if (entry.getValue() <= 0 || entity.isDead()) {
|
if (entry.getValue() <= 0 || !entity.isValid()) {
|
||||||
remove(entity);
|
remove(entity);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -64,7 +62,7 @@ public class BleedTimer implements Runnable {
|
|||||||
else {
|
else {
|
||||||
CombatTools.dealDamage(entity, 2);
|
CombatTools.dealDamage(entity, 2);
|
||||||
entry.setValue(entry.getValue() - 1);
|
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 (lock) {
|
||||||
if (bleedAddList.containsKey(entity)) {
|
if (bleedAddList.containsKey(entity)) {
|
||||||
newTicks += bleedAddList.get(entity);
|
newTicks += bleedAddList.get(entity);
|
||||||
|
bleedAddList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
|
||||||
if (newTicks > MAX_BLEED_TICKS) {
|
|
||||||
newTicks = MAX_BLEED_TICKS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bleedAddList.put(entity, newTicks);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (newTicks > MAX_BLEED_TICKS) {
|
bleedAddList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
|
||||||
newTicks = MAX_BLEED_TICKS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bleedAddList.put(entity, newTicks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (bleedList.containsKey(entity)) {
|
if (bleedList.containsKey(entity)) {
|
||||||
newTicks += bleedList.get(entity);
|
newTicks += bleedList.get(entity);
|
||||||
|
bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
|
||||||
if (newTicks > MAX_BLEED_TICKS) {
|
|
||||||
newTicks = MAX_BLEED_TICKS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bleedList.put(entity, newTicks);
|
|
||||||
|
|
||||||
// Need to find a better way to ensure that the entity stays in bleedList
|
// Need to find a better way to ensure that the entity stays in bleedList
|
||||||
// when some ticks are added but already marked for removal.
|
// when some ticks are added but already marked for removal.
|
||||||
// Suggestion: Why not use Iterator.remove() and drop the lock boolean?
|
// Suggestion: Why not use Iterator.remove() and drop the lock boolean?
|
||||||
|
// TODO: Actually implement this suggestion?
|
||||||
if (bleedRemoveList.contains(entity)) {
|
if (bleedRemoveList.contains(entity)) {
|
||||||
bleedRemoveList.remove(entity);
|
bleedRemoveList.remove(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (newTicks > MAX_BLEED_TICKS) {
|
bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
|
||||||
newTicks = MAX_BLEED_TICKS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bleedList.put(entity, newTicks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ public final class ParticleEffectUtils {
|
|||||||
|
|
||||||
private ParticleEffectUtils() {};
|
private ParticleEffectUtils() {};
|
||||||
|
|
||||||
public static void playBleedEffect(Player player) {
|
public static void playBleedEffect(LivingEntity livingEntity) {
|
||||||
if (!Config.getInstance().getBleedEffectEnabled()) {
|
if (!Config.getInstance().getBleedEffectEnabled()) {
|
||||||
return;
|
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) {
|
public static void playDodgeEffect(Player player) {
|
||||||
|
Loading…
Reference in New Issue
Block a user