mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 03:48:01 +01:00
Register events
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
acc9067060
commit
42ef5c31b7
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user