Skip to content

Commit 65d1141

Browse files
committed
Throw an error when trying to set spawn-rate or spawn-limit if disabled by config
1 parent 14d8ad7 commit 65d1141

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/org/mvplugins/multiverse/core/commands/EntitySpawnConfigCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ void onModifyCommand(
113113
.getSpawnCategoryConfig(spawnCategory)
114114
.getStringPropertyHandle()
115115
.modifyPropertyString(property, value, action)
116-
.onSuccess(ignore -> issuer.sendMessage("Successfully set " + property + " to " + value
116+
.onSuccess(ignore -> issuer.sendInfo("Successfully set " + property + " to " + value
117117
+ " for " + spawnCategory.name() + " in " + world.getName()))
118-
.onFailure(e -> issuer.sendMessage("Unable to set " + property + " to " + value
118+
.onFailure(e -> issuer.sendError("Unable to set " + property + " to " + value
119119
+ " for " + spawnCategory.name() + " in " + world.getName() + ": " + e.getMessage()));
120120

121121
worldManager.saveWorldsConfig();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,20 @@ private <N extends Node> N node(N node) {
167167
final ConfigNode<Integer> tickRate = node(ConfigNode.builder("tick-rate", Integer.class)
168168
.defaultValue(-1)
169169
.suggester(input -> List.of("-1", "10", "100", "400", "1000"))
170+
.validator(input -> config.getApplyEntitySpawnRate()
171+
? Try.success(null)
172+
: Try.failure(new IllegalStateException("Cannot set tick rate as 'apply-entity-spawn-rate' is false in config. " +
173+
"You can re-enable this option with '/mv config set apply-entity-spawn-rate true' command.")))
170174
.onSetValue((oldValue, newValue) -> applyConfigToWorld())
171175
.build());
172176

173177
final ConfigNode<Integer> spawnLimit = node(ConfigNode.builder("spawn-limit", Integer.class)
174178
.defaultValue(-1)
175179
.suggester(input -> List.of("-1", "10", "100", "400", "1000"))
180+
.validator(input -> config.getApplyEntitySpawnLimit()
181+
? Try.success(null)
182+
: Try.failure(new IllegalStateException("Cannot set spawn limit as 'apply-entity-spawn-limit' is false in config. " +
183+
"You can re-enable this option with '/mv config set apply-entity-spawn-limit true' command.")))
176184
.onSetValue((oldValue, newValue) -> applyConfigToWorld())
177185
.build());
178186

0 commit comments

Comments
 (0)