Skip to content

Commit 09ec4f8

Browse files
authored
Merge pull request #3328 from Multiverse/fix/mvapi-not-started
Pass in config object directly into spawn config class instead of using mvapi
2 parents b230c5a + f996f22 commit 09ec4f8

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/main/java/org/mvplugins/multiverse/core/world/WorldConfigNodes.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.jetbrains.annotations.NotNull;
1717

1818
import org.mvplugins.multiverse.core.MultiverseCore;
19+
import org.mvplugins.multiverse.core.config.CoreConfig;
1920
import org.mvplugins.multiverse.core.config.node.serializer.NodeSerializer;
2021
import org.mvplugins.multiverse.core.event.world.MVWorldPropertyChangedEvent;
2122
import org.mvplugins.multiverse.core.config.node.ConfigNode;
@@ -37,11 +38,13 @@ final class WorldConfigNodes {
3738
private final NodeGroup nodes = new NodeGroup();
3839
private WorldManager worldManager;
3940
private EnforcementHandler enforcementHandler;
41+
private CoreConfig config;
4042
private MultiverseWorld world = null;
4143

4244
WorldConfigNodes(@NotNull MultiverseCore multiverseCore) {
4345
this.worldManager = multiverseCore.getServiceLocator().getService(WorldManager.class);
4446
this.enforcementHandler = multiverseCore.getServiceLocator().getService(EnforcementHandler.class);
47+
this.config = multiverseCore.getServiceLocator().getService(CoreConfig.class);
4548
}
4649

4750
MultiverseWorld getWorld() {
@@ -244,15 +247,15 @@ public Object serialize(Material object, Class<Material> type) {
244247
}));
245248

246249
final ConfigNode<EntitySpawnConfig> enititySpawnConfig = node(ConfigNode.builder("spawning", EntitySpawnConfig.class)
247-
.defaultValue(() -> EntitySpawnConfig.fromSection(new MemoryConfiguration()))
250+
.defaultValue(() -> EntitySpawnConfig.fromSection(config, new MemoryConfiguration()))
248251
.hidden()
249252
.serializer(new NodeSerializer<>() {
250253
@Override
251254
public EntitySpawnConfig deserialize(Object object, Class<EntitySpawnConfig> type) {
252255
ConfigurationSection spawnSection = (object instanceof ConfigurationSection section)
253256
? section
254257
: new MemoryConfiguration();
255-
return EntitySpawnConfig.fromSection(spawnSection);
258+
return EntitySpawnConfig.fromSection(config, spawnSection);
256259
}
257260

258261
@Override

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.entity.Entity;
77
import org.bukkit.entity.SpawnCategory;
88
import org.jetbrains.annotations.ApiStatus;
9+
import org.mvplugins.multiverse.core.config.CoreConfig;
910
import org.mvplugins.multiverse.core.utils.StringFormatter;
1011
import org.mvplugins.multiverse.core.world.MultiverseWorld;
1112

@@ -14,15 +15,21 @@
1415

1516
public final class EntitySpawnConfig {
1617

18+
private final CoreConfig config;
1719
private final Map<SpawnCategory, SpawnCategoryConfig> spawnCategoriesConfig;
1820

19-
EntitySpawnConfig(Map<SpawnCategory, SpawnCategoryConfig> spawnCategoriesConfig) {
21+
EntitySpawnConfig(CoreConfig config, Map<SpawnCategory, SpawnCategoryConfig> spawnCategoriesConfig) {
22+
this.config = config;
2023
this.spawnCategoriesConfig = spawnCategoriesConfig;
2124
}
2225

2326
public SpawnCategoryConfig getSpawnCategoryConfig(SpawnCategory spawnCategory) {
2427
return spawnCategoriesConfig.computeIfAbsent(spawnCategory,
25-
computeSpawnCategory -> new SpawnCategoryConfig(computeSpawnCategory, new MemoryConfiguration()));
28+
computeSpawnCategory -> new SpawnCategoryConfig(
29+
config,
30+
computeSpawnCategory,
31+
new MemoryConfiguration()
32+
));
2633
}
2734

2835
public boolean shouldAllowSpawn(Entity entity) {
@@ -51,17 +58,17 @@ public ConfigurationSection toSection() {
5158
}
5259

5360
@ApiStatus.Internal
54-
public static EntitySpawnConfig fromSection(ConfigurationSection section) {
61+
public static EntitySpawnConfig fromSection(CoreConfig config, ConfigurationSection section) {
5562
Map<SpawnCategory, SpawnCategoryConfig> spawnCategoriesConfig = new LinkedHashMap<>();
5663
section.getValues(false).forEach((key, value) -> {
5764
if (!(value instanceof ConfigurationSection sectionPart)) {
5865
Logging.warning("Invalid spawn category config for " + key + ": " + value);
5966
return;
6067
}
6168
SpawnCategory spawnCategory = SpawnCategory.valueOf(key.toUpperCase());
62-
spawnCategoriesConfig.put(spawnCategory, new SpawnCategoryConfig(spawnCategory, sectionPart));
69+
spawnCategoriesConfig.put(spawnCategory, new SpawnCategoryConfig(config, spawnCategory, sectionPart));
6370
});
64-
return new EntitySpawnConfig(spawnCategoriesConfig);
71+
return new EntitySpawnConfig(config, spawnCategoriesConfig);
6572
}
6673

6774
@ApiStatus.Internal

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +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;
10+
import org.mvplugins.multiverse.core.config.CoreConfig;
1111
import org.mvplugins.multiverse.core.config.handle.MemoryConfigurationHandle;
1212
import org.mvplugins.multiverse.core.config.handle.StringPropertyHandle;
1313
import org.mvplugins.multiverse.core.config.node.ConfigNode;
@@ -22,14 +22,16 @@
2222

2323
public final class SpawnCategoryConfig {
2424

25+
private final CoreConfig config;
2526
private final SpawnCategory spawnCategory;
2627
private final MemoryConfigurationHandle handle;
2728
private final StringPropertyHandle stringPropertyHandle;
2829
private final Nodes nodes;
2930

3031
private MultiverseWorld world;
3132

32-
SpawnCategoryConfig(SpawnCategory spawnCategory, ConfigurationSection section) {
33+
SpawnCategoryConfig(CoreConfig config, SpawnCategory spawnCategory, ConfigurationSection section) {
34+
this.config = config;
3335
this.spawnCategory = spawnCategory;
3436
this.nodes = new Nodes();
3537
this.handle = MemoryConfigurationHandle.builder(section, nodes.nodes)
@@ -64,7 +66,7 @@ void applyConfigToWorld() {
6466
}
6567

6668
private void applyTickPerSpawns(World bukkitWorld) {
67-
if (!MultiverseCoreApi.get().getCoreConfig().getApplyEntitySpawnLimit()) {
69+
if (!config.getApplyEntitySpawnLimit()) {
6870
Logging.finer("World %s %s skipping setTicksPerSpawns due to core config", world.getName(), spawnCategory);
6971
return;
7072
}
@@ -83,7 +85,7 @@ private void applyTickPerSpawns(World bukkitWorld) {
8385
}
8486

8587
private void applySpawnLimit(World bukkitWorld) {
86-
if (!MultiverseCoreApi.get().getCoreConfig().getApplyEntitySpawnLimit()) {
88+
if (!config.getApplyEntitySpawnLimit()) {
8789
Logging.finer("Skipping World %s %s setSpawnLimit due to core config", world.getName(), spawnCategory);
8890
return;
8991
}

0 commit comments

Comments
 (0)