From e4d980b135772a7588c2c7c15c65e12f454f7dd8 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Mon, 29 Jul 2019 17:41:57 +0100 Subject: [PATCH] Fixed some concurrency concerns around BleedTasks --- Changelog.txt | 4 ++++ .../java/com/gmail/nossr50/listeners/EntityListener.java | 2 -- .../com/gmail/nossr50/runnables/skills/BleedTimerTask.java | 6 ++++++ .../java/com/gmail/nossr50/util/skills/CombatUtils.java | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index b86d940cc..4999d70fe 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,7 @@ +Version 2.1.101 + mcnotify command now checks that it's being executed by a player + Fixed some concurrency concerns around BleedTasks + Version 2.1.100 Corrected some mistakes made in the updated Russian locale (thanks myfbone!) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 101b5868d..1ee539eed 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -259,8 +259,6 @@ public class EntityListener implements Listener { if(defender.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() > 0) { - defender.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, plugin); - if(defender instanceof Player) { LivingEntity defLive = (LivingEntity) defender; diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java index 2290c241b..db524f03d 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java @@ -9,6 +9,8 @@ import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; + +import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -171,6 +173,10 @@ public class BleedTimerTask extends BukkitRunnable { * @param ticks Number of bleeding ticks */ public static void add(LivingEntity entity, LivingEntity attacker, int ticks, int bleedRank, int toolTier) { + if (!Bukkit.isPrimaryThread()) { + throw new IllegalStateException("Cannot add bleed task async!"); + } + if(toolTier < 4) ticks = Math.max(1, (ticks / 3)); diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 06583d8fc..d1c25da54 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -552,6 +552,7 @@ public final class CombatUtils { target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue); target.damage(damage, attacker); + target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p); // //IFrame storage //// int noDamageTicks = target.getNoDamageTicks();