Skip to content

Commit

Permalink
Prevent potential NPEs with placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 20, 2025
1 parent 22ea268 commit c1dc824
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/world/bentobox/level/PlaceholderManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ String getRankName(World world, int rank, boolean weighted) {
}
@Nullable
UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
.findFirst().flatMap(addon.getIslands()::getIslandById).map(Island::getOwner).orElse(null);
.findFirst().flatMap(addon.getIslands()::getIslandById).filter(island -> island.getOwner() != null) // Filter out null owners
.map(Island::getOwner).orElse(null);

return addon.getPlayers().getName(owner);
}
Expand All @@ -135,10 +136,12 @@ String getRankIslandName(World world, int rank, boolean weighted) {
rank = Math.max(1, Math.min(rank, Level.TEN));
if (weighted) {
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
.findFirst().map(Island::getName).orElse("");
.findFirst().filter(island -> island.getName() != null) // Filter out null names
.map(Island::getName).orElse("");
}
return addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst()
.flatMap(addon.getIslands()::getIslandById).map(Island::getName).orElse("");
.flatMap(addon.getIslands()::getIslandById).filter(island -> island.getName() != null) // Filter out null names
.map(Island::getName).orElse("");
}

/**
Expand Down

0 comments on commit c1dc824

Please sign in to comment.