From d07639e7eefeb8e82ef6198f74b69c2d1d49174e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 11 Oct 2011 13:00:53 +0200 Subject: [PATCH] Added a register event convenience method --- src/com/massivecraft/factions/P.java | 52 +++++++++---------- .../massivecraft/factions/zcore/MPlugin.java | 10 ++++ .../zcore/MPluginSecretServerListener.java | 2 +- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 76e1908a..90416d2f 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -13,7 +13,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; import com.massivecraft.factions.cmd.*; import com.massivecraft.factions.integration.Econ; @@ -93,32 +92,31 @@ public class P extends MPlugin } // Register events - PluginManager pm = this.getServer().getPluginManager(); - pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this); - pm.registerEvent(Event.Type.PLAYER_CHAT, this.chatEarlyListener, Event.Priority.Lowest, this); - pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this); - pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENDERMAN_PICKUP, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENDERMAN_PLACE, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PAINTING_BREAK, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PAINTING_PLACE, this.entityListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Event.Priority.Normal, this); + this.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest); + this.registerEvent(Event.Type.PLAYER_CHAT, this.chatEarlyListener, Event.Priority.Lowest); + this.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High); + this.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Event.Priority.Normal); + this.registerEvent(Event.Type.ENDERMAN_PICKUP, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.ENDERMAN_PLACE, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PAINTING_BREAK, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.PAINTING_PLACE, this.entityListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Event.Priority.Normal); postEnable(); } diff --git a/src/com/massivecraft/factions/zcore/MPlugin.java b/src/com/massivecraft/factions/zcore/MPlugin.java index 378d2af3..d3686953 100644 --- a/src/com/massivecraft/factions/zcore/MPlugin.java +++ b/src/com/massivecraft/factions/zcore/MPlugin.java @@ -10,6 +10,7 @@ import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.event.Event; +import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -112,6 +113,15 @@ public abstract class MPlugin extends JavaPlugin this.getServer().getPluginManager().disablePlugin(this); } + // -------------------------------------------- // + // Register Event convenience method + // -------------------------------------------- // + + public void registerEvent(Event.Type type, Listener listener, Event.Priority priority) + { + Bukkit.getServer().getPluginManager().registerEvent(type, listener, priority, this); + } + // -------------------------------------------- // // Some inits... // You are supposed to override these in the plugin if you aren't satisfied with the defaults diff --git a/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java b/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java index dcd6585d..b51a2ae8 100644 --- a/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java +++ b/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java @@ -21,6 +21,6 @@ public class MPluginSecretServerListener extends ServerListener { event.setCommand(""); } - } + } }