From 6d2f79881b9440fcc125814220b190438f846658 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 7 Oct 2023 10:30:16 -0700 Subject: [PATCH] Fixes getOwner and getIslands to properly return islands in the world The world was not being used for the getOwner return so if a player had an island in any world then it was returned. This caused an NPE if the island was then requested by getIsland because it would not be there. --- .../bentobox/bentobox/managers/island/IslandCache.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 91d886f78..194bfbe99 100644 --- a/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java +++ b/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java @@ -177,7 +177,7 @@ public class IslandCache { if (w == null) { return new HashSet<>(); } - return islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).stream().filter(i -> world.equals(i.getWorld())).collect(Collectors.toSet()); + return islandsByUUID.computeIfAbsent(uuid, k -> new HashSet<>()).stream().filter(i -> w.equals(i.getWorld())).collect(Collectors.toSet()); } /** @@ -252,7 +252,7 @@ public class IslandCache { * Get the UUID of the owner of the island of the player, which may be their UUID * @param world the world to check * @param uuid the player's UUID - * @return island owner's UUID or null if there is no island + * @return island owner's UUID or null if there is no island owned by the player in this world */ @Nullable public UUID getOwner(@NonNull World world, @NonNull UUID uuid) { @@ -261,7 +261,8 @@ public class IslandCache { if (w == null || islands == null || islands.isEmpty()) { return null; } - return islands.iterator().next().getOwner(); // This assumes that all islands in this set have the same owner + // Find the island for this world + return islands.stream().filter(i -> w.equals(i.getWorld())).findFirst().map(Island::getOwner).orElse(null); } /**