Browse Source

use iterator instead of for loop

Daniel Nägele 1 year ago
parent
commit
b46382f4d7

+ 1 - 1
missilewars-plugin/pom.xml

@@ -26,7 +26,7 @@
         <version>1.0</version>
         <version>1.0</version>
     </parent>
     </parent>
 
 
-    <version>4.6.0-beta.2</version>
+    <version>4.6.0</version>
 
 
     <modelVersion>4.0.0</modelVersion>
     <modelVersion>4.0.0</modelVersion>
 
 

+ 5 - 2
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/GameManager.java

@@ -46,8 +46,11 @@ public class GameManager {
     }
     }
 
 
     public void restartAll() {
     public void restartAll() {
-        for (Game game : games.values()) {
-            restartGame(game.getLobby(), false);
+        // We use an iterator to prevent a possible ConcurrentModificationException
+        var iterator = games.values().iterator();
+        //noinspection WhileLoopReplaceableByForEach
+        while (iterator.hasNext()) {
+            restartGame(iterator.next().getLobby(), false);
         }
         }
     }
     }