From 21aaf4a03ed6aa3849db57d3c61188a9954291c2 Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Thu, 6 Feb 2014 13:12:14 -0500 Subject: [PATCH] Non-default worlds will now no longer initially load their spawn chunks if keepSpawnInMemory is false. Fixes #1079 --- .../MultiverseCore/MultiverseCore.java | 3 ++ .../MultiverseCore/WorldProperties.java | 9 ++++++ .../MultiverseCore/api/MVWorldManager.java | 3 +- .../listeners/MVWorldInitListener.java | 29 +++++++++++++++++++ .../MultiverseCore/utils/WorldManager.java | 5 ++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldInitListener.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 185a1467..f902ff8e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -73,6 +73,7 @@ import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPluginListener; import com.onarandombox.MultiverseCore.listeners.MVPortalListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; +import com.onarandombox.MultiverseCore.listeners.MVWorldInitListener; import com.onarandombox.MultiverseCore.listeners.MVWorldListener; import com.onarandombox.MultiverseCore.utils.AnchorManager; import com.onarandombox.MultiverseCore.utils.MVMessaging; @@ -266,6 +267,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { */ @Override public void onEnable() { + getServer().getPluginManager().registerEvents(new MVWorldInitListener(this), this); + this.messaging = new MVMessaging(); this.banker = new AllPay(this, LOG_TAG + " "); this.vaultHandler = new VaultHandler(this); diff --git a/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java b/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java index 542e47e2..54f4f02a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java +++ b/src/main/java/com/onarandombox/MultiverseCore/WorldProperties.java @@ -62,12 +62,17 @@ public class WorldProperties extends SerializationConfig { PROPERTY_ALIASES.put("allowfly", "allowFlight"); } + private final boolean keepSpawnFallback; + public WorldProperties(Map values) { super(values); + Object keepSpawnObject = values.get("keepSpawnInMemory"); + keepSpawnFallback = keepSpawnObject == null || Boolean.parseBoolean(keepSpawnObject.toString()); } public WorldProperties() { super(); + keepSpawnFallback = true; } public WorldProperties(final boolean fixSpawn, final Environment environment) { @@ -76,6 +81,7 @@ public class WorldProperties extends SerializationConfig { this.adjustSpawn = false; } setScaling(getDefaultScale(environment)); + keepSpawnFallback = true; } void setMVWorld(MVWorld world) { @@ -525,6 +531,9 @@ public class WorldProperties extends SerializationConfig { } public boolean isKeepingSpawnInMemory() { + if (keepSpawnInMemory == null) { + return keepSpawnFallback; + } return this.keepSpawnInMemory.get(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index 8e83db7a..56cb8e9e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.api; import com.onarandombox.MultiverseCore.utils.PurgeWorlds; import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger; - import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldType; @@ -287,4 +286,6 @@ public interface MVWorldManager { * @return True if success, false if fail. */ boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed); + + boolean isKeepingSpawnInMemory(World world); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldInitListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldInitListener.java new file mode 100644 index 00000000..cc12a10e --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldInitListener.java @@ -0,0 +1,29 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + +package com.onarandombox.MultiverseCore.listeners; + +import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldInitEvent; + +public class MVWorldInitListener implements Listener { + + MultiverseCore plugin; + + public MVWorldInitListener(MultiverseCore plugin) { + this.plugin = plugin; + } + + @EventHandler + public void initWorld(WorldInitEvent event) { + if (!plugin.getMVWorldManager().isKeepingSpawnInMemory(event.getWorld())) { + event.getWorld().setKeepSpawnInMemory(false); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index ce246b25..68d7c785 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -710,6 +710,11 @@ public class WorldManager implements MVWorldManager { private static final char SEPARATOR = '\uF8FF'; + public boolean isKeepingSpawnInMemory(World world) { + WorldProperties properties = worldsFromTheConfig.get(world.getName()); + return properties == null || properties.isKeepingSpawnInMemory(); + } + /** * {@inheritDoc} */