mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 12:25:12 -04:00
make anonymous class event caller beautifuler
This commit is contained in:
parent
ba729f7ba3
commit
5244f9de9d
@ -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> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user