From 0185ef6e214bff3743d33c50d7b6203aadcd9940 Mon Sep 17 00:00:00 2001 From: Vankka Date: Fri, 27 Oct 2023 19:05:53 +0300 Subject: [PATCH] Split Processable into NoArgument and Argument variants --- .../api/event/events/Processable.java | 24 +++++++++++++++---- .../channel/GameChannelLookupEvent.java | 12 ++-------- .../DiscordChatMessageProcessEvent.java | 2 +- .../game/AbstractGameMessageReceiveEvent.java | 2 +- .../placeholder/PlaceholderLookupEvent.java | 8 +------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/api/src/main/java/com/discordsrv/api/event/events/Processable.java b/api/src/main/java/com/discordsrv/api/event/events/Processable.java index 9cb72529..02093b8e 100644 --- a/api/src/main/java/com/discordsrv/api/event/events/Processable.java +++ b/api/src/main/java/com/discordsrv/api/event/events/Processable.java @@ -40,11 +40,6 @@ public interface Processable extends Event { */ boolean isProcessed(); - /** - * Marks this event as processed. This cannot be reversed, events cannot be unprocessed. - */ - void markAsProcessed(); - /** * Returns the {@link EventListener} that processed this event. * @@ -63,4 +58,23 @@ public interface Processable extends Event { return listener; } + + interface NoArgument extends Processable { + + /** + * Marks this event as processed. This cannot be reversed. + * @see #isProcessed() + */ + void markAsProcessed(); + } + + interface Argument extends Processable { + + /** + * Marks this event as processed with the given argument. This cannot be reversed. + * @param input the argument for processing the event + * @see #isProcessed() + */ + void process(T input); + } } diff --git a/api/src/main/java/com/discordsrv/api/event/events/channel/GameChannelLookupEvent.java b/api/src/main/java/com/discordsrv/api/event/events/channel/GameChannelLookupEvent.java index 9110458b..f640b25f 100644 --- a/api/src/main/java/com/discordsrv/api/event/events/channel/GameChannelLookupEvent.java +++ b/api/src/main/java/com/discordsrv/api/event/events/channel/GameChannelLookupEvent.java @@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable; * * @see #isDefault() */ -public class GameChannelLookupEvent implements Processable { +public class GameChannelLookupEvent implements Processable.Argument { private final String pluginName; private final String channelName; @@ -90,6 +90,7 @@ public class GameChannelLookupEvent implements Processable { * @throws IllegalStateException if the event is already processed * @throws IllegalArgumentException if the provided channel doesn't match {@link #getChannelName()} and {@link #isDefault()} is {@code false} */ + @Override public void process(@NotNull GameChannel channel) { if (processed) { throw new IllegalStateException("Already processed"); @@ -108,13 +109,4 @@ public class GameChannelLookupEvent implements Processable { this.channel = channel; this.processed = true; } - - /** - * @deprecated Use {@link #process(GameChannel)}. - */ - @Override - @Deprecated - public void markAsProcessed() { - throw new RuntimeException("Please use process(GameChannel) instead"); - } } diff --git a/api/src/main/java/com/discordsrv/api/event/events/message/receive/discord/DiscordChatMessageProcessEvent.java b/api/src/main/java/com/discordsrv/api/event/events/message/receive/discord/DiscordChatMessageProcessEvent.java index 2519af1b..c61b1482 100644 --- a/api/src/main/java/com/discordsrv/api/event/events/message/receive/discord/DiscordChatMessageProcessEvent.java +++ b/api/src/main/java/com/discordsrv/api/event/events/message/receive/discord/DiscordChatMessageProcessEvent.java @@ -10,7 +10,7 @@ import com.discordsrv.api.event.events.Processable; * Indicates that a Discord message is about to be processed, this will run once per {@link GameChannel} destination, * meaning it could run multiple times for a single Discord message. This runs after {@link DiscordChatMessageReceiveEvent}. */ -public class DiscordChatMessageProcessEvent implements Cancellable, Processable { +public class DiscordChatMessageProcessEvent implements Cancellable, Processable.NoArgument { private final DiscordMessageChannel discordChannel; private final ReceivedDiscordMessage message; diff --git a/api/src/main/java/com/discordsrv/api/event/events/message/receive/game/AbstractGameMessageReceiveEvent.java b/api/src/main/java/com/discordsrv/api/event/events/message/receive/game/AbstractGameMessageReceiveEvent.java index 7d3e45f5..f1ce9328 100644 --- a/api/src/main/java/com/discordsrv/api/event/events/message/receive/game/AbstractGameMessageReceiveEvent.java +++ b/api/src/main/java/com/discordsrv/api/event/events/message/receive/game/AbstractGameMessageReceiveEvent.java @@ -27,7 +27,7 @@ import com.discordsrv.api.event.events.Cancellable; import com.discordsrv.api.event.events.Processable; import org.jetbrains.annotations.Nullable; -public abstract class AbstractGameMessageReceiveEvent implements Processable, Cancellable { +public abstract class AbstractGameMessageReceiveEvent implements Cancellable, Processable.NoArgument { private final Object triggeringEvent; private boolean cancelled; diff --git a/api/src/main/java/com/discordsrv/api/event/events/placeholder/PlaceholderLookupEvent.java b/api/src/main/java/com/discordsrv/api/event/events/placeholder/PlaceholderLookupEvent.java index a6e28168..a83f61be 100644 --- a/api/src/main/java/com/discordsrv/api/event/events/placeholder/PlaceholderLookupEvent.java +++ b/api/src/main/java/com/discordsrv/api/event/events/placeholder/PlaceholderLookupEvent.java @@ -34,7 +34,7 @@ import java.util.Set; /** * An event for converting a placeholder's name and context into a {@link PlaceholderLookupResult}. */ -public class PlaceholderLookupEvent implements Event, Processable { +public class PlaceholderLookupEvent implements Event, Processable.Argument { private final String placeholder; private final Set contexts; @@ -114,10 +114,4 @@ public class PlaceholderLookupEvent implements Event, Processable { this.result = result; this.processed = true; } - - @Override - @Deprecated - public void markAsProcessed() { - throw new RuntimeException("Please use process(PlaceholderLookupResult) instead"); - } }