Fixes issue with null placeholder error

https://github.com/BentoBoxWorld/Level/issues/159
This commit is contained in:
tastybento 2020-06-26 15:44:03 -07:00
parent a6be22bfe5
commit 1a7d48a0ec
3 changed files with 25 additions and 8 deletions

View File

@ -120,19 +120,27 @@ public class Level extends Addon {
}
private String getRankName(World world, int rank) {
String getRankName(World world, int rank) {
if (rank < 1) rank = 1;
if (rank > 10) rank = 10;
return getPlayers().getName(getManager().getTopTen(world, 10).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
}
private String getRankLevel(World world, int rank) {
String getRankLevel(World world, int rank) {
if (rank < 1) rank = 1;
if (rank > 10) rank = 10;
return getManager().formatLevel(getManager().getTopTen(world, 10).values().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
return getManager()
.formatLevel(getManager()
.getTopTen(world, 10)
.values()
.stream()
.skip(rank - 1L)
.limit(1L)
.findFirst()
.orElse(null));
}
private String getVisitedIslandLevel(GameModeAddon gm, User user) {
String getVisitedIslandLevel(GameModeAddon gm, User user) {
if (!gm.inWorld(user.getLocation())) return "";
return getIslands().getIslandAt(user.getLocation())
.map(island -> getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner()))

View File

@ -133,7 +133,8 @@ public class LevelsManager {
* @param lvl - long value to represent
* @return string of the level.
*/
public String formatLevel(long lvl) {
public String formatLevel(@Nullable Long lvl) {
if (lvl == null) return "";
String level = String.valueOf(lvl);
// Asking for the level of another player
if(addon.getSettings().isShorthand()) {
@ -270,7 +271,8 @@ public class LevelsManager {
* @param size - size of the top ten
* @return sorted top ten map
*/
public Map<UUID, Long> getTopTen(World world, int size) {
@NonNull
public Map<UUID, Long> getTopTen(@NonNull World world, int size) {
topTenLists.computeIfAbsent(world, TopTenData::new);
// Remove player from top ten if they are online and do not have the perm
topTenLists.get(world).getTopTen().keySet().removeIf(u -> !hasTopTenPerm(world, u));
@ -286,7 +288,7 @@ public class LevelsManager {
* Checks if player has the correct top ten perm to have their level saved
* @param world
* @param targetPlayer
* @return
* @return true if player has the perm
*/
boolean hasTopTenPerm(@NonNull World world, @NonNull UUID targetPlayer) {
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(world);

View File

@ -300,5 +300,12 @@ public class LevelTest {
assertEquals(100, s.getLevelCost());
}
/**
* Test method for {@link world.bentobox.level.Level#getRankLevel(World, int)}.
*/
@Test
public void testRankLevel() {
addon.onEnable();
assertEquals("",addon.getRankLevel(world, 1));
}
}