mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-16 23:55:17 +01:00
Fixes issue with null placeholder error
https://github.com/BentoBoxWorld/Level/issues/159
This commit is contained in:
parent
a6be22bfe5
commit
1a7d48a0ec
@ -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()))
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user