diff --git a/src/main/java/org/mvplugins/multiverse/core/config/CoreConfig.java b/src/main/java/org/mvplugins/multiverse/core/config/CoreConfig.java index 11d961afb..a3ee2d5b6 100644 --- a/src/main/java/org/mvplugins/multiverse/core/config/CoreConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/config/CoreConfig.java @@ -190,6 +190,26 @@ public boolean getEnforceFlight() { return configHandle.get(configNodes.enforceFlight); } + @ApiStatus.AvailableSince("5.3") + public Try setApplyEntitySpawnRate(boolean applyEntitySpawnRate) { + return configHandle.set(configNodes.applyEntitySpawnRate, applyEntitySpawnRate); + } + + @ApiStatus.AvailableSince("5.3") + public boolean getApplyEntitySpawnRate() { + return configHandle.get(configNodes.applyEntitySpawnRate); + } + + @ApiStatus.AvailableSince("5.3") + public Try setApplyEntitySpawnLimit(boolean applyEntitySpawnLimit) { + return configHandle.set(configNodes.applyEntitySpawnLimit, applyEntitySpawnLimit); + } + + @ApiStatus.AvailableSince("5.3") + public boolean getApplyEntitySpawnLimit() { + return configHandle.get(configNodes.applyEntitySpawnLimit); + } + /** * {@inheritDoc} */ diff --git a/src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java b/src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java index 8b10c33e7..670b6f039 100644 --- a/src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java +++ b/src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java @@ -137,6 +137,24 @@ private N node(N node) { .name("enforce-flight") .build()); + final ConfigNode applyEntitySpawnRate = node(ConfigNode.builder("world.apply-entity-spawn-rate", Boolean.class) + .comment("") + .comment("Sets whether Multiverse will apply the world's entity `tick-rate` config in worlds.yml.") + .comment("If disabled, the `tick-rate` config in worlds.yml will be ignored.") + .comment("Disable this if you want paper-world.yml or another plugin to handle entity spawn rate per world.") + .defaultValue(true) + .name("apply-entity-spawn-rate") + .build()); + + final ConfigNode applyEntitySpawnLimit = node(ConfigNode.builder("world.apply-entity-spawn-limit", Boolean.class) + .comment("") + .comment("Sets whether Multiverse will apply the world's entity `spawn-limit` config when a world is loaded.") + .comment("If disabled, the `spawn-limit` config in worlds.yml will be ignored.") + .comment("Disable this if you want paper-world.yml or another plugin to handle entity limits per world.") + .defaultValue(true) + .name("apply-entity-spawn-limit") + .build()); + final ConfigNode autoPurgeEntities = node(ConfigNode.builder("world.auto-purge-entities", Boolean.class) .comment("") .comment("Sets whether Multiverse will purge entities on world load based world's entity spawn config.") diff --git a/src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java b/src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java index 5f7b49c10..590942328 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.SpawnCategory; +import org.mvplugins.multiverse.core.MultiverseCoreApi; import org.mvplugins.multiverse.core.config.handle.MemoryConfigurationHandle; import org.mvplugins.multiverse.core.config.handle.StringPropertyHandle; import org.mvplugins.multiverse.core.config.node.ConfigNode; @@ -57,21 +58,37 @@ void applyConfigToWorld() { return; } loadedWorld.getBukkitWorld().peek(bukkitWorld -> { - if (!isSpawn()) { - if (getExceptions().isEmpty()) { - Logging.finer("World %s %s setTicksPerSpawns: 0", world.getName(), spawnCategory); - bukkitWorld.setTicksPerSpawns(spawnCategory, 0); - } else { - Logging.finer("World %s %s setTicksPerSpawns: -1", world.getName(), spawnCategory); - bukkitWorld.setTicksPerSpawns(spawnCategory, -1); - } + applyTickPerSpawns(bukkitWorld); + applySpawnLimit(bukkitWorld); + }); + } + + private void applyTickPerSpawns(World bukkitWorld) { + if (!MultiverseCoreApi.get().getCoreConfig().getApplyEntitySpawnLimit()) { + Logging.finer("World %s %s skipping setTicksPerSpawns due to core config", world.getName(), spawnCategory); + return; + } + if (!isSpawn()) { + if (getExceptions().isEmpty()) { + Logging.finer("World %s %s setTicksPerSpawns: 0", world.getName(), spawnCategory); + bukkitWorld.setTicksPerSpawns(spawnCategory, 0); } else { - Logging.finer("World %s %s setTicksPerSpawns: %d", world.getName(), spawnCategory, getTickRate()); - bukkitWorld.setTicksPerSpawns(spawnCategory, getTickRate()); + Logging.finer("World %s %s setTicksPerSpawns: -1", world.getName(), spawnCategory); + bukkitWorld.setTicksPerSpawns(spawnCategory, -1); } - Logging.finer("World %s %s setSpawnLimit: %d", world.getName(), spawnCategory, getSpawnLimit()); - bukkitWorld.setSpawnLimit(spawnCategory, getSpawnLimit()); - }); + } else { + Logging.finer("World %s %s setTicksPerSpawns: %d", world.getName(), spawnCategory, getTickRate()); + bukkitWorld.setTicksPerSpawns(spawnCategory, getTickRate()); + } + } + + private void applySpawnLimit(World bukkitWorld) { + if (!MultiverseCoreApi.get().getCoreConfig().getApplyEntitySpawnLimit()) { + Logging.finer("Skipping World %s %s setSpawnLimit due to core config", world.getName(), spawnCategory); + return; + } + Logging.finer("World %s %s setSpawnLimit: %d", world.getName(), spawnCategory, getSpawnLimit()); + bukkitWorld.setSpawnLimit(spawnCategory, getSpawnLimit()); } public StringPropertyHandle getStringPropertyHandle() { diff --git a/src/test/resources/configs/fresh_config.yml b/src/test/resources/configs/fresh_config.yml index aefac74bd..83425bd9a 100644 --- a/src/test/resources/configs/fresh_config.yml +++ b/src/test/resources/configs/fresh_config.yml @@ -4,6 +4,8 @@ world: enforce-access: false enforce-gamemode: true enforce-flight: true + apply-entity-spawn-rate: true + apply-entity-spawn-limit: true auto-purge-entities: false world-name-format: nether: '%overworld%_nether'