- Moved Bukkit event registration from WorldEditPlugin into the respective listeners.

- Changed registerEvent to the string-based system WorldGuard has, which should improve compatibility with differing Bukkit versions.
This commit is contained in:
TomyLobo 2011-08-21 23:05:03 +02:00
parent d12bff993b
commit 9de9004834
3 changed files with 23 additions and 12 deletions

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
@ -39,6 +40,8 @@ public class WorldEditCriticalPlayerListener extends PlayerListener {
*/ */
public WorldEditCriticalPlayerListener(WorldEditPlugin plugin) { public WorldEditCriticalPlayerListener(WorldEditPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
plugin.registerEvent("PLAYER_JOIN", this, Priority.Lowest);
} }
/** /**

View File

@ -51,6 +51,10 @@ public class WorldEditPlayerListener extends PlayerListener {
*/ */
public WorldEditPlayerListener(WorldEditPlugin plugin) { public WorldEditPlayerListener(WorldEditPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
plugin.registerEvent("PLAYER_QUIT", this);
plugin.registerEvent("PLAYER_INTERACT", this);
plugin.registerEvent("PLAYER_COMMAND_PREPROCESS", this);
} }
/** /**

View File

@ -32,6 +32,7 @@ import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.bukkit.migration.PermissionsResolverManager; import com.sk89q.bukkit.migration.PermissionsResolverManager;
import com.sk89q.bukkit.migration.PermissionsResolverServerListener; import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
@ -135,14 +136,11 @@ public class WorldEditPlugin extends JavaPlugin {
* Register the events used by WorldEdit. * Register the events used by WorldEdit.
*/ */
protected void registerEvents() { protected void registerEvents() {
@SuppressWarnings("unused")
PlayerListener playerListener = new WorldEditPlayerListener(this); PlayerListener playerListener = new WorldEditPlayerListener(this);
@SuppressWarnings("unused")
PlayerListener criticalPlayerListener = new WorldEditCriticalPlayerListener(this); PlayerListener criticalPlayerListener = new WorldEditCriticalPlayerListener(this);
registerEvent(Event.Type.PLAYER_QUIT, playerListener);
registerEvent(Event.Type.PLAYER_INTERACT, playerListener);
registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener);
registerEvent(Event.Type.PLAYER_JOIN, criticalPlayerListener, Priority.Lowest);
// The permissions resolver has some hooks of its own // The permissions resolver has some hooks of its own
(new PermissionsResolverServerListener(perms)).register(this); (new PermissionsResolverServerListener(perms)).register(this);
} }
@ -154,9 +152,16 @@ public class WorldEditPlugin extends JavaPlugin {
* @param listener * @param listener
* @param priority * @param priority
*/ */
protected void registerEvent(Event.Type type, Listener listener, Priority priority) { protected void registerEvent(String typeName, Listener listener, Priority priority) {
getServer().getPluginManager() try {
.registerEvent(type, listener, priority, this); Event.Type type = Event.Type.valueOf(typeName);
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(type, listener, priority, this);
} catch (IllegalArgumentException e) {
logger.info("WorldGuard: Unable to register missing event type " + typeName);
}
/*getServer().getPluginManager()
.registerEvent(type, listener, priority, this);*/
} }
/** /**
@ -165,9 +170,8 @@ public class WorldEditPlugin extends JavaPlugin {
* @param type * @param type
* @param listener * @param listener
*/ */
protected void registerEvent(Event.Type type, Listener listener) { protected void registerEvent(String typeName, Listener listener) {
getServer().getPluginManager() registerEvent(typeName, listener, Event.Priority.Normal);
.registerEvent(type, listener, Priority.Normal, this);
} }
/** /**