Skip to content

Commit 064e4a0

Browse files
authored
Merge pull request #3207 from Multiverse/fix/purge-entities
Actually implement the auto-purge-entities config option
2 parents 65d199c + e417e04 commit 064e4a0

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private <N extends Node> N node(N node) {
108108

109109
final ConfigNode<Boolean> autoPurgeEntities = node(ConfigNode.builder("world.auto-purge-entities", Boolean.class)
110110
.comment("")
111-
.comment("Sets whether Multiverse will purge mobs and entities automatically.")
111+
.comment("Sets whether Multiverse will purge entities on world load based world's entity spawn config.")
112112
.defaultValue(false)
113113
.name("auto-purge-entities")
114114
.build());

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.mvplugins.multiverse.core.config.CoreConfig;
1616
import org.mvplugins.multiverse.core.teleportation.BlockSafety;
1717
import org.mvplugins.multiverse.core.teleportation.LocationManipulation;
18+
import org.mvplugins.multiverse.core.world.entity.EntityPurger;
1819
import org.mvplugins.multiverse.core.world.location.NullSpawnLocation;
1920
import org.mvplugins.multiverse.core.world.location.SpawnLocation;
2021

@@ -27,20 +28,25 @@ public final class LoadedMultiverseWorld extends MultiverseWorld {
2728

2829
private final BlockSafety blockSafety;
2930
private final LocationManipulation locationManipulation;
31+
private final EntityPurger entityPurger;
3032

3133
LoadedMultiverseWorld(
3234
@NotNull World world,
3335
@NotNull WorldConfig worldConfig,
36+
@NotNull CoreConfig config,
3437
@NotNull BlockSafety blockSafety,
3538
@NotNull LocationManipulation locationManipulation,
36-
@NotNull CoreConfig config) {
39+
@NotNull EntityPurger entityPurger
40+
) {
3741
super(world.getName(), worldConfig, config);
3842
this.worldUid = world.getUID();
3943
this.blockSafety = blockSafety;
4044
this.locationManipulation = locationManipulation;
45+
this.entityPurger = entityPurger;
4146

4247
setupWorldConfig(world);
4348
setupSpawnLocation(world);
49+
purgeEntitiesOnLoad();
4450
}
4551

4652
private void setupWorldConfig(World world) {
@@ -101,6 +107,12 @@ private Location readSpawnFromWorld(World world) {
101107
return location;
102108
}
103109

110+
private void purgeEntitiesOnLoad() {
111+
if (config.isAutoPurgeEntities()) {
112+
entityPurger.purgeEntities(this);
113+
}
114+
}
115+
104116
/**
105117
* Gets the Unique ID of this world.
106118
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public sealed class MultiverseWorld permits LoadedMultiverseWorld {
3333
*/
3434
WorldConfig worldConfig;
3535

36-
private final CoreConfig config;
36+
protected final CoreConfig config;
3737
private String colourlessAlias = "";
3838

3939
MultiverseWorld(String worldName, WorldConfig worldConfig, CoreConfig config) {

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.mvplugins.multiverse.core.utils.result.FailureReason;
4949
import org.mvplugins.multiverse.core.utils.FileUtils;
5050
import org.mvplugins.multiverse.core.world.biomeprovider.BiomeProviderFactory;
51+
import org.mvplugins.multiverse.core.world.entity.EntityPurger;
5152
import org.mvplugins.multiverse.core.world.generators.GeneratorProvider;
5253
import org.mvplugins.multiverse.core.world.helpers.DataStore.GameRulesStore;
5354
import org.mvplugins.multiverse.core.world.helpers.DataTransfer;
@@ -91,8 +92,8 @@ public final class WorldManager {
9192
private final PluginManager pluginManager;
9293
private final CorePermissions corePermissions;
9394
private final ServerProperties serverProperties;
94-
@NotNull
9595
private final CoreConfig config;
96+
private final EntityPurger entityPurger;
9697

9798
@Inject
9899
WorldManager(
@@ -106,7 +107,8 @@ public final class WorldManager {
106107
@NotNull PluginManager pluginManager,
107108
@NotNull CorePermissions corePermissions,
108109
@NotNull ServerProperties serverProperties,
109-
@NotNull CoreConfig config) {
110+
@NotNull CoreConfig config,
111+
@NotNull EntityPurger entityPurger) {
110112
this.worldsConfigManager = worldsConfigManager;
111113
this.worldNameChecker = worldNameChecker;
112114
this.biomeProviderFactory = biomeProviderFactory;
@@ -118,6 +120,7 @@ public final class WorldManager {
118120
this.corePermissions = corePermissions;
119121
this.serverProperties = serverProperties;
120122
this.config = config;
123+
this.entityPurger = entityPurger;
121124

122125
this.worldsMap = new HashMap<>();
123126
this.loadedWorldsMap = new HashMap<>();
@@ -312,9 +315,11 @@ private LoadedMultiverseWorld newLoadedMultiverseWorld(
312315
LoadedMultiverseWorld loadedWorld = new LoadedMultiverseWorld(
313316
world,
314317
worldConfig,
318+
config,
315319
blockSafety,
316320
locationManipulation,
317-
config);
321+
entityPurger
322+
);
318323
setDefaultEnvironmentScale(mvWorld);
319324
loadedWorldsMap.put(loadedWorld.getName(), loadedWorld);
320325
saveWorldsConfig();
@@ -390,9 +395,11 @@ private Attempt<LoadedMultiverseWorld, LoadFailureReason> newLoadedMultiverseWor
390395
LoadedMultiverseWorld loadedWorld = new LoadedMultiverseWorld(
391396
bukkitWorld,
392397
worldConfig,
398+
config,
393399
blockSafety,
394400
locationManipulation,
395-
config);
401+
entityPurger
402+
);
396403
loadedWorldsMap.put(loadedWorld.getName(), loadedWorld);
397404
saveWorldsConfig();
398405
pluginManager.callEvent(new MVWorldLoadedEvent(loadedWorld));

0 commit comments

Comments
 (0)