Split Processable into NoArgument and Argument variants

This commit is contained in:
Vankka 2023-10-27 19:05:53 +03:00
parent 639507e9db
commit 0185ef6e21
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
5 changed files with 24 additions and 24 deletions

View File

@ -40,11 +40,6 @@ public interface Processable extends Event {
*/ */
boolean isProcessed(); 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. * Returns the {@link EventListener} that processed this event.
* *
@ -63,4 +58,23 @@ public interface Processable extends Event {
return listener; return listener;
} }
interface NoArgument extends Processable {
/**
* Marks this event as processed. This cannot be reversed.
* @see #isProcessed()
*/
void markAsProcessed();
}
interface Argument<T> 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);
}
} }

View File

@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable;
* *
* @see #isDefault() * @see #isDefault()
*/ */
public class GameChannelLookupEvent implements Processable { public class GameChannelLookupEvent implements Processable.Argument<GameChannel> {
private final String pluginName; private final String pluginName;
private final String channelName; private final String channelName;
@ -90,6 +90,7 @@ public class GameChannelLookupEvent implements Processable {
* @throws IllegalStateException if the event is already processed * @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} * @throws IllegalArgumentException if the provided channel doesn't match {@link #getChannelName()} and {@link #isDefault()} is {@code false}
*/ */
@Override
public void process(@NotNull GameChannel channel) { public void process(@NotNull GameChannel channel) {
if (processed) { if (processed) {
throw new IllegalStateException("Already processed"); throw new IllegalStateException("Already processed");
@ -108,13 +109,4 @@ public class GameChannelLookupEvent implements Processable {
this.channel = channel; this.channel = channel;
this.processed = true; this.processed = true;
} }
/**
* @deprecated Use {@link #process(GameChannel)}.
*/
@Override
@Deprecated
public void markAsProcessed() {
throw new RuntimeException("Please use process(GameChannel) instead");
}
} }

View File

@ -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, * 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}. * 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 DiscordMessageChannel discordChannel;
private final ReceivedDiscordMessage message; private final ReceivedDiscordMessage message;

View File

@ -27,7 +27,7 @@ import com.discordsrv.api.event.events.Cancellable;
import com.discordsrv.api.event.events.Processable; import com.discordsrv.api.event.events.Processable;
import org.jetbrains.annotations.Nullable; 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 final Object triggeringEvent;
private boolean cancelled; private boolean cancelled;

View File

@ -34,7 +34,7 @@ import java.util.Set;
/** /**
* An event for converting a placeholder's name and context into a {@link PlaceholderLookupResult}. * 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<PlaceholderLookupResult> {
private final String placeholder; private final String placeholder;
private final Set<Object> contexts; private final Set<Object> contexts;
@ -114,10 +114,4 @@ public class PlaceholderLookupEvent implements Event, Processable {
this.result = result; this.result = result;
this.processed = true; this.processed = true;
} }
@Override
@Deprecated
public void markAsProcessed() {
throw new RuntimeException("Please use process(PlaceholderLookupResult) instead");
}
} }