Skip to content

Commit

Permalink
feat: add island total points + placeholder (#264)
Browse files Browse the repository at this point in the history
* feat: add island total points + placeholder

* Update IslandLevels.java
  • Loading branch information
emmanuelvlad committed Jan 16, 2023
1 parent ac6bead commit fba7394
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import world.bentobox.level.config.ConfigSettings;
import world.bentobox.level.listeners.IslandActivitiesListeners;
import world.bentobox.level.listeners.JoinLeaveListener;
import world.bentobox.level.objects.IslandLevels;
import world.bentobox.level.listeners.MigrationListener;
import world.bentobox.level.objects.LevelsData;
import world.bentobox.level.objects.TopTenData;
Expand Down Expand Up @@ -226,6 +227,13 @@ private void registerPlaceholders(GameModeAddon gm) {
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_island_level_raw",
user -> String.valueOf(getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId())));
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_island_total_points",
user -> {
IslandLevels data = getManager().getLevelsData(this.getIslands().getIsland(gm.getOverWorld(), user));
return data.getTotalPoints()+"";
});

getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
user -> getManager().getPointsToNextString(gm.getOverWorld(), user.getUniqueId()));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/level/LevelsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private boolean fireIslandLevelCalcEvent(UUID targetPlayer, Island island, Resul
results.setInitialLevel((Long)ilce.getKeyValues().getOrDefault("initialLevel", results.getInitialLevel()));
results.setDeathHandicap((int)ilce.getKeyValues().getOrDefault("deathHandicap", results.getDeathHandicap()));
results.setPointsToNextLevel((Long)ilce.getKeyValues().getOrDefault("pointsToNextLevel", results.getPointsToNextLevel()));
results.setTotalPoints((Long)ilce.getKeyValues().getOrDefault("totalPoints", results.getTotalPoints()));
return ((Boolean)ilce.getKeyValues().getOrDefault("isCancelled", false));
}

Expand Down Expand Up @@ -432,6 +433,7 @@ private void setIslandResults(World world, @NonNull UUID owner, Results r) {
ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem)));
ld.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem)));
ld.setPointsToNextLevel(r.getPointsToNextLevel());
ld.setTotalPoints(r.getTotalPoints());
levelsCache.put(island.getUniqueId(), ld);
handler.saveObjectAsync(ld);
// Update TopTen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

public class IslandLevelCalculator {
private static final String LINE_BREAK = "==================================";
public static final long MAX_AMOUNT = 10000;
public static final long MAX_AMOUNT = 10000000;
private static final List<Material> CHESTS = Arrays.asList(Material.CHEST, Material.CHEST_MINECART, Material.TRAPPED_CHEST,
Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX, Material.BROWN_SHULKER_BOX,
Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX,
Expand Down Expand Up @@ -601,6 +601,7 @@ public void tidyUp() {
}

long blockAndDeathPoints = this.results.rawBlockCount.get();
this.results.totalPoints.set(blockAndDeathPoints);

if (this.addon.getSettings().getDeathPenalty() > 0)
{
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/world/bentobox/level/calculators/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum Result {
AtomicInteger deathHandicap = new AtomicInteger(0);
AtomicLong pointsToNextLevel = new AtomicLong(0);
AtomicLong initialLevel = new AtomicLong(0);
AtomicLong totalPoints = new AtomicLong(0);
final Result state;

public Results(Result state) {
Expand Down Expand Up @@ -93,6 +94,21 @@ public void setPointsToNextLevel(long points) {
pointsToNextLevel.set(points);
}

/**
* @return the totalPoints
*/
public long getTotalPoints() {
return totalPoints.get();
}

/**
* Set the total points
* @param points
*/
public void setTotalPoints(long points) {
totalPoints.set(points);
}

public long getInitialLevel() {
return initialLevel.get();
}
Expand All @@ -109,7 +125,7 @@ public String toString() {
return "Results [report=" + report + ", mdCount=" + mdCount + ", uwCount=" + uwCount + ", ncCount="
+ ncCount + ", ofCount=" + ofCount + ", rawBlockCount=" + rawBlockCount + ", underWaterBlockCount="
+ underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap
+ ", pointsToNextLevel=" + pointsToNextLevel + ", initialLevel=" + initialLevel + "]";
+ ", pointsToNextLevel=" + pointsToNextLevel + ", totalPoints=" + totalPoints + ", initialLevel=" + initialLevel + "]";
}
/**
* @return the mdCount
Expand All @@ -130,4 +146,4 @@ public Result getState() {
return state;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void showResult(User user, UUID playerUUID, Island island, long oldLevel
user.sendMessage("island.level.deaths", "[number]", String.valueOf(results.getDeathHandicap()));
}
// Send player how many points are required to reach next island level
if (results.getPointsToNextLevel() >= 0 && results.getPointsToNextLevel() < 10000) {
if (results.getPointsToNextLevel() >= 0) {
user.sendMessage("island.level.required-points-to-next-level", "[points]", String.valueOf(results.getPointsToNextLevel()));
}
// Tell other team members
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/world/bentobox/level/objects/IslandLevels.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public class IslandLevels implements DataObject {
@Expose
private long maxLevel;

/**
* Total points
*/
@Expose
private long totalPoints;

/**
* Underwater count
*/
Expand Down Expand Up @@ -133,6 +139,20 @@ public void setPointsToNextLevel(long pointsToNextLevel) {
this.pointsToNextLevel = pointsToNextLevel;
}

/**
* @return the pointsToNextLevel
*/
public long getTotalPoints() {
return totalPoints;
}

/**
* @param totalPoints the totalPoints to set
*/
public void setTotalPoints(long totalPoints) {
this.totalPoints = totalPoints;
}

/**
* Get the maximum level ever set using {@link #setLevel(long)}
* @return the maxLevel
Expand Down

0 comments on commit fba7394

Please sign in to comment.