2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.runnables.skills;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2019-01-14 07:21:16 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
2019-01-22 00:14:01 +01:00
|
|
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
|
|
import com.gmail.nossr50.util.sounds.SoundType;
|
2012-03-18 21:59:35 +01:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-03-20 08:11:16 +01:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2013-03-20 08:11:16 +01:00
|
|
|
public class BleedTimerTask extends BukkitRunnable {
|
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>();
|
2019-01-22 00:14:01 +01:00
|
|
|
private static Map<LivingEntity, Integer> bleedDamage = new HashMap<LivingEntity, Integer>();
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-05-11 15:14:46 +02:00
|
|
|
for (Iterator<Entry<LivingEntity, Integer>> bleedIterator = bleedList.entrySet().iterator(); bleedIterator.hasNext(); ) {
|
2013-02-26 16:32:06 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-11 12:18:31 +02:00
|
|
|
double damage;
|
2013-02-27 13:49:56 +01:00
|
|
|
|
2019-01-22 00:14:01 +01:00
|
|
|
//Play Bleed Sound
|
|
|
|
SoundManager.worldSendSound(entity.getWorld(), entity.getLocation(), SoundType.BLEED);
|
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
if (entity instanceof Player) {
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = AdvancedConfig.getInstance().getRuptureDamagePlayer();
|
|
|
|
|
|
|
|
//Above Bleed Rank 3 deals 50% more damage
|
|
|
|
if(bleedDamage.get(entity) >= 3)
|
|
|
|
damage = damage * 1.5;
|
|
|
|
|
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) {
|
2019-01-23 21:28:30 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(entity, damage, null);
|
2013-02-26 16:32:06 +01:00
|
|
|
ParticleEffectUtils.playBleedEffect(entity);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
|
2014-10-11 12:18:31 +02:00
|
|
|
entry.setValue(entry.getValue() - 1);
|
2012-04-01 06:11:57 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
if (entry.getValue() <= 0) {
|
2019-01-14 07:21:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Swords.Combat.Bleeding.Stopped");
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = AdvancedConfig.getInstance().getRuptureDamageMobs();
|
2013-02-27 13:49:56 +01:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2019-01-23 21:28:30 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(entity, damage, null);
|
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)) {
|
2019-01-22 00:14:01 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(entity, bleedList.get(entity) * 2, null);
|
2012-04-28 06:14:19 +02:00
|
|
|
bleedList.remove(entity);
|
2019-01-22 00:14:01 +01:00
|
|
|
bleedDamage.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);
|
2019-01-22 00:14:01 +01:00
|
|
|
bleedDamage.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
|
|
|
*/
|
2019-01-22 00:14:01 +01:00
|
|
|
public static void add(LivingEntity entity, int ticks, int bleedRank) {
|
2012-04-28 06:14:19 +02:00
|
|
|
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));
|
2019-01-22 00:14:01 +01:00
|
|
|
|
|
|
|
//Override the current bleed rank only if this one is higher
|
|
|
|
if(bleedDamage.get(entity) < bleedRank)
|
|
|
|
bleedDamage.put(entity, bleedRank);
|
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));
|
2019-01-22 00:14:01 +01:00
|
|
|
bleedDamage.put(entity, bleedRank);
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-02 19:41:44 +02:00
|
|
|
|
|
|
|
public static boolean isBleeding(LivingEntity entity) {
|
|
|
|
return bleedList.containsKey(entity);
|
|
|
|
}
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|