Sfoglia il codice sorgente

Do not allow additions of timer tasks while iterating

Follow up on:
https://github.com/mcMMO-Dev/mcMMO/commit/e4d980b135772a7588c2c7c15c65e12f454f7dd8
Should help debug #4019 (and let us know when this actually occurs)
Shane Freeder 5 anni fa
parent
commit
bb7989449e

+ 5 - 0
src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java

@@ -22,9 +22,11 @@ import java.util.Map.Entry;
 
 public class BleedTimerTask extends BukkitRunnable {
     private static Map<LivingEntity, BleedContainer> bleedList = new HashMap<LivingEntity, BleedContainer>();
+    private static boolean isIterating = false;
 
     @Override
     public void run() {
+        isIterating = true;
         Iterator<Entry<LivingEntity, BleedContainer>> bleedIterator = bleedList.entrySet().iterator();
 
         while (bleedIterator.hasNext()) {
@@ -136,6 +138,7 @@ public class BleedTimerTask extends BukkitRunnable {
 
 //            Bukkit.broadcastMessage(debugMessage);
         }
+        isIterating = false;
     }
 
     public static BleedContainer copyContainer(BleedContainer container)
@@ -176,6 +179,8 @@ public class BleedTimerTask extends BukkitRunnable {
             throw new IllegalStateException("Cannot add bleed task async!");
         }
 
+        if (isIterating) throw new IllegalStateException("Cannot add task while iterating timers!");
+
         if(toolTier < 4)
             ticks = Math.max(1, (ticks / 3));