Merge branch 'BentoBoxWorld:develop' into feature/#223-count-shulkers

This commit is contained in:
DevSolaris 2023-01-17 14:35:28 +01:00 committed by GitHub
commit e959ec7524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 6 deletions

View File

@ -36,6 +36,7 @@ import world.bentobox.level.config.BlockConfig;
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;
@ -226,6 +227,13 @@ public class Level extends Addon {
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()));

View File

@ -181,6 +181,7 @@ public class LevelsManager {
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));
}
@ -432,6 +433,7 @@ public class LevelsManager {
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

View File

@ -50,7 +50,7 @@ import world.bentobox.level.calculators.Results.Result;
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,
@ -133,6 +133,9 @@ public class IslandLevelCalculator {
case "tan":
x = Math.tan(Math.toRadians(x));
break;
case "log":
x = Math.log(x);
break;
default:
throw new RuntimeException("Unknown function: " + func);
}
@ -602,6 +605,7 @@ public class IslandLevelCalculator {
}
long blockAndDeathPoints = this.results.rawBlockCount.get();
this.results.totalPoints.set(blockAndDeathPoints);
if (this.addon.getSettings().getDeathPenalty() > 0)
{

View File

@ -36,6 +36,7 @@ public class Results {
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) {
@ -93,6 +94,21 @@ public class Results {
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();
}
@ -109,7 +125,7 @@ public class Results {
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
@ -130,4 +146,4 @@ public class Results {
return state;
}
}
}

View File

@ -110,7 +110,7 @@ public class IslandLevelCommand extends CompositeCommand {
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

View File

@ -90,7 +90,7 @@ public class ConfigSettings implements ConfigObject {
@ConfigComment("Island level calculation formula")
@ConfigComment("blocks - the sum total of all block values, less any death penalty")
@ConfigComment("level_cost - in a linear equation, the value of one level")
@ConfigComment("This formula can include +,=,*,/,sqrt,^,sin,cos,tan. Result will always be rounded to a long integer")
@ConfigComment("This formula can include +,=,*,/,sqrt,^,sin,cos,tan,log (natural log). Result will always be rounded to a long integer")
@ConfigComment("for example, an alternative non-linear option could be: 3 * sqrt(blocks / level_cost)")
@ConfigEntry(path = "level-calc")
private String levelCalc = "blocks / level_cost";

View File

@ -49,6 +49,12 @@ public class IslandLevels implements DataObject {
@Expose
private long maxLevel;
/**
* Total points
*/
@Expose
private long totalPoints;
/**
* Underwater count
*/
@ -133,6 +139,20 @@ public class IslandLevels implements DataObject {
this.pointsToNextLevel = pointsToNextLevel;
}
/**
* @return the totalPoints
*/
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

View File

@ -53,7 +53,7 @@ levelcost: 100
# Island level calculation formula
# blocks - the sum total of all block values, less any death penalty
# level_cost - in a linear equation, the value of one level
# This formula can include +,=,*,/,sqrt,^,sin,cos,tan. Result will always be rounded to a long integer
# This formula can include +,=,*,/,sqrt,^,sin,cos,tan,log (natural log). Result will always be rounded to a long integer
# for example, an alternative non-linear option could be: 3 * sqrt(blocks / level_cost)
level-calc: blocks / level_cost
#