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-25 20:12:31 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2019-01-24 01:01:30 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.util.MobHealthbarUtils;
|
2019-01-25 20:12:31 +01:00
|
|
|
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;
|
2019-01-25 20:12:31 +01:00
|
|
|
import java.util.Iterator;
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.Map;
|
2019-01-25 20:12:31 +01:00
|
|
|
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 {
|
2019-01-25 20:12:31 +01:00
|
|
|
private static Map<LivingEntity, BleedContainer> bleedList = new HashMap<LivingEntity, BleedContainer>();
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
@Override
|
2019-01-25 20:12:31 +01:00
|
|
|
synchronized public void run() {
|
|
|
|
Iterator<Entry<LivingEntity, BleedContainer>> bleedIterator = bleedList.entrySet().iterator();
|
2019-01-24 22:20:45 +01:00
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
while (bleedIterator.hasNext()) {
|
|
|
|
Entry<LivingEntity, BleedContainer> containerEntry = bleedIterator.next();
|
|
|
|
LivingEntity target = containerEntry.getKey();
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
int bleedTicks = containerEntry.getValue().bleedTicks;
|
|
|
|
|
|
|
|
if (containerEntry.getValue().bleedTicks <= 0 || !target.isValid()) {
|
|
|
|
bleedIterator.remove();
|
2013-02-26 16:32:06 +01:00
|
|
|
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-24 01:01:30 +01:00
|
|
|
if (target instanceof Player) {
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = AdvancedConfig.getInstance().getRuptureDamagePlayer();
|
|
|
|
|
|
|
|
//Above Bleed Rank 3 deals 50% more damage
|
2019-01-25 20:12:31 +01:00
|
|
|
if (containerEntry.getValue().bleedRank >= 3)
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = damage * 1.5;
|
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
Player player = (Player) target;
|
2012-04-28 06:14:19 +02:00
|
|
|
|
|
|
|
if (!player.isOnline()) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Swords.Combat.Bleeding.Stopped");
|
|
|
|
} else {
|
2019-01-22 00:14:01 +01:00
|
|
|
damage = AdvancedConfig.getInstance().getRuptureDamageMobs();
|
2019-01-25 20:12:31 +01:00
|
|
|
|
|
|
|
//Above Bleed Rank 3 deals 50% more damage
|
|
|
|
if (containerEntry.getValue().bleedRank >= 3)
|
|
|
|
damage = damage * 1.5;
|
|
|
|
|
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
MobHealthbarUtils.handleMobHealthbars(target, damage, mcMMO.p); //Update health bars
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
2019-01-24 01:01:30 +01:00
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(target, damage, containerEntry.getValue().damageSource);
|
2019-01-24 01:08:41 +01:00
|
|
|
//Play Bleed Sound
|
|
|
|
SoundManager.worldSendSound(target.getWorld(), target.getLocation(), SoundType.BLEED);
|
|
|
|
|
2019-01-24 01:01:30 +01:00
|
|
|
ParticleEffectUtils.playBleedEffect(target);
|
2012-03-18 21:59:35 +01:00
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
//Lower Bleed Ticks
|
|
|
|
BleedContainer loweredBleedContainer = copyContainer(containerEntry.getValue());
|
|
|
|
loweredBleedContainer.bleedTicks -= 1;
|
|
|
|
containerEntry.setValue(loweredBleedContainer);
|
2019-01-24 22:20:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
public static BleedContainer copyContainer(BleedContainer container)
|
|
|
|
{
|
|
|
|
LivingEntity target = container.target;
|
|
|
|
LivingEntity source = container.damageSource;
|
|
|
|
int bleedTicks = container.bleedTicks;
|
|
|
|
int bleedRank = container.bleedRank;
|
2019-01-24 22:20:45 +01:00
|
|
|
|
2019-01-25 20:12:31 +01:00
|
|
|
BleedContainer newContainer = new BleedContainer(target, bleedTicks, bleedRank, source);
|
|
|
|
return newContainer;
|
2019-01-24 01:01:30 +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) {
|
2019-01-25 20:12:31 +01:00
|
|
|
/*
|
|
|
|
* Don't remove anything from the list outside of run()
|
|
|
|
*/
|
2012-04-28 06:14:19 +02:00
|
|
|
|
2013-02-26 16:32:06 +01:00
|
|
|
if (bleedList.containsKey(entity)) {
|
2019-01-25 20:12:31 +01:00
|
|
|
CombatUtils.dealNoInvulnerabilityTickDamage(entity, bleedList.get(entity).bleedTicks * 2, bleedList.get(entity).damageSource);
|
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-25 20:12:31 +01:00
|
|
|
public synchronized static void add(LivingEntity entity, LivingEntity attacker, int ticks, int bleedRank) {
|
|
|
|
BleedContainer newBleedContainer = new BleedContainer(entity, ticks, bleedRank, attacker);
|
|
|
|
bleedList.put(entity, newBleedContainer);
|
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
|
|
|
}
|