Skip to content

Commit 2561107

Browse files
authored
Merge pull request #3325 from Multiverse/feat/disable-apply-spawn
Add option to disable mv handling of spawn rate and limit
2 parents bd09d6c + 25c7017 commit 2561107

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed

src/main/java/org/mvplugins/multiverse/core/config/CoreConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,26 @@ public boolean getEnforceFlight() {
190190
return configHandle.get(configNodes.enforceFlight);
191191
}
192192

193+
@ApiStatus.AvailableSince("5.3")
194+
public Try<Void> setApplyEntitySpawnRate(boolean applyEntitySpawnRate) {
195+
return configHandle.set(configNodes.applyEntitySpawnRate, applyEntitySpawnRate);
196+
}
197+
198+
@ApiStatus.AvailableSince("5.3")
199+
public boolean getApplyEntitySpawnRate() {
200+
return configHandle.get(configNodes.applyEntitySpawnRate);
201+
}
202+
203+
@ApiStatus.AvailableSince("5.3")
204+
public Try<Void> setApplyEntitySpawnLimit(boolean applyEntitySpawnLimit) {
205+
return configHandle.set(configNodes.applyEntitySpawnLimit, applyEntitySpawnLimit);
206+
}
207+
208+
@ApiStatus.AvailableSince("5.3")
209+
public boolean getApplyEntitySpawnLimit() {
210+
return configHandle.get(configNodes.applyEntitySpawnLimit);
211+
}
212+
193213
/**
194214
* {@inheritDoc}
195215
*/

src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ private <N extends Node> N node(N node) {
137137
.name("enforce-flight")
138138
.build());
139139

140+
final ConfigNode<Boolean> applyEntitySpawnRate = node(ConfigNode.builder("world.apply-entity-spawn-rate", Boolean.class)
141+
.comment("")
142+
.comment("Sets whether Multiverse will apply the world's entity `tick-rate` config in worlds.yml.")
143+
.comment("If disabled, the `tick-rate` config in worlds.yml will be ignored.")
144+
.comment("Disable this if you want paper-world.yml or another plugin to handle entity spawn rate per world.")
145+
.defaultValue(true)
146+
.name("apply-entity-spawn-rate")
147+
.build());
148+
149+
final ConfigNode<Boolean> applyEntitySpawnLimit = node(ConfigNode.builder("world.apply-entity-spawn-limit", Boolean.class)
150+
.comment("")
151+
.comment("Sets whether Multiverse will apply the world's entity `spawn-limit` config when a world is loaded.")
152+
.comment("If disabled, the `spawn-limit` config in worlds.yml will be ignored.")
153+
.comment("Disable this if you want paper-world.yml or another plugin to handle entity limits per world.")
154+
.defaultValue(true)
155+
.name("apply-entity-spawn-limit")
156+
.build());
157+
140158
final ConfigNode<Boolean> autoPurgeEntities = node(ConfigNode.builder("world.auto-purge-entities", Boolean.class)
141159
.comment("")
142160
.comment("Sets whether Multiverse will purge entities on world load based world's entity spawn config.")

src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.entity.Entity;
88
import org.bukkit.entity.EntityType;
99
import org.bukkit.entity.SpawnCategory;
10+
import org.mvplugins.multiverse.core.MultiverseCoreApi;
1011
import org.mvplugins.multiverse.core.config.handle.MemoryConfigurationHandle;
1112
import org.mvplugins.multiverse.core.config.handle.StringPropertyHandle;
1213
import org.mvplugins.multiverse.core.config.node.ConfigNode;
@@ -57,21 +58,37 @@ void applyConfigToWorld() {
5758
return;
5859
}
5960
loadedWorld.getBukkitWorld().peek(bukkitWorld -> {
60-
if (!isSpawn()) {
61-
if (getExceptions().isEmpty()) {
62-
Logging.finer("World %s %s setTicksPerSpawns: 0", world.getName(), spawnCategory);
63-
bukkitWorld.setTicksPerSpawns(spawnCategory, 0);
64-
} else {
65-
Logging.finer("World %s %s setTicksPerSpawns: -1", world.getName(), spawnCategory);
66-
bukkitWorld.setTicksPerSpawns(spawnCategory, -1);
67-
}
61+
applyTickPerSpawns(bukkitWorld);
62+
applySpawnLimit(bukkitWorld);
63+
});
64+
}
65+
66+
private void applyTickPerSpawns(World bukkitWorld) {
67+
if (!MultiverseCoreApi.get().getCoreConfig().getApplyEntitySpawnLimit()) {
68+
Logging.finer("World %s %s skipping setTicksPerSpawns due to core config", world.getName(), spawnCategory);
69+
return;
70+
}
71+
if (!isSpawn()) {
72+
if (getExceptions().isEmpty()) {
73+
Logging.finer("World %s %s setTicksPerSpawns: 0", world.getName(), spawnCategory);
74+
bukkitWorld.setTicksPerSpawns(spawnCategory, 0);
6875
} else {
69-
Logging.finer("World %s %s setTicksPerSpawns: %d", world.getName(), spawnCategory, getTickRate());
70-
bukkitWorld.setTicksPerSpawns(spawnCategory, getTickRate());
76+
Logging.finer("World %s %s setTicksPerSpawns: -1", world.getName(), spawnCategory);
77+
bukkitWorld.setTicksPerSpawns(spawnCategory, -1);
7178
}
72-
Logging.finer("World %s %s setSpawnLimit: %d", world.getName(), spawnCategory, getSpawnLimit());
73-
bukkitWorld.setSpawnLimit(spawnCategory, getSpawnLimit());
74-
});
79+
} else {
80+
Logging.finer("World %s %s setTicksPerSpawns: %d", world.getName(), spawnCategory, getTickRate());
81+
bukkitWorld.setTicksPerSpawns(spawnCategory, getTickRate());
82+
}
83+
}
84+
85+
private void applySpawnLimit(World bukkitWorld) {
86+
if (!MultiverseCoreApi.get().getCoreConfig().getApplyEntitySpawnLimit()) {
87+
Logging.finer("Skipping World %s %s setSpawnLimit due to core config", world.getName(), spawnCategory);
88+
return;
89+
}
90+
Logging.finer("World %s %s setSpawnLimit: %d", world.getName(), spawnCategory, getSpawnLimit());
91+
bukkitWorld.setSpawnLimit(spawnCategory, getSpawnLimit());
7592
}
7693

7794
public StringPropertyHandle getStringPropertyHandle() {

src/test/resources/configs/fresh_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ world:
44
enforce-access: false
55
enforce-gamemode: true
66
enforce-flight: true
7+
apply-entity-spawn-rate: true
8+
apply-entity-spawn-limit: true
79
auto-purge-entities: false
810
world-name-format:
911
nether: '%overworld%_nether'

0 commit comments

Comments
 (0)