Adds %Level_[gamemode]_island_level_max% placeholder

This records the lifetime maximum level the island has ever had.
Addresses #271
This commit is contained in:
tastybento 2022-11-26 18:20:14 -08:00
parent 3988659dcc
commit f3ee8a381c
4 changed files with 42 additions and 0 deletions

View File

@ -228,6 +228,9 @@ public class Level extends Addon {
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
user -> getManager().getPointsToNextString(gm.getOverWorld(), user.getUniqueId()));
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_island_level_max",
user -> String.valueOf(getManager().getIslandMaxLevel(gm.getOverWorld(), user.getUniqueId())));
// Visited Island Level
getPlugin().getPlaceholdersManager().registerPlaceholder(this,

View File

@ -231,6 +231,19 @@ public class LevelsManager {
return island == null ? 0L : getLevelsData(island).getLevel();
}
/**
* Get the maximum level ever given to this island
* @param world - world where the island is
* @param targetPlayer - target player UUID
* @return Max level of the player's island or zero if player is unknown or UUID is null
*/
public long getIslandMaxLevel(@NonNull World world, @Nullable UUID targetPlayer) {
if (targetPlayer == null) return 0L;
// Get the island
Island island = addon.getIslands().getIsland(world, targetPlayer);
return island == null ? 0L : getLevelsData(island).getMaxLevel();
}
/**
* Returns a formatted string of the target player's island level
* @param world - world where the island is

View File

@ -43,6 +43,11 @@ public class IslandLevels implements DataObject {
*/
@Expose
private long pointsToNextLevel;
/**
* The maximum level this island has ever had
*/
@Expose
private long maxLevel;
/**
* Underwater count
@ -94,6 +99,10 @@ public class IslandLevels implements DataObject {
*/
public void setLevel(long level) {
this.level = level;
// Track maximum level
if (level > this.maxLevel) {
maxLevel = level;
}
}
/**
@ -124,6 +133,14 @@ public class IslandLevels implements DataObject {
this.pointsToNextLevel = pointsToNextLevel;
}
/**
* Get the maximum level ever set using {@link #setLevel(long)}
* @return the maxLevel
*/
public long getMaxLevel() {
return maxLevel;
}
/**
* @return the uwCount
*/

View File

@ -270,6 +270,15 @@ public class LevelsManagerTest {
//Map<UUID, Long> tt = lm.getTopTen(world, 10);
//assertEquals(1, tt.size());
//assertTrue(tt.get(uuid) == 10000);
assertEquals(10000L, lm.getIslandMaxLevel(world, uuid));
results.setLevel(5000);
lm.calculateLevel(uuid, island);
// Complete the pipelined completable future
cf.complete(results);
assertEquals(5000L, lm.getLevelsData(island).getLevel());
// Still should be 10000
assertEquals(10000L, lm.getIslandMaxLevel(world, uuid));
}