Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public boolean shouldAllowSpawn(Entity entity) {
}

public void applyConfigToWorld() {
spawnCategoriesConfig.values()
.forEach(SpawnCategoryConfig::applyConfigToWorld);
for (SpawnCategory category : SpawnCategory.values()) {
getSpawnCategoryConfig(category).applyConfigToWorld();
}
}

@Override
Expand All @@ -61,14 +62,18 @@ public ConfigurationSection toSection() {
@ApiStatus.Internal
public static EntitySpawnConfig fromSection(CoreConfig config, ConfigurationSection section) {
Map<SpawnCategory, SpawnCategoryConfig> spawnCategoriesConfig = new LinkedHashMap<>();
section.getValues(false).forEach((key, value) -> {
if (!(value instanceof ConfigurationSection sectionPart)) {
Logging.warning("Invalid spawn category config for " + key + ": " + value);
return;
Map<String, Object> existingCategories = section.getValues(false);
for (SpawnCategory category : SpawnCategory.values()) {
Object value = existingCategories.get(category.toString().toLowerCase(Locale.ENGLISH));
if (!(value instanceof ConfigurationSection)) {
if (value != null) {
Logging.warning("Invalid spawn category config for " + category + ": " + value);
}
value = section.createSection(category.toString());
}
SpawnCategory spawnCategory = SpawnCategory.valueOf(key.toUpperCase(Locale.ENGLISH));
spawnCategoriesConfig.put(spawnCategory, new SpawnCategoryConfig(config, spawnCategory, sectionPart));
});
ConfigurationSection sectionPart = (ConfigurationSection) value;
spawnCategoriesConfig.put(category, new SpawnCategoryConfig(config, category, sectionPart));
}
return new EntitySpawnConfig(config, spawnCategoriesConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.mvplugins.multiverse.core.config.node.ListConfigNode;
import org.mvplugins.multiverse.core.config.node.Node;
import org.mvplugins.multiverse.core.config.node.NodeGroup;
import org.mvplugins.multiverse.core.config.node.serializer.NodeSerializer;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.MultiverseWorld;

Expand Down Expand Up @@ -71,25 +72,28 @@
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: -1", world.getName(), spawnCategory);
bukkitWorld.setTicksPerSpawns(spawnCategory, -1);
}
} else {
Logging.finer("World %s %s setTicksPerSpawns: %d", world.getName(), spawnCategory, getTickRate());
bukkitWorld.setTicksPerSpawns(spawnCategory, getTickRate());
if (!isSpawn() && getExceptions().isEmpty()) {
Logging.finer("World %s %s setTicksPerSpawns: 0", world.getName(), spawnCategory);
bukkitWorld.setTicksPerSpawns(spawnCategory, 0);
return;
}
if (getTickRate() == -2) {

Check warning on line 80 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 '-2' is a magic number. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:80:30: warning: '-2' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
Logging.finer("World %s %s skipping setTicksPerSpawns as tick-rate is UNSET", world.getName(), spawnCategory);

Check warning on line 81 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 122). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:81:0: warning: Line is longer than 120 characters (found 122). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
return;
}
Logging.finer("World %s %s setTicksPerSpawns: %d", world.getName(), spawnCategory, getTickRate());
bukkitWorld.setTicksPerSpawns(spawnCategory, getTickRate());
}

private void applySpawnLimit(World bukkitWorld) {
if (!config.getApplyEntitySpawnLimit()) {
Logging.finer("Skipping World %s %s setSpawnLimit due to core config", world.getName(), spawnCategory);
return;
}
if (getSpawnLimit() == -2) {

Check warning on line 93 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 '-2' is a magic number. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:93:32: warning: '-2' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
Logging.finer("World %s %s skipping setSpawnLimit as spawn-limit is UNSET", world.getName(), spawnCategory);
return;
}
Logging.finer("World %s %s setSpawnLimit: %d", world.getName(), spawnCategory, getSpawnLimit());
bukkitWorld.setSpawnLimit(spawnCategory, getSpawnLimit());
}
Expand Down Expand Up @@ -166,25 +170,33 @@
.build());

final ConfigNode<Integer> tickRate = node(ConfigNode.builder("tick-rate", Integer.class)
.defaultValue(-1)
.suggester(input -> List.of("-1", "10", "100", "400", "1000"))
.defaultValue(-2)

Check warning on line 173 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 '-2' is a magic number. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:173:31: warning: '-2' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
.suggester(input -> List.of("@unset", "@bukkit", "10", "100", "400", "1000"))

Check warning on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "1000" appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:174:86: warning: The String "1000" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check warning on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "400" appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:174:79: warning: The String "400" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check warning on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "100" appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:174:72: warning: The String "100" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check warning on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "10" appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:174:66: warning: The String "10" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check warning on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "@Bukkit" appears 4 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:174:55: warning: The String "@Bukkit" appears 4 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check warning on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "@Unset" appears 4 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java:174:45: warning: The String "@Unset" appears 4 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)

Check failure on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "@bukkit" 4 times.

