diff --git a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java index 7bba904..a1b060b 100644 --- a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java +++ b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java @@ -31,8 +31,8 @@ import world.bentobox.level.Level; public class CalcIslandLevel { - private static final int MAX_CHUNKS = 200; - private static final long SPEED = 1; + private final int MAX_CHUNKS; + private final long SPEED; private static final String LINE_BREAK = "=================================="; private boolean checking; private final BukkitTask task; @@ -80,6 +80,9 @@ public class CalcIslandLevel { // Set the initial island handicap result.initialLevel = addon.getInitialIslandLevel(island); + SPEED = addon.getSettings().getUpdateTickDelay(); + MAX_CHUNKS = addon.getSettings().getChunksPerTick(); + // Get chunks to scan chunksToScan = getChunksToScan(island); diff --git a/src/main/java/world/bentobox/level/config/Settings.java b/src/main/java/world/bentobox/level/config/Settings.java index 5a16783..0c63609 100644 --- a/src/main/java/world/bentobox/level/config/Settings.java +++ b/src/main/java/world/bentobox/level/config/Settings.java @@ -1,6 +1,5 @@ package world.bentobox.level.config; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,7 +22,19 @@ public class Settings { private int deathpenalty; private long levelCost; private int levelWait; - private List gameModes = new ArrayList<>(); + + /** + * Stores number of chunks that can be updated in single tick. + */ + private int chunksPerTick; + + /** + * Stores number of tick delay between each chunk loading. + */ + private long updateTickDelay; + + private List gameModes; + public Settings(Level level) { this.level = level; @@ -32,6 +43,22 @@ public class Settings { // GameModes gameModes = level.getConfig().getStringList("game-modes"); + // Level calculation chunk load speed + this.setUpdateTickDelay(level.getConfig().getLong("updatetickdelay", 1)); + + if (this.getUpdateTickDelay() <= 0) + { + this.setUpdateTickDelay(1); + } + + // Level calculation chunk count per update + this.setChunksPerTick(level.getConfig().getInt("chunkspertick", 200)); + + if (this.getChunksPerTick() <= 0) + { + this.setChunksPerTick(200); + } + setLevelWait(level.getConfig().getInt("levelwait", 60)); if (getLevelWait() < 0) { setLevelWait(0); @@ -218,4 +245,46 @@ public class Settings { public boolean isShortHand() { return level.getConfig().getBoolean("shorthand"); } + + + /** + * This method returns the number of chunks that can be processed at single tick. + * @return the value of chunksPerTick. + */ + public int getChunksPerTick() + { + return this.chunksPerTick; + } + + + /** + * This method sets the chunksPerTick value. + * @param chunksPerTick the chunksPerTick new value. + * + */ + public void setChunksPerTick(int chunksPerTick) + { + this.chunksPerTick = chunksPerTick; + } + + + /** + * This method returns the delay between each update call. + * @return the value of updateTickDelay. + */ + public long getUpdateTickDelay() + { + return this.updateTickDelay; + } + + + /** + * This method sets the updateTickDelay value. + * @param updateTickDelay the updateTickDelay new value. + * + */ + public void setUpdateTickDelay(long updateTickDelay) + { + this.updateTickDelay = updateTickDelay; + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3651de6..0891dc9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -40,6 +40,14 @@ levelcost: 100 # Cooldown between level requests in seconds levelwait: 60 +# Delay between each task that loads chunks for calculating island level. +# Increasing this will increase time to calculate island level. +updatetickdelay: 1 + +# Number of chunks that will be processed at the same tick. +# Decreasing this will increase time to calculate island level. +chunkspertick: 200 + # Death penalty # How many block values a player will lose per death. # Default value of 100 means that for every death, the player will lose 1 level (if levelcost is 100)