mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-14 04:02:04 +01:00
Add /paper dumplisteners command
This commit is contained in:
parent
8a7cabbac9
commit
8636a7d5a4
@ -84,4 +84,10 @@ public class TimedEventExecutor implements EventExecutor {
|
|||||||
executor.execute(listener, event);
|
executor.execute(listener, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public String toString() {
|
||||||
|
return "TimedEventExecutor['" + this.executor.toString() + "']";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,12 @@ public class MethodHandleEventExecutor implements EventExecutor {
|
|||||||
|
|
||||||
private final Class<? extends Event> eventClass;
|
private final Class<? extends Event> eventClass;
|
||||||
private final MethodHandle handle;
|
private final MethodHandle handle;
|
||||||
|
private final @Nullable Method method;
|
||||||
|
|
||||||
public MethodHandleEventExecutor(final Class<? extends Event> eventClass, final MethodHandle handle) {
|
public MethodHandleEventExecutor(final Class<? extends Event> eventClass, final MethodHandle handle) {
|
||||||
this.eventClass = eventClass;
|
this.eventClass = eventClass;
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
this.method = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodHandleEventExecutor(final Class<? extends Event> eventClass, final Method m) {
|
public MethodHandleEventExecutor(final Class<? extends Event> eventClass, final Method m) {
|
||||||
@ -32,6 +34,7 @@ public class MethodHandleEventExecutor implements EventExecutor {
|
|||||||
} catch (final IllegalAccessException e) {
|
} catch (final IllegalAccessException e) {
|
||||||
throw new AssertionError("Unable to set accessible", e);
|
throw new AssertionError("Unable to set accessible", e);
|
||||||
}
|
}
|
||||||
|
this.method = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,4 +46,9 @@ public class MethodHandleEventExecutor implements EventExecutor {
|
|||||||
SneakyThrow.sneaky(t);
|
SneakyThrow.sneaky(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MethodHandleEventExecutor['" + this.method + "']";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ public class StaticMethodHandleEventExecutor implements EventExecutor {
|
|||||||
|
|
||||||
private final Class<? extends Event> eventClass;
|
private final Class<? extends Event> eventClass;
|
||||||
private final MethodHandle handle;
|
private final MethodHandle handle;
|
||||||
|
private final Method method;
|
||||||
|
|
||||||
public StaticMethodHandleEventExecutor(final Class<? extends Event> eventClass, final Method m) {
|
public StaticMethodHandleEventExecutor(final Class<? extends Event> eventClass, final Method m) {
|
||||||
Preconditions.checkArgument(Modifier.isStatic(m.getModifiers()), "Not a static method: %s", m);
|
Preconditions.checkArgument(Modifier.isStatic(m.getModifiers()), "Not a static method: %s", m);
|
||||||
@ -30,6 +31,7 @@ public class StaticMethodHandleEventExecutor implements EventExecutor {
|
|||||||
} catch (final IllegalAccessException e) {
|
} catch (final IllegalAccessException e) {
|
||||||
throw new AssertionError("Unable to set accessible", e);
|
throw new AssertionError("Unable to set accessible", e);
|
||||||
}
|
}
|
||||||
|
this.method = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -41,4 +43,9 @@ public class StaticMethodHandleEventExecutor implements EventExecutor {
|
|||||||
SneakyThrow.sneaky(throwable);
|
SneakyThrow.sneaky(throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "StaticMethodHandleEventExecutor['" + this.method + "']";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,13 @@ public class HandlerList {
|
|||||||
*/
|
*/
|
||||||
private static ArrayList<HandlerList> allLists = new ArrayList<HandlerList>();
|
private static ArrayList<HandlerList> allLists = new ArrayList<HandlerList>();
|
||||||
|
|
||||||
|
// Paper start
|
||||||
|
/**
|
||||||
|
* Event types which have instantiated a {@link HandlerList}.
|
||||||
|
*/
|
||||||
|
private static final java.util.Set<String> EVENT_TYPES = java.util.concurrent.ConcurrentHashMap.newKeySet();
|
||||||
|
// Paper end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bake all handler lists. Best used just after all normal event
|
* Bake all handler lists. Best used just after all normal event
|
||||||
* registration is complete, ie just after all plugins are loaded if
|
* registration is complete, ie just after all plugins are loaded if
|
||||||
@ -94,6 +101,12 @@ public class HandlerList {
|
|||||||
* The HandlerList is then added to meta-list for use in bakeAll()
|
* The HandlerList is then added to meta-list for use in bakeAll()
|
||||||
*/
|
*/
|
||||||
public HandlerList() {
|
public HandlerList() {
|
||||||
|
// Paper start
|
||||||
|
java.lang.StackWalker.getInstance(java.util.EnumSet.of(java.lang.StackWalker.Option.RETAIN_CLASS_REFERENCE), 4)
|
||||||
|
.walk(s -> s.filter(f -> Event.class.isAssignableFrom(f.getDeclaringClass())).findFirst())
|
||||||
|
.map(f -> f.getDeclaringClass().getName())
|
||||||
|
.ifPresent(EVENT_TYPES::add);
|
||||||
|
// Paper end
|
||||||
handlerslots = new EnumMap<EventPriority, ArrayList<RegisteredListener>>(EventPriority.class);
|
handlerslots = new EnumMap<EventPriority, ArrayList<RegisteredListener>>(EventPriority.class);
|
||||||
for (EventPriority o : EventPriority.values()) {
|
for (EventPriority o : EventPriority.values()) {
|
||||||
handlerslots.put(o, new ArrayList<RegisteredListener>());
|
handlerslots.put(o, new ArrayList<RegisteredListener>());
|
||||||
|
@ -70,9 +70,18 @@ public interface EventExecutor {
|
|||||||
try {
|
try {
|
||||||
EventExecutor asmExecutor = executorClass.newInstance();
|
EventExecutor asmExecutor = executorClass.newInstance();
|
||||||
// Define a wrapper to conform to bukkit stupidity (passing in events that don't match and wrapper exception)
|
// Define a wrapper to conform to bukkit stupidity (passing in events that don't match and wrapper exception)
|
||||||
return (listener, event) -> {
|
return new EventExecutor() {
|
||||||
if (!eventClass.isInstance(event)) return;
|
@Override
|
||||||
asmExecutor.execute(listener, event);
|
public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
|
||||||
|
if (!eventClass.isInstance(event)) return;
|
||||||
|
asmExecutor.execute(listener, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public String toString() {
|
||||||
|
return "ASMEventExecutor['" + m + "']";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new AssertionError("Unable to initialize generated event executor", e);
|
throw new AssertionError("Unable to initialize generated event executor", e);
|
||||||
|
@ -78,4 +78,27 @@ public class RegisteredListener {
|
|||||||
public boolean isIgnoringCancelled() {
|
public boolean isIgnoringCancelled() {
|
||||||
return ignoreCancelled;
|
return ignoreCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start
|
||||||
|
/**
|
||||||
|
* Get the executor for this registration.
|
||||||
|
*
|
||||||
|
* @return executor
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public EventExecutor getExecutor() {
|
||||||
|
return this.executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RegisteredListener{"
|
||||||
|
+ "plugin=\"" + this.plugin.getName()
|
||||||
|
+ "\", listener=\"" + this.listener
|
||||||
|
+ "\", executor=\"" + this.executor
|
||||||
|
+ "\", priority=\"" + this.priority.name() + " (" + this.priority.getSlot() + ")"
|
||||||
|
+ "\", ignoringCancelled=" + this.ignoreCancelled
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user