Skip to content

Commit

Permalink
Fixes getOwner and getIslands to properly return islands in the world
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tastybento committed Oct 7, 2023
1 parent e6ccce4 commit 6d2f798
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public Set<Island> getIslands(@NonNull World world, @NonNull UUID uuid) {
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());
}

/**
Expand Down Expand Up @@ -252,7 +252,7 @@ public Set<UUID> getMembers(@NonNull World world, @NonNull UUID uuid, int minimu
* 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) {
Expand All @@ -261,7 +261,8 @@ public UUID getOwner(@NonNull World world, @NonNull UUID uuid) {
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);
}

/**
Expand Down

0 comments on commit 6d2f798

Please sign in to comment.