Skip to content
Browse files

Avoid changing set while traversing it. Fix bug #178.

  • Loading branch information...
1 parent 92aa92c commit e958f925e01f9d2053c670f69d1c99e6142bc706 @mkalus committed Apr 18, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/main/java/de/beimax/simplespleef/gamehelpers/OriginalPositionKeeper.java
View
12 src/main/java/de/beimax/simplespleef/gamehelpers/OriginalPositionKeeper.java
@@ -19,6 +19,8 @@
package de.beimax.simplespleef.gamehelpers;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Location;
@@ -127,11 +129,17 @@ protected void pruneOriginalLocations() {
long checkTime = (System.currentTimeMillis() / 1000) - maxTime;
// delete entries that are too old
+ List<String> keys = new LinkedList<String>();
for (Entry<String, PlayerOriginalLocation> entry : playerOriginalLocations
.entrySet()) {
- if (entry.getValue().timestamp < checkTime) // remove entries that
+ if (entry.getValue().timestamp < checkTime) // mark entries that
// are too old
- playerOriginalLocations.remove(entry.getKey());
+ keys.add(entry.getKey()); // add to list to remove later
+ }
+
+ // now remove old keys
+ for (String key: keys) {
+ playerOriginalLocations.remove(key);
}
}

0 comments on commit e958f92

Please sign in to comment.
Something went wrong with that request. Please try again.