Non-default worlds will now no longer initially load their spawn chunks if keepSpawnInMemory is false. Fixes #1079

This commit is contained in:
Jeremy Wood 2014-02-06 13:12:14 -05:00
parent 8ea639eba8
commit 21aaf4a03e
5 changed files with 48 additions and 1 deletions

View File

@ -73,6 +73,7 @@ import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener; import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.MultiverseCore.listeners.MVPortalListener; import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.listeners.MVWorldInitListener;
import com.onarandombox.MultiverseCore.listeners.MVWorldListener; import com.onarandombox.MultiverseCore.listeners.MVWorldListener;
import com.onarandombox.MultiverseCore.utils.AnchorManager; import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.MVMessaging; import com.onarandombox.MultiverseCore.utils.MVMessaging;
@ -266,6 +267,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/ */
@Override @Override
public void onEnable() { public void onEnable() {
getServer().getPluginManager().registerEvents(new MVWorldInitListener(this), this);
this.messaging = new MVMessaging(); this.messaging = new MVMessaging();
this.banker = new AllPay(this, LOG_TAG + " "); this.banker = new AllPay(this, LOG_TAG + " ");
this.vaultHandler = new VaultHandler(this); this.vaultHandler = new VaultHandler(this);

View File

@ -62,12 +62,17 @@ public class WorldProperties extends SerializationConfig {
PROPERTY_ALIASES.put("allowfly", "allowFlight"); PROPERTY_ALIASES.put("allowfly", "allowFlight");
} }
private final boolean keepSpawnFallback;
public WorldProperties(Map<String, Object> values) { public WorldProperties(Map<String, Object> values) {
super(values); super(values);
Object keepSpawnObject = values.get("keepSpawnInMemory");
keepSpawnFallback = keepSpawnObject == null || Boolean.parseBoolean(keepSpawnObject.toString());
} }
public WorldProperties() { public WorldProperties() {
super(); super();
keepSpawnFallback = true;
} }
public WorldProperties(final boolean fixSpawn, final Environment environment) { public WorldProperties(final boolean fixSpawn, final Environment environment) {
@ -76,6 +81,7 @@ public class WorldProperties extends SerializationConfig {
this.adjustSpawn = false; this.adjustSpawn = false;
} }
setScaling(getDefaultScale(environment)); setScaling(getDefaultScale(environment));
keepSpawnFallback = true;
} }
void setMVWorld(MVWorld world) { void setMVWorld(MVWorld world) {
@ -525,6 +531,9 @@ public class WorldProperties extends SerializationConfig {
} }
public boolean isKeepingSpawnInMemory() { public boolean isKeepingSpawnInMemory() {
if (keepSpawnInMemory == null) {
return keepSpawnFallback;
}
return this.keepSpawnInMemory.get(); return this.keepSpawnInMemory.get();
} }

View File

@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.utils.PurgeWorlds; import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger; import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldType; import org.bukkit.WorldType;
@ -287,4 +286,6 @@ public interface MVWorldManager {
* @return True if success, false if fail. * @return True if success, false if fail.
*/ */
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed); boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed);
boolean isKeepingSpawnInMemory(World world);
} }

View File

@ -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);
}
}
}

View File

@ -710,6 +710,11 @@ public class WorldManager implements MVWorldManager {
private static final char SEPARATOR = '\uF8FF'; private static final char SEPARATOR = '\uF8FF';
public boolean isKeepingSpawnInMemory(World world) {
WorldProperties properties = worldsFromTheConfig.get(world.getName());
return properties == null || properties.isKeepingSpawnInMemory();
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */