geforkt von Mirrors/Paper
Event system optimizations. Addresses BUKKIT-813
- Made the handlers field a simple array instead of an array of arrays. - Got rid of the "baked" field. By: TomyLobo <tomylobo@nurfuerspam.de>
Dieser Commit ist enthalten in:
Ursprung
4c1a926d66
Commit
345f24b35c
@ -37,11 +37,9 @@ public class TimingsCommand extends Command {
|
||||
boolean separate = "separate".equals(args[0]);
|
||||
if ("reset".equals(args[0])) {
|
||||
for (HandlerList handlerList : HandlerList.getHandlerLists()) {
|
||||
for (RegisteredListener[] listeners : handlerList.getRegisteredListeners()) {
|
||||
for (RegisteredListener listener : listeners) {
|
||||
if (listener instanceof TimedRegisteredListener) {
|
||||
((TimedRegisteredListener)listener).reset();
|
||||
}
|
||||
for (RegisteredListener listener : handlerList.getRegisteredListeners()) {
|
||||
if (listener instanceof TimedRegisteredListener) {
|
||||
((TimedRegisteredListener)listener).reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class HandlerList {
|
||||
/**
|
||||
* Handler array. This field being an array is the key to this system's speed.
|
||||
*/
|
||||
private RegisteredListener[][] handlers = new RegisteredListener[EventPriority.values().length][];
|
||||
private RegisteredListener[] handlers = null;
|
||||
|
||||
/**
|
||||
* Dynamic handler lists. These are changed using register() and
|
||||
@ -23,15 +23,6 @@ public class HandlerList {
|
||||
*/
|
||||
private final EnumMap<EventPriority, ArrayList<RegisteredListener>> handlerslots;
|
||||
|
||||
/**
|
||||
* Whether the current HandlerList has been fully baked. When this is set
|
||||
* to false, the Map<EventPriority, List<RegisteredListener>> will be baked to RegisteredListener[][]
|
||||
* next time the event is called.
|
||||
*
|
||||
* @see org.bukkit.plugin.SimplePluginManager#callEvent
|
||||
*/
|
||||
private boolean baked = false;
|
||||
|
||||
/**
|
||||
* List of all HandlerLists which have been created, for use in bakeAll()
|
||||
*/
|
||||
@ -56,7 +47,7 @@ public class HandlerList {
|
||||
for (List<RegisteredListener> list : h.handlerslots.values()) {
|
||||
list.clear();
|
||||
}
|
||||
h.baked = false;
|
||||
h.handlers = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +93,7 @@ public class HandlerList {
|
||||
public void register(RegisteredListener listener) {
|
||||
if (handlerslots.get(listener.getPriority()).contains(listener))
|
||||
throw new IllegalStateException("This listener is already registered to priority " + listener.getPriority().toString());
|
||||
baked = false;
|
||||
handlers = null;
|
||||
handlerslots.get(listener.getPriority()).add(listener);
|
||||
}
|
||||
|
||||
@ -123,9 +114,8 @@ public class HandlerList {
|
||||
* @param listener listener to remove
|
||||
*/
|
||||
public void unregister(RegisteredListener listener) {
|
||||
if (handlerslots.get(listener.getPriority()).contains(listener)) {
|
||||
baked = false;
|
||||
handlerslots.get(listener.getPriority()).remove(listener);
|
||||
if (handlerslots.get(listener.getPriority()).remove(listener)) {
|
||||
handlers = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +134,7 @@ public class HandlerList {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) baked = false;
|
||||
if (changed) handlers = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,18 +152,19 @@ public class HandlerList {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) baked = false;
|
||||
if (changed) handlers = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake HashMap and ArrayLists to 2d array - does nothing if not necessary
|
||||
*/
|
||||
public void bake() {
|
||||
if (baked) return; // don't re-bake when still valid
|
||||
if (handlers != null) return; // don't re-bake when still valid
|
||||
List<RegisteredListener> entries = new ArrayList<RegisteredListener>();
|
||||
for (Entry<EventPriority, ArrayList<RegisteredListener>> entry : handlerslots.entrySet()) {
|
||||
handlers[entry.getKey().getSlot()] = (entry.getValue().toArray(new RegisteredListener[entry.getValue().size()]));
|
||||
entries.addAll(entry.getValue());
|
||||
}
|
||||
baked = true;
|
||||
handlers = entries.toArray(new RegisteredListener[entries.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +172,8 @@ public class HandlerList {
|
||||
*
|
||||
* @return the array of registered listeners
|
||||
*/
|
||||
public RegisteredListener[][] getRegisteredListeners() {
|
||||
public RegisteredListener[] getRegisteredListeners() {
|
||||
bake();
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
@ -431,38 +431,35 @@ public final class SimplePluginManager implements PluginManager {
|
||||
*/
|
||||
public synchronized void callEvent(Event event) {
|
||||
HandlerList handlers = event.getHandlers();
|
||||
handlers.bake();
|
||||
RegisteredListener[][] listeners = handlers.getRegisteredListeners();
|
||||
RegisteredListener[] listeners = handlers.getRegisteredListeners();
|
||||
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
for (RegisteredListener registration : listeners[i]) {
|
||||
if (!registration.getPlugin().isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
for (RegisteredListener registration : listeners) {
|
||||
if (!registration.getPlugin().isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
registration.callEvent(event);
|
||||
} catch (AuthorNagException ex) {
|
||||
Plugin plugin = registration.getPlugin();
|
||||
try {
|
||||
registration.callEvent(event);
|
||||
} catch (AuthorNagException ex) {
|
||||
Plugin plugin = registration.getPlugin();
|
||||
|
||||
if (plugin.isNaggable()) {
|
||||
plugin.setNaggable(false);
|
||||
if (plugin.isNaggable()) {
|
||||
plugin.setNaggable(false);
|
||||
|
||||
String author = "<NoAuthorGiven>";
|
||||
String author = "<NoAuthorGiven>";
|
||||
|
||||
if (plugin.getDescription().getAuthors().size() > 0) {
|
||||
author = plugin.getDescription().getAuthors().get(0);
|
||||
}
|
||||
server.getLogger().log(Level.SEVERE, String.format(
|
||||
"Nag author: '%s' of '%s' about the following: %s",
|
||||
author,
|
||||
plugin.getDescription().getName(),
|
||||
ex.getMessage()
|
||||
));
|
||||
if (plugin.getDescription().getAuthors().size() > 0) {
|
||||
author = plugin.getDescription().getAuthors().get(0);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not pass event " + event.getEventName() + " to " + registration.getPlugin().getDescription().getName(), ex);
|
||||
server.getLogger().log(Level.SEVERE, String.format(
|
||||
"Nag author: '%s' of '%s' about the following: %s",
|
||||
author,
|
||||
plugin.getDescription().getName(),
|
||||
ex.getMessage()
|
||||
));
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not pass event " + event.getEventName() + " to " + registration.getPlugin().getDescription().getName(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren