2
0
Эх сурвалжийг харах

use iterator instead of for loop

Daniel Nägele 1 жил өмнө
parent
commit
b46382f4d7

+ 1 - 1
missilewars-plugin/pom.xml

@@ -26,7 +26,7 @@
         <version>1.0</version>
     </parent>
 
-    <version>4.6.0-beta.2</version>
+    <version>4.6.0</version>
 
     <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() {
-        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);
         }
     }