From c9c57e113f7226fadac817c0049ab3fef8128538 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 5 Aug 2024 12:22:32 -0700 Subject: [PATCH] More code to clean up when an island is deleted. #2456 --- .../bentobox/bentobox/managers/island/IslandCache.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java b/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java index e6f91066d..cfeea4202 100644 --- a/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java +++ b/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java @@ -171,8 +171,15 @@ public class IslandCache { } private void removeFromIslandsByUUID(Island island) { - for (Set set : islandsByUUID.values()) { + Iterator>> iterator = islandsByUUID.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + Set set = entry.getValue(); set.removeIf(island.getUniqueId()::equals); + if (set.isEmpty()) { + // Removes the overall entry if there is nothing left in the set + iterator.remove(); + } } }