See more on https://sonarcloud.io/project/issues?id=Multiverse_Multiverse-Core&issues=AZsB2FssRwmy363BVva0&open=AZsB2FssRwmy363BVva0&pullRequest=3396

Check failure on line 174 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "@unset" 4 times.

See more on https://sonarcloud.io/project/issues?id=Multiverse_Multiverse-Core&issues=AZsB2FssRwmy363BVva1&open=AZsB2FssRwmy363BVva1&pullRequest=3396
.serializer(SpawnValueSerializer.INSTANCE)
.onLoadAndChange((oldValue, newValue) -> applyConfigToWorld())
.onChange((sender, oldValue, newValue) -> {
if (!config.getApplyEntitySpawnRate()) {
sender.sendMessage(ChatColor.RED + "Warning: Changing tick rates has no effect because " +
"'apply-entity-spawn-rate' is disabled in the core config.");
} else if (newValue == -2) {
sender.sendMessage(ChatColor.YELLOW + "Note: Setting tick-rate to '@unset' may not reset to " +
"the server default until the world is reloaded or server is restarted.");
}
})
.build());

final ConfigNode<Integer> spawnLimit = node(ConfigNode.builder("spawn-limit", Integer.class)
.defaultValue(-1)
.suggester(input -> List.of("-1", "10", "100", "400", "1000"))
.defaultValue(-2)
.suggester(input -> List.of("@unset", "@bukkit", "10", "100", "400", "1000"))
.serializer(SpawnValueSerializer.INSTANCE)
.onLoadAndChange((oldValue, newValue) -> applyConfigToWorld())
.onChange((sender, oldValue, newValue) -> {
if (!config.getApplyEntitySpawnLimit()) {
sender.sendMessage(ChatColor.RED + "Warning: Changing spawn limits has no effect because " +
"'apply-entity-spawn-limit' is disabled in the core config.");
} else if (newValue == -2) {
sender.sendMessage(ChatColor.YELLOW + "Note: Setting spawn-limit to '@unset' may not reset to " +
"the server default until the world is reloaded or server is restarted.");
}
})
.build());
Expand All @@ -197,4 +209,29 @@
.onLoadAndChange((oldValue, newValue) -> applyConfigToWorld())
.build());
}

private static class SpawnValueSerializer implements NodeSerializer<Integer> {

Check warning on line 213 in src/main/java/org/mvplugins/multiverse/core/world/entity/SpawnCategoryConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A Singleton implementation was detected. Make sure the use of the Singleton pattern is required and the implementation is the right one for the context.

See more on https://sonarcloud.io/project/issues?id=Multiverse_Multiverse-Core&issues=AZsB2FssRwmy363BVva2&open=AZsB2FssRwmy363BVva2&pullRequest=3396
private static final SpawnValueSerializer INSTANCE = new SpawnValueSerializer();

@Override
public Integer deserialize(Object object, Class<Integer> type) {
String str = String.valueOf(object);
if (str.equalsIgnoreCase("@unset")) {
return -2;
}
if (str.equalsIgnoreCase("@bukkit")) {
return -1;
}
return Integer.parseInt(str);
}

@Override
public Object serialize(Integer object, Class<Integer> type) {
return switch (object) {
case -2 -> "@unset";
case -1 -> "@bukkit";
default -> object;
};
}
}
}
84 changes: 82 additions & 2 deletions src/test/resources/worlds/default_worlds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,47 @@ world:
z: 48.0
pitch: 0.0
yaw: 0.0
spawning: {}
spawning:
monster:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_underground_creature:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
axolotl:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
misc:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
world-blacklist: []
version: 1.2
world_nether:
Expand Down Expand Up @@ -71,6 +111,46 @@ world_nether:
z: 48.0
pitch: 0.0
yaw: 0.0
spawning: {}
spawning:
monster:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_underground_creature:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
axolotl:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
misc:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
world-blacklist: []
version: 1.2
42 changes: 41 additions & 1 deletion src/test/resources/worlds/delete_worlds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,46 @@ world_nether:
z: 48.0
pitch: 0.0
yaw: 0.0
spawning: {}
spawning:
monster:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_underground_creature:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
axolotl:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
misc:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
world-blacklist: []
version: 1.2
81 changes: 78 additions & 3 deletions src/test/resources/worlds/edgecase_worlds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,46 @@ world:
pitch: 0.0
yaw: 0.0
spawning:
monster:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
animal:
spawn: falSe
tick-rate: 123
spawn-limit: -1
exceptions: [cow]
spawn-limit: '@unset'
exceptions: [ cow ]
water_animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_underground_creature:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
axolotl:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
misc:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
world-blacklist: # should be parsed as list of string
- a
- 1
Expand Down Expand Up @@ -78,6 +113,46 @@ world_nether:
z: 48.0
pitch: 0.0
yaw: 0.0
spawning: {}
spawning:
monster:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_animal:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
water_underground_creature:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
ambient:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
axolotl:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
misc:
exceptions: [ ]
spawn: true
spawn-limit: '@unset'
tick-rate: '@unset'
world-blacklist: []
version: 1.2
Loading
Loading