From 8fcd24da2c13926ec8d1589b70f151a02ef811ea Mon Sep 17 00:00:00 2001 From: taoneill Date: Sun, 7 Aug 2011 17:37:55 -0400 Subject: [PATCH] Fixed load/unload re-registering listeners. This is War v1.6 PREVIEW 3. --- .../main/java/bukkit/tommytony/war/War.java | 52 +++++++++++-------- .../tommytony/war/command/LoadWarCommand.java | 3 +- .../war/command/UnloadWarCommand.java | 2 +- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index a9a2062..9c923ff 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -38,6 +38,7 @@ import com.tommytony.war.utils.*; public class War extends JavaPlugin { public static PermissionHandler permissionHandler; public static War war; + private static boolean loadedOnce = false; // general private WarPlayerListener playerListener = new WarPlayerListener(); @@ -88,7 +89,6 @@ public class War extends JavaPlugin { * @see War.loadWar() */ public void onEnable() { - War.war = this; this.loadWar(); } @@ -109,27 +109,31 @@ public class War extends JavaPlugin { this.logger = this.getServer().getLogger(); this.setupPermissions(); - // Register hooks - PluginManager pm = this.getServer().getPluginManager(); - pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.INVENTORY_OPEN, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Priority.Normal, this); - - pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.High, this); - pm.registerEvent(Event.Type.ENTITY_COMBUST, this.entityListener, Priority.Normal, this); - pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); - - pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this); - - + if(!loadedOnce) { + loadedOnce = true; // This prevented multiple hookups of the same listener + + // Register hooks + PluginManager pm = this.getServer().getPluginManager(); + + pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.INVENTORY_OPEN, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Priority.Normal, this); + + pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.High, this); + pm.registerEvent(Event.Type.ENTITY_COMBUST, this.entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); + + pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this); + } + // Load files from disk or create them (using these defaults) this.getDefaultLoadout().put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8)); this.getDefaultLoadout().put(1, new ItemStack(Material.BOW, 1, (byte) 8)); @@ -137,7 +141,7 @@ public class War extends JavaPlugin { this.getDefaultLoadout().put(3, new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8)); this.getDefaultLoadout().put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8)); this.getDefaultReward().put( 0, new ItemStack(Material.CAKE, 1)); - + WarMapper.load(); this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO); } @@ -150,6 +154,8 @@ public class War extends JavaPlugin { warzone.unload(); } this.warzones.clear(); + + PluginManager pm = this.getServer().getPluginManager(); if (this.warHub != null) { this.warHub.getVolume().resetBlocks(); diff --git a/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java index 3dd674f..655bc86 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java @@ -15,8 +15,9 @@ public class LoadWarCommand extends AbstractZoneMakerCommand { if (this.args.length != 0) { return false; } + War.war.loadWar(); - + this.msg("War loaded."); return true; } } diff --git a/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java index 5d1b735..7d4e3ba 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java @@ -17,7 +17,7 @@ public class UnloadWarCommand extends AbstractZoneMakerCommand { } War.war.unloadWar(); - + this.msg("War unloaded."); return true; } }