2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.runnables.skills;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
import java.util.HashMap;
|
2013-02-26 16:32:06 +01:00
|
|
|
import java.util.Iterator;
|
2012-04-28 06:14:19 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public class BleedTimerTask implements Runnable {
|
2012-04-28 06:14:19 +02:00
|
|
|
private final static int MAX_BLEED_TICKS = 10;
|
|
|
|
private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>();
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2013-02-26 16:32:06 +01:00
|
|
|
for (Iterator<Entry<LivingEntity, Integer>> bleedIterator = bleedList.entrySet().iterator(); bleedIterator.hasNext();) {
|
|
|
|
Entry<LivingEntity, Integer> entry = bleedIterator.next();
|
2012-04-28 06:14:19 +02:00
|
|
|
LivingEntity entity = entry.getKey();
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2013-02-26 16:13:40 +01:00
|
|
|
if (entry.getValue() <= 0 || !entity.isValid()) {
|
2013-02-26 16:32:06 +01:00
|
|
|
bleedIterator.remove();
|
|
|
|
continue;
|
2012-03-21 03:51:02 +01:00
|
|
|
}
|
|
|
|
|
2013-02-27 13:49:56 +01:00
|
|
|
int damage = 0;
|
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
if (entity instanceof Player) {
|
2013-02-27 13:49:56 +01:00
|
|
|
damage = 1;
|
2012-04-28 06:14:19 +02:00
|
|
|
Player player = (Player) entity;
|
|
|
|
|
|
|
|
if (!player.isOnline()) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2013-02-26 16:32:06 +01:00
|
|
|
// Never kill with Bleeding
|
2013-02-27 13:49:56 +01:00
|
|
|
if (player.getHealth() - damage > 0) {
|
2013-03-01 06:52:01 +01:00
|
|
|
CombatUtils.dealDamage(player, damage);
|
2013-02-26 16:32:06 +01:00
|
|
|
ParticleEffectUtils.playBleedEffect(entity);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
|
2013-02-27 13:49:56 +01:00
|
|
|
entry.setValue(entry.getValue() - damage);
|
2012-04-01 06:11:57 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
if (entry.getValue() <= 0) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Stopped"));
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2013-02-27 13:49:56 +01:00
|
|
|
damage = 2;
|
|
|
|
|
|
|
|
// Anticipate the entity's death to prevent CME because of our EntityDeathEvent listener
|
|
|
|
if (entity.getHealth() - damage > 0) {
|
|
|
|
entry.setValue(entry.getValue() - 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bleedIterator.remove();
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
CombatUtils.dealDamage(entity, damage);
|
2013-02-26 16:13:40 +01:00
|
|
|
ParticleEffectUtils.playBleedEffect(entity);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
/**
|
|
|
|
* Instantly Bleed out a LivingEntity
|
2012-06-05 15:57:10 +02:00
|
|
|
*
|
2012-04-28 06:14:19 +02:00
|
|
|
* @param entity LivingEntity to bleed out
|
|
|
|
*/
|
|
|
|
public static void bleedOut(LivingEntity entity) {
|
|
|
|
if (bleedList.containsKey(entity)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
CombatUtils.dealDamage(entity, bleedList.get(entity) * 2);
|
2012-04-28 06:14:19 +02:00
|
|
|
bleedList.remove(entity);
|
2012-12-24 22:56:25 +01:00
|
|
|
}
|
2012-04-28 06:14:19 +02:00
|
|
|
}
|
|
|
|
|
2012-03-18 21:59:35 +01:00
|
|
|
/**
|
|
|
|
* Remove a LivingEntity from the bleedList if it is in it
|
2012-06-05 15:57:10 +02:00
|
|
|
*
|
2012-03-18 21:59:35 +01:00
|
|
|
* @param entity LivingEntity to remove
|
|
|
|
*/
|
|
|
|
public static void remove(LivingEntity entity) {
|
2013-02-26 16:32:06 +01:00
|
|
|
if (bleedList.containsKey(entity)) {
|
|
|
|
bleedList.remove(entity);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-21 03:51:02 +01:00
|
|
|
* Add a LivingEntity to the bleedList if it is not in it.
|
|
|
|
*
|
2012-03-18 21:59:35 +01:00
|
|
|
* @param entity LivingEntity to add
|
2012-05-01 01:32:50 +02:00
|
|
|
* @param ticks Number of bleeding ticks
|
2012-03-18 21:59:35 +01:00
|
|
|
*/
|
2012-04-28 06:14:19 +02:00
|
|
|
public static void add(LivingEntity entity, int ticks) {
|
|
|
|
int newTicks = ticks;
|
|
|
|
|
2013-02-26 16:32:06 +01:00
|
|
|
if (bleedList.containsKey(entity)) {
|
|
|
|
newTicks += bleedList.get(entity);
|
|
|
|
bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2013-02-26 16:32:06 +01:00
|
|
|
bleedList.put(entity, Math.min(newTicks, MAX_BLEED_TICKS));
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|