|
4 | 4 | import net.dv8tion.jda.api.Permission; |
5 | 5 | import net.dv8tion.jda.api.entities.Guild; |
6 | 6 | import net.dv8tion.jda.api.entities.TextChannel; |
| 7 | +import net.dv8tion.jda.api.events.GenericEvent; |
7 | 8 | import net.dv8tion.jda.api.events.ReadyEvent; |
8 | 9 | import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; |
9 | 10 | import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; |
10 | 11 | import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; |
11 | 12 | import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; |
12 | 13 | import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent; |
13 | 14 | import net.dv8tion.jda.api.exceptions.ErrorHandler; |
| 15 | +import net.dv8tion.jda.api.hooks.EventListener; |
14 | 16 | import net.dv8tion.jda.api.hooks.ListenerAdapter; |
15 | 17 | import net.dv8tion.jda.api.interactions.commands.Command; |
16 | 18 | import net.dv8tion.jda.api.interactions.components.ComponentInteraction; |
@@ -282,21 +284,20 @@ private interface TriConsumer<A, B, C> { |
282 | 284 | void accept(A first, B second, C third); |
283 | 285 | } |
284 | 286 |
|
285 | | - private static final class MessageReceiverAsEventListener extends ListenerAdapter { |
| 287 | + private static final class MessageReceiverAsEventListener implements EventListener { |
286 | 288 | private final MessageReceiver messageReceiver; |
287 | 289 |
|
288 | 290 | MessageReceiverAsEventListener(MessageReceiver messageReceiver) { |
289 | 291 | this.messageReceiver = messageReceiver; |
290 | 292 | } |
291 | 293 |
|
292 | 294 | @Override |
293 | | - public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { |
294 | | - messageReceiver.onMessageSent(event); |
295 | | - } |
296 | | - |
297 | | - @Override |
298 | | - public void onGuildMessageUpdate(@NotNull GuildMessageUpdateEvent event) { |
299 | | - messageReceiver.onMessageUpdated(event); |
| 295 | + public void onEvent(@NotNull GenericEvent event) { |
| 296 | + if (event instanceof GuildMessageReceivedEvent receivedEvent) { |
| 297 | + messageReceiver.onMessageReceived(receivedEvent); |
| 298 | + } else if (event instanceof GuildMessageUpdateEvent updateEvent) { |
| 299 | + messageReceiver.onMessageUpdated(updateEvent); |
| 300 | + } |
300 | 301 | } |
301 | 302 | } |
302 | 303 | } |
0 commit comments