2012-03-18 21:59:35 +01:00
|
|
|
package com.gmail.nossr50.runnables;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.Combat;
|
|
|
|
import com.gmail.nossr50.Users;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
|
|
|
|
|
|
|
public class mcBleedTimer implements Runnable {
|
|
|
|
private final mcMMO plugin;
|
|
|
|
|
|
|
|
private static HashSet<LivingEntity> bleedList = new HashSet<LivingEntity>();
|
|
|
|
private static HashSet<LivingEntity> bleedAddList = new HashSet<LivingEntity>();
|
|
|
|
private static HashSet<LivingEntity> bleedRemoveList = new HashSet<LivingEntity>();
|
|
|
|
|
|
|
|
private static boolean lock = false;
|
|
|
|
|
|
|
|
public mcBleedTimer(final mcMMO plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
updateBleedList();
|
|
|
|
|
|
|
|
// Player bleed simulation
|
2012-03-21 03:51:02 +01:00
|
|
|
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
|
|
|
if (player == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
2012-03-21 03:51:02 +01:00
|
|
|
if (PP == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PP.getBleedTicks() >= 1) {
|
2012-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
//Never kill with Bleeding
|
2012-03-21 03:51:02 +01:00
|
|
|
if (player.getHealth() - 2 < 0) {
|
|
|
|
if (player.getHealth() - 1 > 0) {
|
2012-03-18 21:59:35 +01:00
|
|
|
Combat.dealDamage(player, 1);
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2012-03-18 21:59:35 +01:00
|
|
|
Combat.dealDamage(player, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.decreaseBleedTicks();
|
2012-04-01 06:11:57 +02:00
|
|
|
|
2012-03-21 03:51:02 +01:00
|
|
|
if (PP.getBleedTicks() == 0) {
|
2012-04-24 15:21:21 +02:00
|
|
|
player.sendMessage(mcLocale.getString("Swords.Combat.Bleeding.Stopped"));
|
2012-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-player bleed simulation
|
|
|
|
bleedSimulate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void bleedSimulate() {
|
|
|
|
lock = true;
|
|
|
|
|
|
|
|
// Bleed monsters/animals
|
2012-03-21 03:51:02 +01:00
|
|
|
for (LivingEntity entity : bleedList) {
|
|
|
|
if ((entity == null || entity.isDead())) {
|
2012-03-18 21:59:35 +01:00
|
|
|
remove(entity);
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2012-03-18 21:59:35 +01:00
|
|
|
Combat.dealDamage(entity, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlock list now that we are done
|
|
|
|
lock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBleedList() {
|
2012-03-21 03:51:02 +01:00
|
|
|
if (lock) {
|
2012-03-18 21:59:35 +01:00
|
|
|
plugin.getLogger().warning("mcBleedTimer attempted to update the bleedList but the list was locked!");
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
2012-03-18 21:59:35 +01:00
|
|
|
bleedList.removeAll(bleedRemoveList);
|
|
|
|
bleedRemoveList.clear();
|
2012-03-21 03:51:02 +01:00
|
|
|
|
2012-03-18 21:59:35 +01:00
|
|
|
bleedList.addAll(bleedAddList);
|
|
|
|
bleedAddList.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a LivingEntity from the bleedList if it is in it
|
|
|
|
*
|
|
|
|
* @param entity LivingEntity to remove
|
|
|
|
*/
|
|
|
|
public static void remove(LivingEntity entity) {
|
2012-03-21 03:51:02 +01:00
|
|
|
if (lock) {
|
|
|
|
if (!bleedRemoveList.contains(entity)) {
|
2012-03-18 21:59:35 +01:00
|
|
|
bleedRemoveList.add(entity);
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
|
|
|
if (bleedList.contains(entity)) {
|
2012-03-18 21:59:35 +01:00
|
|
|
bleedList.remove(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
public static void add(LivingEntity entity) {
|
2012-03-21 03:51:02 +01:00
|
|
|
if (lock) {
|
|
|
|
if (!bleedAddList.contains(entity)) {
|
2012-03-18 21:59:35 +01:00
|
|
|
bleedAddList.add(entity);
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 03:51:02 +01:00
|
|
|
else {
|
|
|
|
if (!bleedList.contains(entity)){
|
2012-03-18 21:59:35 +01:00
|
|
|
bleedList.add(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if a LivingEntity is in the bleedList
|
|
|
|
*
|
|
|
|
* @param entity LivingEntity to check if in the bleedList
|
|
|
|
* @return true if in the list, false if not
|
|
|
|
*/
|
|
|
|
public static boolean contains(LivingEntity entity) {
|
|
|
|
return (bleedList.contains(entity) || bleedAddList.contains(entity));
|
|
|
|
}
|
|
|
|
}
|