From df6693da9dc526312affbee9faf84fdb7e754636 Mon Sep 17 00:00:00 2001 From: IoyoCode Date: Thu, 14 Mar 2024 16:29:20 +0000 Subject: [PATCH] feat(events): included a new "type" property in Event classes, so that if there's a listener that listens to multiple events, such as an InteractionEvent listener, discord.jar will now provide the relevant event type --- .../discordjar/events/EventDispatcher.java | 1 + .../seailz/discordjar/events/model/Event.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/seailz/discordjar/events/EventDispatcher.java b/src/main/java/com/seailz/discordjar/events/EventDispatcher.java index a8415200..b1e9d890 100644 --- a/src/main/java/com/seailz/discordjar/events/EventDispatcher.java +++ b/src/main/java/com/seailz/discordjar/events/EventDispatcher.java @@ -94,6 +94,7 @@ private List findListenersForEvent(@NotNull Class type, DiscordJar djv) { if (event == null) return; + event.setType(type); new Thread(() -> { long start = System.currentTimeMillis(); List listenersForEventType = findListenersForEvent(type); diff --git a/src/main/java/com/seailz/discordjar/events/model/Event.java b/src/main/java/com/seailz/discordjar/events/model/Event.java index 5360c488..bc69aa8e 100644 --- a/src/main/java/com/seailz/discordjar/events/model/Event.java +++ b/src/main/java/com/seailz/discordjar/events/model/Event.java @@ -1,7 +1,9 @@ package com.seailz.discordjar.events.model; import com.seailz.discordjar.DiscordJar; +import lombok.Setter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.json.JSONObject; /** @@ -21,6 +23,13 @@ public class Event { private final DiscordJar bot; private final long sequence; private final JSONObject json; + /** + * -- SETTER -- + * Not intended for use by the end user. + */ + @Setter + @Nullable + private Class type; public Event(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { this.bot = bot; @@ -54,4 +63,12 @@ public JSONObject getJson() { return json; } + /** + * Returns the type of the event, such as {@link com.seailz.discordjar.events.model.message.MessageCreateEvent MessageCreateEvent}. This is nullable! + */ + @Nullable + public Class getType() { + return type; + } + }