@@ -3,7 +3,8 @@ package org.bukkit.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* Represents a plugin loader, which handles direct access to specific types
|
||||
@@ -32,5 +33,5 @@ public interface PluginLoader {
|
||||
* @param type Type of player related event to call
|
||||
* @param event Event details
|
||||
*/
|
||||
public void callEvent(RegisteredListener registration, PlayerEvent.EventType type, PlayerEvent event);
|
||||
public void callEvent(RegisteredListener registration, Event event);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
package org.bukkit.plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all plugin management from the Server
|
||||
@@ -72,15 +73,15 @@ public interface PluginManager {
|
||||
* @param type Type of player related event to call
|
||||
* @param event Event details
|
||||
*/
|
||||
public void callEvent(PlayerEvent.EventType type, PlayerEvent event);
|
||||
public void callEvent(Event event);
|
||||
|
||||
/**
|
||||
* Registers the given player event to the specified listener
|
||||
*
|
||||
* @param type EventType to register
|
||||
* @param listener PlayerListener to register
|
||||
* @param listener Listener 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);
|
||||
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin);
|
||||
}
|
||||
|
||||
@@ -14,9 +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;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all plugin management from the Server
|
||||
@@ -26,7 +27,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||
private final Map<Pattern, PluginLoader> fileAssociations = new HashMap<Pattern, PluginLoader>();
|
||||
private final List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
private final Map<String, Plugin> lookupNames = new HashMap<String, Plugin>();
|
||||
private final Map<PlayerEvent.EventType, List<RegisteredListener>> playerListeners = new EnumMap<PlayerEvent.EventType, List<RegisteredListener>>(PlayerEvent.EventType.class);
|
||||
private final Map<Event.Type, List<RegisteredListener>> listeners = new EnumMap<Event.Type, List<RegisteredListener>>(Event.Type.class);
|
||||
|
||||
public SimplePluginManager(Server instance) {
|
||||
server = instance;
|
||||
@@ -166,16 +167,16 @@ public final class SimplePluginManager implements PluginManager {
|
||||
* @param type Type of player related event to call
|
||||
* @param event Event details
|
||||
*/
|
||||
public void callEvent(PlayerEvent.EventType type, PlayerEvent event) {
|
||||
List<RegisteredListener> listeners = playerListeners.get(type);
|
||||
public void callEvent(Event event) {
|
||||
List<RegisteredListener> eventListeners = listeners.get(event.getType());
|
||||
|
||||
if (listeners != null) {
|
||||
for (RegisteredListener registration : listeners) {
|
||||
for (RegisteredListener registration : eventListeners) {
|
||||
Plugin plugin = registration.getPlugin();
|
||||
PluginLoader loader = plugin.getPluginLoader();
|
||||
|
||||
if (plugin.isEnabled()) {
|
||||
loader.callEvent(registration, type, event);
|
||||
loader.callEvent(registration, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,12 +190,12 @@ public final class SimplePluginManager implements PluginManager {
|
||||
* @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);
|
||||
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin) {
|
||||
List<RegisteredListener> eventListeners = listeners.get(type);
|
||||
int position = 0;
|
||||
|
||||
if (listeners != null) {
|
||||
for (RegisteredListener registration : listeners) {
|
||||
for (RegisteredListener registration : eventListeners) {
|
||||
if (registration.getPriority().compareTo(priority) < 0) {
|
||||
break;
|
||||
}
|
||||
@@ -202,10 +203,10 @@ public final class SimplePluginManager implements PluginManager {
|
||||
position++;
|
||||
}
|
||||
} else {
|
||||
listeners = new ArrayList<RegisteredListener>();
|
||||
playerListeners.put(type, listeners);
|
||||
eventListeners = new ArrayList<RegisteredListener>();
|
||||
listeners.put(type, eventListeners);
|
||||
}
|
||||
|
||||
listeners.add(position, new RegisteredListener(listener, priority, plugin));
|
||||
eventListeners.add(position, new RegisteredListener(listener, priority, plugin));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.plugin.*;
|
||||
@@ -74,17 +75,17 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||
return fileFilters;
|
||||
}
|
||||
|
||||
public void callEvent(RegisteredListener registration, PlayerEvent.EventType type, PlayerEvent event) {
|
||||
public void callEvent(RegisteredListener registration, Event event) {
|
||||
Listener listener = registration.getListener();
|
||||
|
||||
if (listener instanceof PlayerListener) {
|
||||
PlayerListener trueListener = (PlayerListener)listener;
|
||||
|
||||
switch (type) {
|
||||
case Join:
|
||||
switch (event.getType()) {
|
||||
case JOIN:
|
||||
trueListener.onPlayerJoin((PlayerEvent)event);
|
||||
break;
|
||||
case Quit:
|
||||
case QUIT:
|
||||
trueListener.onPlayerQuit((PlayerEvent)event);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user