From 68608169cd75cb5df86f087abd2ba1ff32b9c3ae Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 7 Jun 2011 02:54:14 -0400 Subject: [PATCH] Implemented unloadWorld(). Thanks Rigby! --- .../org/bukkit/craftbukkit/CraftServer.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 7696462131..77e2d836b2 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -10,6 +10,8 @@ import org.bukkit.World.Environment; import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldSaveEvent; +import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.inventory.FurnaceRecipe; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; @@ -30,6 +32,7 @@ import net.minecraft.server.ConvertProgressUpdater; import net.minecraft.server.Convertable; import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityTracker; +import net.minecraft.server.IProgressUpdate; import net.minecraft.server.MinecraftServer; import net.minecraft.server.PropertyManager; import net.minecraft.server.ServerConfigurationManager; @@ -423,6 +426,48 @@ public final class CraftServer implements Server { return internal.getWorld(); } + public boolean unloadWorld(String name, boolean save) { + return unloadWorld(getWorld(name), save); + } + + public boolean unloadWorld(World world, boolean save) { + if (world == null) { + return false; + } + + WorldServer handle = ((CraftWorld) world).getHandle(); + + if (!(console.worlds.contains(handle))) { + return false; + } + + if (!(handle.dimension > 1)) { + return false; + } + + if (handle.players.size() > 0) { + return false; + } + + WorldUnloadEvent e = new WorldUnloadEvent(handle.getWorld()); + + if (e.isCancelled()) { + return false; + } + + if (save) { + handle.save(true, (IProgressUpdate) null); + handle.saveLevel(); + WorldSaveEvent event = new WorldSaveEvent(handle.getWorld()); + getPluginManager().callEvent(event); + } + + worlds.remove(world.getName().toLowerCase()); + console.worlds.remove(console.worlds.indexOf(handle)); + + return true; + } + public MinecraftServer getServer() { return console; }