Add /paper dumplisteners command

This commit is contained in:
Warrior
2022-11-19 19:46:44 +01:00
parent 8a7cabbac9
commit 8636a7d5a4
6 changed files with 69 additions and 3 deletions

View File

@@ -33,6 +33,13 @@ public class 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
* 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()
*/
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);
for (EventPriority o : EventPriority.values()) {
handlerslots.put(o, new ArrayList<RegisteredListener>());

View File

@@ -70,9 +70,18 @@ public interface EventExecutor {
try {
EventExecutor asmExecutor = executorClass.newInstance();
// Define a wrapper to conform to bukkit stupidity (passing in events that don't match and wrapper exception)
return (listener, event) -> {
if (!eventClass.isInstance(event)) return;
asmExecutor.execute(listener, event);
return new EventExecutor() {
@Override
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) {
throw new AssertionError("Unable to initialize generated event executor", e);

View File

@@ -78,4 +78,27 @@ public class RegisteredListener {
public boolean isIgnoringCancelled() {
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
}