make anonymous class event caller beautifuler

This commit is contained in:
Bixilon 2021-01-11 22:56:46 +01:00
parent ba729f7ba3
commit 5244f9de9d
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -19,8 +19,6 @@ import de.bixilon.minosoft.modding.loading.Priorities;
public class EventInvokerCallback<V extends ConnectionEvent> extends EventInvoker {
private final InvokerCallback<V> callback;
Class<? extends ConnectionEvent> eventType = ConnectionEvent.class;
public EventInvokerCallback(boolean ignoreCancelled, InvokerCallback<V> callback) {
super(ignoreCancelled, Priorities.NORMAL, null);
this.callback = callback;
@ -29,19 +27,18 @@ public class EventInvokerCallback<V extends ConnectionEvent> extends EventInvoke
// if you need instant fireing support
public EventInvokerCallback(Class<? extends ConnectionEvent> eventType, InvokerCallback<V> callback) {
this(false, callback);
this.eventType = eventType; // ToDo: how to get the class of V? seems to be impossible
}
@SuppressWarnings("unchecked")
public void invoke(ConnectionEvent event) {
if (this.eventType != event.getClass()) {
return;
try {
this.callback.handle((V) event);
} catch (ClassCastException ignored) {
}
this.callback.handle((V) event);
}
public Class<? extends ConnectionEvent> getEventType() {
return this.eventType;
return ConnectionEvent.class;
}
public interface InvokerCallback<V> {