use of me.piggypiglet.gary.core.objects.enums.EventsEnum in project Gary by help-chat.
the class EventUtils method pullEvent.
private static GenericEvent pullEvent(EventsEnum event, JDA jda) {
final Logger logger = LoggerFactory.getLogger("Event Puller");
final AtomicReference<GenericEvent> pulledEvent = new AtomicReference<>();
EventListener listener = l -> {
if (EventsEnum.fromEvent(l) == event) {
pulledEvent.set(l);
}
};
logger.info("Adding temporary event listener for " + event.name());
jda.addEventListener(listener);
// exception will only be thrown on gary shutdown, no point in printing stack trace.
while (pulledEvent.get() == null) try {
Thread.sleep(100);
} catch (Exception ignored) {
}
jda.removeEventListener(listener);
logger.info("Removing temporary event listener for " + event.name());
return pulledEvent.get();
}
Aggregations