freezetimers: fix concurrent modification exception (#1349)

* Changed for loop to iterator to prevent concurrent modification exceptions

* changes suggested on PR

* freezetimers: Cleanup

* Fix actual issue

* Fix format

* freezetimers: clean

* freezetimers: we need to rewrite this fucking plugin, holy shit, i'd rather kms than to work on this for 1 more minute JFC. :(
This commit is contained in:
Netami1
2019-08-15 17:41:14 -04:00
committed by Ganom
parent 8239be4b75
commit dd3809c495
2 changed files with 20 additions and 12 deletions

View File

@@ -207,7 +207,7 @@ public class FreezeTimersPlugin extends Plugin
} }
} }
public void onLocalPlayerDeath(LocalPlayerDeath event) private void onLocalPlayerDeath(LocalPlayerDeath event)
{ {
final Player localPlayer = client.getLocalPlayer(); final Player localPlayer = client.getLocalPlayer();
final long currentTime = System.currentTimeMillis(); final long currentTime = System.currentTimeMillis();

View File

@@ -25,6 +25,7 @@ package net.runelite.client.plugins.freezetimers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -37,7 +38,7 @@ public class Timers
{ {
private final Map<Actor, HashMap<TimerType, Long>> timerMap = new HashMap<>(); private final Map<Actor, HashMap<TimerType, Long>> timerMap = new HashMap<>();
public void setTimerEnd(Actor actor, TimerType type, long n) void setTimerEnd(Actor actor, TimerType type, long n)
{ {
if (!timerMap.containsKey(actor)) if (!timerMap.containsKey(actor))
{ {
@@ -47,7 +48,7 @@ public class Timers
timerMap.get(actor).put(type, n + type.getImmunityTime()); timerMap.get(actor).put(type, n + type.getImmunityTime());
} }
public void setTimerReApply(Actor actor, TimerType type, long n) void setTimerReApply(Actor actor, TimerType type, long n)
{ {
if (!timerMap.containsKey(actor)) if (!timerMap.containsKey(actor))
{ {
@@ -57,7 +58,7 @@ public class Timers
timerMap.get(actor).put(type, n); timerMap.get(actor).put(type, n);
} }
public long getTimerEnd(Actor actor, TimerType type) long getTimerEnd(Actor actor, TimerType type)
{ {
if (!timerMap.containsKey(actor)) if (!timerMap.containsKey(actor))
{ {
@@ -67,7 +68,7 @@ public class Timers
return timerMap.get(actor).getOrDefault(type, (long) type.getImmunityTime()) - type.getImmunityTime(); return timerMap.get(actor).getOrDefault(type, (long) type.getImmunityTime()) - type.getImmunityTime();
} }
public long getTimerReApply(Actor actor, TimerType type) long getTimerReApply(Actor actor, TimerType type)
{ {
if (!timerMap.containsKey(actor)) if (!timerMap.containsKey(actor))
{ {
@@ -77,15 +78,23 @@ public class Timers
return timerMap.get(actor).getOrDefault(type, (long) 0); return timerMap.get(actor).getOrDefault(type, (long) 0);
} }
public List<Actor> getAllActorsOnTimer(TimerType type) List<Actor> getAllActorsOnTimer(TimerType type)
{ {
List<Actor> actors = new ArrayList<Actor>(); final List<Actor> actors = new ArrayList<>();
final Iterator<Actor> it = timerMap.keySet().iterator();
for (Actor actor : timerMap.keySet()) while (it.hasNext())
{ {
if (areAllTimersZero(actor)) final Actor actor = it.next();
for (TimerType timerType : TimerType.values())
{ {
continue; if (getTimerReApply(actor, timerType) > System.currentTimeMillis())
{
break;
}
it.remove();
break;
} }
final long end = getTimerReApply(actor, type); final long end = getTimerReApply(actor, type);
@@ -99,7 +108,7 @@ public class Timers
return actors; return actors;
} }
public boolean areAllTimersZero(Actor actor) boolean areAllTimersZero(Actor actor)
{ {
for (TimerType type : TimerType.values()) for (TimerType type : TimerType.values())
{ {
@@ -108,7 +117,6 @@ public class Timers
return false; return false;
} }
} }
timerMap.remove(actor);
return true; return true;
} }
} }