diff --git a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java index e64b31d..b927e00 100644 --- a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java +++ b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java @@ -1,6 +1,15 @@ package world.bentobox.level.calculators; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -92,17 +101,15 @@ public class CalcIslandLevel { total += chunksToScan.size(); } } - queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), new Runnable() { - public void run() { - for (int i = 0; i < 10; i++) { - if (q.size() == 0) { - return; - } - Chunk c = q.remove(); - getChunk(c); + queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), () -> { + for (int i = 0; i < addon.getSettings().getChunks(); i++) { + if (q.size() == 0) { + return; } + Chunk c = q.remove(); + getChunk(c); } - }, 1L, 1L); + }, addon.getSettings().getTickDelay(), addon.getSettings().getTickDelay()); chunksToScan.forEach(c -> worlds.forEach(w -> Util.getChunkAtAsync(w, c.x, c.z).thenAccept(this::addChunkQueue))); } diff --git a/src/main/java/world/bentobox/level/config/Settings.java b/src/main/java/world/bentobox/level/config/Settings.java index 979bd8e..9beeef9 100644 --- a/src/main/java/world/bentobox/level/config/Settings.java +++ b/src/main/java/world/bentobox/level/config/Settings.java @@ -23,6 +23,8 @@ public class Settings { private int deathpenalty; private long levelCost; private int levelWait; + private int chunks; + private long taskDelay; private List gameModes; @@ -33,9 +35,22 @@ public class Settings { // GameModes gameModes = level.getConfig().getStringList("game-modes"); + + // Performance + setTickDelay(level.getConfig().getLong("task-delay",1)); + if (taskDelay < 1L) { + level.logError("task-delay must be at least 1"); + setTickDelay(1L); + } + setChunks(level.getConfig().getInt("chunks", 10)); + if (chunks < 1) { + level.logError("chunks must be at least 1"); + setChunks(1); + } setLevelWait(level.getConfig().getInt("levelwait", 60)); if (getLevelWait() < 0) { + level.logError("levelwait must be at least 0"); setLevelWait(0); } setDeathpenalty(level.getConfig().getInt("deathpenalty", 0)); @@ -228,4 +243,32 @@ public class Settings { return level.getConfig().getString("level-calc", "blocks / level_cost"); } + /** + * @return the chunks + */ + public int getChunks() { + return chunks; + } + + /** + * @param chunks the chunks to set + */ + public void setChunks(int chunks) { + this.chunks = chunks; + } + + /** + * @return the tickDelay + */ + public long getTickDelay() { + return taskDelay; + } + + /** + * @param tickDelay the tickDelay to set + */ + public void setTickDelay(long tickDelay) { + this.taskDelay = tickDelay; + } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ae1f500..ea1d5cb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,6 +9,15 @@ game-modes: - CaveBlock #- SkyGrid +# Performance settings +# Level is very processor intensive, so these settings may need to be tweaked to optimize for your server +# Delay between each task that loads chunks for calulcating levels +# Increasing this will slow down level calculations but reduce average load +task-delay: 1 + +# Number of chunks that will be processed per task +chunks: 10 + # This file lists the values for various blocks that are used to calculate the # island level. Level = total of all blocks in island boundary / 100. # Players with the permission askyblock.island.multiplier.# will have their blocks