From 589d197bf12b0a165b88f5b3408fe45f89615f7e Mon Sep 17 00:00:00 2001 From: taoneill Date: Sat, 7 Jan 2012 00:36:29 -0500 Subject: [PATCH] Server reload isn't broken anymore: now removing Spout widgets at Spout plugin disable-time, since Spout was already gone by the time War was getting disabled and tried to remove them. --- .../main/java/bukkit/tommytony/war/War.java | 13 +++------ .../tommytony/war/WarServerListener.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 war/src/main/java/bukkit/tommytony/war/WarServerListener.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index acb7b7b..f43bd25 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -61,6 +61,8 @@ public class War extends JavaPlugin { private WarPlayerListener playerListener = new WarPlayerListener(); private WarEntityListener entityListener = new WarEntityListener(); private WarBlockListener blockListener = new WarBlockListener(); + private WarServerListener pluginListener = new WarServerListener(); + private WarCommandHandler commandHandler = new WarCommandHandler(); private Logger logger; private PluginDescriptionFile desc = null; @@ -158,6 +160,8 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Normal, this); + if (this.isSpoutServer()) { pm.registerEvent(Event.Type.CUSTOM_EVENT, new WarSpoutListener(this), Priority.Low, this); } @@ -265,15 +269,6 @@ public class War extends JavaPlugin { * Cleans up war */ public void unloadWar() { - if (this.isSpoutServer()) { - for (Player player : getServer().getOnlinePlayers()) { - SpoutPlayer sp = (SpoutPlayer) player; - if (sp.isSpoutCraftEnabled()) { - sp.getMainScreen().removeWidgets(this); - } - } - } - for (Warzone warzone : this.warzones) { warzone.unload(); } diff --git a/war/src/main/java/bukkit/tommytony/war/WarServerListener.java b/war/src/main/java/bukkit/tommytony/war/WarServerListener.java new file mode 100644 index 0000000..07b8e07 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/WarServerListener.java @@ -0,0 +1,27 @@ +package bukkit.tommytony.war; + +import org.bukkit.entity.Player; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.ServerListener; +import org.bukkit.plugin.java.JavaPlugin; +import org.getspout.spoutapi.player.SpoutPlayer; + +public class WarServerListener extends ServerListener { + + public void onPluginDisable(PluginDisableEvent event) { + if (event.getPlugin() instanceof JavaPlugin) { + JavaPlugin plugin = (JavaPlugin)event.getPlugin(); + + if (plugin.getDataFolder().getName().equals("Spout")) { + if (War.war.isSpoutServer()) { + for (Player player : War.war.getServer().getOnlinePlayers()) { + SpoutPlayer sp = (SpoutPlayer) player; + if (sp.isSpoutCraftEnabled()) { + sp.getMainScreen().removeWidgets(War.war); + } + } + } + } + } + } +}