Added support for latest events version

This commit is contained in:
Tim203 2022-09-01 00:50:03 +02:00
parent 1db77ad2bd
commit c07c7b9337
No known key found for this signature in database
GPG key ID: 064EE9F5BF7C3EE8
3 changed files with 36 additions and 12 deletions

View file

@ -27,6 +27,7 @@ package org.geysermc.geyser.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.event.PostOrder;
import org.geysermc.event.bus.impl.OwnedEventBusImpl;
import org.geysermc.event.subscribe.OwnedSubscriber;
import org.geysermc.event.subscribe.Subscribe;
@ -43,8 +44,11 @@ public final class GeyserEventBus extends OwnedEventBusImpl<Extension, Event, Ev
implements EventBus {
@Override
protected <L, T extends Event, B extends OwnedSubscriber<Extension, T>> B makeSubscription(
Extension owner, Class<T> eventClass, Subscribe subscribe,
L listener, BiConsumer<L, T> handler) {
@NonNull Extension owner,
@NonNull Class<T> eventClass,
@NonNull Subscribe subscribe,
@NonNull L listener,
@NonNull BiConsumer<L, T> handler) {
return (B) new GeyserEventSubscriber<>(
owner, eventClass, subscribe.postOrder(), subscribe.ignoreCancelled(), listener, handler
);
@ -52,8 +56,11 @@ public final class GeyserEventBus extends OwnedEventBusImpl<Extension, Event, Ev
@Override
protected <T extends Event, B extends OwnedSubscriber<Extension, T>> B makeSubscription(
Extension owner, Class<T> eventClass, Consumer<T> handler) {
return (B) new GeyserEventSubscriber<>(owner, eventClass, handler);
@NonNull Extension owner,
@NonNull Class<T> eventClass,
@NonNull Consumer<T> handler,
@NonNull PostOrder postOrder) {
return (B) new GeyserEventSubscriber<>(owner, eventClass, handler, postOrder);
}
@Override

View file

@ -25,6 +25,7 @@
package org.geysermc.geyser.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.event.PostOrder;
import org.geysermc.event.subscribe.impl.OwnedSubscriberImpl;
@ -36,12 +37,21 @@ import java.util.function.Consumer;
public final class GeyserEventSubscriber<E extends Event> extends OwnedSubscriberImpl<Extension, E>
implements ExtensionEventSubscriber<E> {
GeyserEventSubscriber(Extension owner, Class<E> eventClass, Consumer<E> handler) {
super(owner, eventClass, handler);
GeyserEventSubscriber(
@NonNull Extension owner,
@NonNull Class<E> eventClass,
@NonNull Consumer<E> handler,
@NonNull PostOrder postOrder) {
super(owner, eventClass, handler, postOrder);
}
<H> GeyserEventSubscriber(Extension owner, Class<E> eventClass, PostOrder postOrder, boolean ignoreCancelled,
H handlerInstance, BiConsumer<H, E> handler) {
<H> GeyserEventSubscriber(
@NonNull Extension owner,
@NonNull Class<E> eventClass,
@NonNull PostOrder postOrder,
boolean ignoreCancelled,
@NonNull H handlerInstance,
@NonNull BiConsumer<H, E> handler) {
super(owner, eventClass, postOrder, ignoreCancelled, handlerInstance, handler);
}
}

View file

@ -27,17 +27,14 @@ package org.geysermc.geyser.extension.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.event.bus.impl.EventBusImpl;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.event.PostOrder;
import org.geysermc.event.subscribe.Subscriber;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventSubscriber;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import org.geysermc.geyser.api.event.ExtensionEventSubscriber;
import org.geysermc.geyser.api.extension.Extension;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public record GeyserExtensionEventBus(EventBus eventBus, Extension extension) implements ExtensionEventBus {
@ -68,6 +65,16 @@ public record GeyserExtensionEventBus(EventBus eventBus, Extension extension) im
return eventBus.subscribe(extension, eventClass, consumer);
}
@Override
@SuppressWarnings("unchecked")
public <T extends Event, U extends Subscriber<T>> @NonNull U subscribe(
@NonNull Class<T> eventClass,
@NonNull Consumer<T> consumer,
@NonNull PostOrder postOrder
) {
return eventBus.subscribe(extension, eventClass, consumer, postOrder);
}
@Override
public void unregisterAll() {
eventBus.unregisterAll(extension);