- 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.
Dieser Commit ist enthalten in:
TomyLobo 2011-08-21 23:05:03 +02:00
Ursprung d12bff993b
Commit 9de9004834
3 geänderte Dateien mit 23 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
@ -39,6 +40,8 @@ public class WorldEditCriticalPlayerListener extends PlayerListener {
*/
public WorldEditCriticalPlayerListener(WorldEditPlugin plugin) {
this.plugin = plugin;
plugin.registerEvent("PLAYER_JOIN", this, Priority.Lowest);
}
/**
@ -50,7 +53,7 @@ public class WorldEditCriticalPlayerListener extends PlayerListener {
public void onPlayerJoin(PlayerJoinEvent event) {
wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
}
private BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(plugin, plugin.getServerInterface(), player);
}

Datei anzeigen

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

Datei anzeigen

@ -32,6 +32,7 @@ import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.bukkit.migration.PermissionsResolverManager;
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
@ -135,14 +136,11 @@ public class WorldEditPlugin extends JavaPlugin {
* Register the events used by WorldEdit.
*/
protected void registerEvents() {
@SuppressWarnings("unused")
PlayerListener playerListener = new WorldEditPlayerListener(this);
@SuppressWarnings("unused")
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
(new PermissionsResolverServerListener(perms)).register(this);
}
@ -154,9 +152,16 @@ public class WorldEditPlugin extends JavaPlugin {
* @param listener
* @param priority
*/
protected void registerEvent(Event.Type type, Listener listener, Priority priority) {
getServer().getPluginManager()
.registerEvent(type, listener, priority, this);
protected void registerEvent(String typeName, Listener listener, Priority priority) {
try {
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 listener
*/
protected void registerEvent(Event.Type type, Listener listener) {
getServer().getPluginManager()
.registerEvent(type, listener, Priority.Normal, this);
protected void registerEvent(String typeName, Listener listener) {
registerEvent(typeName, listener, Event.Priority.Normal);
}
/**