Do not allow additions of timer tasks while iterating

Follow up on:
e4d980b135
Should help debug #4019 (and let us know when this actually occurs)
This commit is contained in:
Shane Freeder 2019-08-12 02:31:46 +01:00
parent 4246f59d44
commit bb7989449e
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C

View File

@ -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));