Skip to content

Commit

Permalink
feat(events): included a new "type" property in Event classes, so tha…
Browse files Browse the repository at this point in the history
…t if there's a listener that listens to multiple events, such as an InteractionEvent listener, discord.jar will now provide the relevant event type
  • Loading branch information
seailz committed Mar 14, 2024
1 parent 5d25050 commit df6693d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private List<ListenerMethodPair> findListenersForEvent(@NotNull Class<? extends
*/
public void dispatchEvent(Event event, Class<? extends Event> type, DiscordJar djv) {
if (event == null) return;
event.setType(type);
new Thread(() -> {
long start = System.currentTimeMillis();
List<ListenerMethodPair> listenersForEventType = findListenersForEvent(type);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/seailz/discordjar/events/model/Event.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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<? extends Event> type;

public Event(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) {
this.bot = bot;
Expand Down Expand Up @@ -54,4 +63,12 @@ public JSONObject getJson() {
return json;
}

/**
* Returns the <i>type</i> of the event, such as {@link com.seailz.discordjar.events.model.message.MessageCreateEvent MessageCreateEvent}. This is nullable!
*/
@Nullable
public Class<? extends Event> getType() {
return type;
}

}

0 comments on commit df6693d

Please sign in to comment.