Register events

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-26 00:38:11 +00:00
parent acc9067060
commit 42ef5c31b7
2 changed files with 40 additions and 0 deletions

View File

@ -2,7 +2,9 @@
package org.bukkit.plugin;
import java.io.File;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener;
/**
* Handles all plugin management from the Server
@ -71,4 +73,14 @@ public interface PluginManager {
* @param event Event details
*/
public void callEvent(PlayerEvent.EventType type, PlayerEvent event);
/**
* Registers the given player event to the specified listener
*
* @param type EventType to register
* @param listener PlayerListener to register
* @param priority Priority of this event
* @param plugin Plugin to register
*/
public void registerEvent(PlayerEvent.EventType type, PlayerListener listener, Priority priority, Plugin plugin);
}

View File

@ -14,7 +14,10 @@ import java.util.logging.Logger;
import java.util.regex.Matcher;
import org.bukkit.Server;
import java.util.regex.Pattern;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener;
/**
* Handles all plugin management from the Server
@ -178,4 +181,29 @@ public final class SimplePluginManager implements PluginManager {
}
}
}
/**
* Registers the given player event to the specified listener
*
* @param type EventType to register
* @param listener PlayerListener to register
* @param priority Priority of this event
* @param plugin Plugin to register
*/
public void registerEvent(PlayerEvent.EventType type, PlayerListener listener, Priority priority, Plugin plugin) {
List<RegisteredListener> listeners = playerListeners.get(type);
int position = 0;
if (listeners != null) {
for (RegisteredListener registration : listeners) {
if (registration.getPriority().compareTo(priority) < 0) {
break;
}
position++;
}
}
listeners.add(position, new RegisteredListener(listener, priority, plugin));
}
}