mirror of
https://github.com/PaperMC/Paper.git
synced 2026-11-24 18:09:41 -05:00
Support asynchronous events; Addresses BUKKIT-1212
By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
1 parent
ca71171e8c
commit
ad7045596d
10 files changed
+300
-27
No files matched your search
@@ -443,11 +443,28 @@ public final class SimplePluginManager implements PluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls an event with the given details
|
||||
* Calls an event with the given details.<br>
|
||||
* This method only synchronizes when the event is not asynchronous.
|
||||
*
|
||||
* @param event Event details
|
||||
*/
|
||||
public synchronized void callEvent(Event event) {
|
||||
public void callEvent(Event event) {
|
||||
if (event.isAsynchronous()) {
|
||||
if (Thread.holdsLock(this)) {
|
||||
throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code.");
|
||||
}
|
||||
if (server.isPrimaryThread()) {
|
||||
throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from primary server thread.");
|
||||
}
|
||||
fireEvent(event);
|
||||
} else {
|
||||
synchronized (this) {
|
||||
fireEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fireEvent(Event event) {
|
||||
HandlerList handlers = event.getHandlers();
|
||||
RegisteredListener[] listeners = handlers.getRegisteredListeners();
|
||||
|
||||
|
||||
Reference in new issue
Block a user