dev.alangomes.springspigot.reactive.EventEmitter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spigot-spring-boot-starter Show documentation
Show all versions of spigot-spring-boot-starter Show documentation
Spring support for spigot plugins
package dev.alangomes.springspigot.reactive;
import dev.alangomes.springspigot.context.Context;
import dev.alangomes.springspigot.event.EventUtil;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.FieldDefaults;
import lombok.val;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
@AllArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
class EventEmitter implements ObservableOnSubscribe {
@Getter
Listener listener = new Listener() {
};
Class extends Event> eventClazz;
ObserveEvent observeEvent;
Plugin plugin;
Context context;
@Override
public void subscribe(ObservableEmitter observableEmitter) {
val pluginManager = plugin.getServer().getPluginManager();
pluginManager.registerEvent(eventClazz, listener, observeEvent.priority(), (l, event) -> {
if (eventClazz.isAssignableFrom(event.getClass())) {
T emittedEvent = (T) event;
context.runWithSender(EventUtil.getSender(emittedEvent), () -> observableEmitter.onNext(emittedEvent));
}
}, plugin, observeEvent.ignoreCancelled());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy