mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-20 23:31:23 +01:00
Merge pull request #1205 from bloodmc/master
Added World Load/Unload Event listeners to support Forge in MCPC.
This commit is contained in:
commit
e69b5a6b17
@ -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.MVWorldListener;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
@ -204,6 +205,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private final MVPluginListener pluginListener = new MVPluginListener(this);
|
||||
private final MVWeatherListener weatherListener = new MVWeatherListener(this);
|
||||
private final MVPortalListener portalListener = new MVPortalListener(this);
|
||||
private final MVWorldListener worldListener = new MVWorldListener(this);
|
||||
private MVChatListener chatListener;
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
@ -459,6 +461,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
pm.registerEvents(this.pluginListener, this);
|
||||
pm.registerEvents(this.weatherListener, this);
|
||||
pm.registerEvents(this.portalListener, this);
|
||||
pm.registerEvents(this.worldListener, this);
|
||||
pm.registerEvents(new MVMapListener(this), this);
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,15 @@ public interface MVWorldManager {
|
||||
*/
|
||||
boolean unloadWorld(String name);
|
||||
|
||||
/**
|
||||
* Unload a world from Multiverse with option to prevent calling unloadWorld in Bukkit.
|
||||
*
|
||||
* @param name Name of the world to unload
|
||||
* @param unloadBukkit True if Bukkit world should be unloaded
|
||||
* @return True if the world was unloaded, false if not.
|
||||
*/
|
||||
boolean unloadWorld(String name, boolean unloadBukkit);
|
||||
|
||||
/**
|
||||
* Loads the world. Only use this if the world has been
|
||||
* unloaded with {@link #unloadWorld(String)}.
|
||||
|
@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* 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 com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
|
||||
/**
|
||||
* Multiverse's World {@link Listener}.
|
||||
*/
|
||||
public class MVWorldListener implements Listener {
|
||||
private MultiverseCore plugin;
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public MVWorldListener(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.worldManager = plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when Bukkit fires off a WorldUnloadEvent.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void unloadWorld(WorldUnloadEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (event.getWorld() instanceof World) {
|
||||
World world = (World) event.getWorld();
|
||||
if (world != null) {
|
||||
this.plugin.getMVWorldManager().unloadWorld(world.getName(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when Bukkit fires off a WorldLoadEvent.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void loadWorld(WorldLoadEvent event) {
|
||||
if (event.getWorld() instanceof World) {
|
||||
World world = (World) event.getWorld();
|
||||
if (world != null && this.plugin.getMVWorldManager().getUnloadedWorlds().contains(world.getName())) {
|
||||
this.plugin.getMVWorldManager().loadWorld(world.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -316,9 +316,21 @@ public class WorldManager implements MVWorldManager {
|
||||
*/
|
||||
@Override
|
||||
public boolean unloadWorld(String name) {
|
||||
return this.unloadWorld(name, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean unloadWorld(String name, boolean unloadBukkit) {
|
||||
if (this.worlds.containsKey(name)) {
|
||||
this.worldsFromTheConfig.get(name).cacheVirtualProperties();
|
||||
if (this.unloadWorldFromBukkit(name, true)) {
|
||||
if (unloadBukkit && this.unloadWorldFromBukkit(name, true)) {
|
||||
this.worlds.remove(name);
|
||||
Logging.info("World '%s' was unloaded from memory.", name);
|
||||
return true;
|
||||
} else if (!unloadBukkit){
|
||||
this.worlds.remove(name);
|
||||
Logging.info("World '%s' was unloaded from memory.", name);
|
||||
return true;
|
||||
@ -397,7 +409,7 @@ public class WorldManager implements MVWorldManager {
|
||||
if (worlds.containsKey(worldName))
|
||||
throw new IllegalArgumentException("That world is already loaded!");
|
||||
|
||||
if (!ignoreExists && !new File(this.plugin.getServer().getWorldContainer(), worldName).exists()) {
|
||||
if (!ignoreExists && !new File(this.plugin.getServer().getWorldContainer(), worldName).exists() && !new File(this.plugin.getServer().getWorldContainer().getParent(), worldName).exists()) {
|
||||
this.plugin.log(Level.WARNING, "WorldManager: Can't load this world because the folder was deleted/moved: " + worldName);
|
||||
this.plugin.log(Level.WARNING, "Use '/mv remove' to remove it from the config!");
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user