Fix error message when event handlers throw an exception

This commit is contained in:
Luck 2018-12-22 17:03:51 +00:00
parent fc69002c86
commit 2ccffc6e6d
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 15 additions and 2 deletions

View File

@ -43,4 +43,12 @@ public interface LuckPermsEvent {
*/
@NonNull LuckPermsApi getApi();
/**
* Gets the type of the event.
*
* @return the type of the event
* @since 4.4
*/
@NonNull Class<? extends LuckPermsEvent> getEventType();
}

View File

@ -108,7 +108,7 @@ public class LuckPermsEventHandler<T extends LuckPermsEvent> implements EventHan
this.consumer.accept(event);
this.callCount.incrementAndGet();
} catch (Throwable t) {
this.eventBus.getPlugin().getLogger().warn("Unable to pass event " + event.getClass().getSimpleName() + " to handler " + this.consumer.getClass().getName());
this.eventBus.getPlugin().getLogger().warn("Unable to pass event " + event.getEventType().getSimpleName() + " to handler " + this.consumer.getClass().getName());
t.printStackTrace();
}
}

View File

@ -52,12 +52,14 @@ public class GeneratedEventSpec {
private static final Method EQUALS_METHOD;
private static final Method HASHCODE_METHOD;
private static final Method GET_API_METHOD;
private static final Method GET_EVENT_TYPE_METHOD;
static {
try {
TO_STRING_METHOD = Object.class.getMethod("toString");
EQUALS_METHOD = Object.class.getMethod("equals", Object.class);
HASHCODE_METHOD = Object.class.getMethod("hashCode");
GET_API_METHOD = LuckPermsEvent.class.getMethod("getApi");
GET_EVENT_TYPE_METHOD = LuckPermsEvent.class.getMethod("getEventType");
} catch (NoSuchMethodException e) {
throw new ExceptionInInitializerError(e);
}
@ -81,7 +83,7 @@ public class GeneratedEventSpec {
if (method.isDefault()) {
continue;
}
if (GET_API_METHOD.equals(method)) {
if (GET_API_METHOD.equals(method) || GET_EVENT_TYPE_METHOD.equals(method)) {
continue;
}
@ -141,6 +143,9 @@ public class GeneratedEventSpec {
if (GET_API_METHOD.equals(method)) {
return this.api;
}
if (GET_EVENT_TYPE_METHOD.equals(method)) {
return GeneratedEventSpec.this.eventClass;
}
if (method.getDeclaringClass() == Object.class || method.isDefault()) {
return MethodHandles.lookup()