From 35f154aa0f580a25b3c12278b33b377e62a463ce Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sat, 5 Oct 2024 13:13:48 +0200 Subject: [PATCH] fixed clear --- .../model/src/main/java/pp/battleship/model/ShipMap.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java b/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java index bb73d6b..0422616 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java @@ -10,6 +10,7 @@ package pp.battleship.model; import pp.battleship.notification.GameEvent; import pp.battleship.notification.GameEventBroker; import pp.battleship.notification.ItemAddedEvent; +import pp.battleship.notification.ItemRemovedEvent; import java.util.ArrayList; import java.util.Collections; @@ -104,7 +105,10 @@ public class ShipMap { * Removes all items from the map and triggers corresponding removal events for each. */ public void clear() { - new ArrayList<>(items).forEach(this::remove); + for (Item item : items) { + items.remove(item); + notifyListeners(new ItemRemovedEvent(item, this)); + } } /**