From 764e6d26807bb218d688c1345221bdc13512fa05 Mon Sep 17 00:00:00 2001 From: Snabeldier <79211348+Snabeldier@users.noreply.github.com> Date: Fri, 31 Jan 2025 04:36:00 +0100 Subject: [PATCH] introduce DialogReceiver --- .../core/api/messaging/DialogReceiver.java | 106 ++++++++++++++++++ .../core/api/messaging/MessageReceiver.java | 56 --------- .../minevalley/core/api/users/OnlineUser.java | 38 +------ 3 files changed, 108 insertions(+), 92 deletions(-) create mode 100644 src/main/java/minevalley/core/api/messaging/DialogReceiver.java diff --git a/src/main/java/minevalley/core/api/messaging/DialogReceiver.java b/src/main/java/minevalley/core/api/messaging/DialogReceiver.java new file mode 100644 index 0000000..3f36312 --- /dev/null +++ b/src/main/java/minevalley/core/api/messaging/DialogReceiver.java @@ -0,0 +1,106 @@ +package minevalley.core.api.messaging; + +import minevalley.core.api.messaging.clickable.ChatMenu; +import minevalley.core.api.messaging.clickable.ClickableOption; +import minevalley.core.api.messaging.instruction.Instruction; +import minevalley.core.api.messaging.types.MessageType; +import net.kyori.adventure.text.ComponentLike; +import org.jetbrains.annotations.Contract; + +import javax.annotation.Nonnull; +import java.util.function.Consumer; + +@SuppressWarnings("unused") +public interface DialogReceiver { + + /** + * Sends a message to the receiver. + * + * @param message the message to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the message or menu is null + */ + @Nonnull + @Contract("_, _ -> new") + ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull ClickableOption... menu) + throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param message the message to send + * @param instruction the instruction to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the message, instruction or menu is null + */ + @Nonnull + @Contract("_, _, _ -> new") + ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull Instruction instruction, + @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param type the type of message + * @param message the message to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the type, message or menu is null + */ + @Nonnull + @Contract("_, _, _ -> new") + ChatMenu sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull ClickableOption... menu) + throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param type the type of message + * @param message the message to send + * @param instruction the instruction to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the type, message, instruction or menu is null + */ + @Nonnull + @Contract("_, _, _, _ -> new") + ChatMenu sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull Instruction instruction, + @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Sends a message to the receiver and waits for an input. + * + * @param text the text to send + * @param callback the callback to call when the user inputs something + * @throws IllegalArgumentException if the text or callback is null + */ + void input(@Nonnull String text, @Nonnull Consumer callback) throws IllegalArgumentException; + + /** + * Sends a message to the receiver and waits for an input. + * + * @param text the text to send + * @param instruction the instruction to send + * @param callback the callback to call when the user inputs something + * @throws IllegalArgumentException if the text, instruction or callback is null + */ + void input(@Nonnull String text, @Nonnull Instruction instruction, @Nonnull Consumer callback) + throws IllegalArgumentException; + + /** + * Checks if the receiver is currently in a chat input. + * + * @return true if the receiver is in a chat input, false otherwise + */ + @Contract(pure = true) + boolean isInChatInput(); + + /** + * Leaves the current chat input. + *

+ * If the receiver is not in a chat input, this method does nothing. + */ + void leaveChatInput(); +} diff --git a/src/main/java/minevalley/core/api/messaging/MessageReceiver.java b/src/main/java/minevalley/core/api/messaging/MessageReceiver.java index 6c4b10f..ea0df83 100644 --- a/src/main/java/minevalley/core/api/messaging/MessageReceiver.java +++ b/src/main/java/minevalley/core/api/messaging/MessageReceiver.java @@ -97,33 +97,6 @@ public interface MessageReceiver { */ void sendMessage(@Nonnull ComponentLike message, @Nonnull Instruction instruction) throws IllegalArgumentException; - /** - * Sends a message to the receiver. - * - * @param message the message to send - * @param menu the menu to send - * @return the menu that was sent - * @throws IllegalArgumentException if the message or menu is null - */ - @Nonnull - @Contract("_, _ -> new") - ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull ClickableOption... menu) - throws IllegalArgumentException; - - /** - * Sends a message to the receiver. - * - * @param message the message to send - * @param instruction the instruction to send - * @param menu the menu to send - * @return the menu that was sent - * @throws IllegalArgumentException if the message, instruction or menu is null - */ - @Nonnull - @Contract("_, _, _ -> new") - ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull Instruction instruction, - @Nonnull ClickableOption... menu) throws IllegalArgumentException; - /** * Sends a message to the receiver. * @@ -144,35 +117,6 @@ ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull Instruction instru void sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull Instruction instruction) throws IllegalArgumentException; - /** - * Sends a message to the receiver. - * - * @param type the type of message - * @param message the message to send - * @param menu the menu to send - * @return the menu that was sent - * @throws IllegalArgumentException if the type, message or menu is null - */ - @Nonnull - @Contract("_, _, _ -> new") - ChatMenu sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull ClickableOption... menu) - throws IllegalArgumentException; - - /** - * Sends a message to the receiver. - * - * @param type the type of message - * @param message the message to send - * @param instruction the instruction to send - * @param menu the menu to send - * @return the menu that was sent - * @throws IllegalArgumentException if the type, message, instruction or menu is null - */ - @Nonnull - @Contract("_, _, _, _ -> new") - ChatMenu sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull Instruction instruction, - @Nonnull ClickableOption... menu) throws IllegalArgumentException; - /** * Shows a title to the receiver. * diff --git a/src/main/java/minevalley/core/api/users/OnlineUser.java b/src/main/java/minevalley/core/api/users/OnlineUser.java index 6674b49..30691e9 100644 --- a/src/main/java/minevalley/core/api/users/OnlineUser.java +++ b/src/main/java/minevalley/core/api/users/OnlineUser.java @@ -3,6 +3,7 @@ import minevalley.core.api.audio.SoundReceiver; import minevalley.core.api.economy.AccountUser; import minevalley.core.api.economy.BankAccount; +import minevalley.core.api.messaging.DialogReceiver; import minevalley.core.api.messaging.MessageReceiver; import minevalley.core.api.messaging.instruction.Instruction; import minevalley.core.api.regions.utils.PlayerLocation; @@ -30,7 +31,7 @@ import java.util.function.Consumer; @SuppressWarnings("unused") -public interface OnlineUser extends User, MessageReceiver, SoundReceiver { +public interface OnlineUser extends User, DialogReceiver, MessageReceiver, SoundReceiver { /** * Gets the player object of this user. @@ -82,41 +83,6 @@ default void closeInventory() { player().closeInventory(); } - /** - * Sends a message to the receiver and waits for an input. - * - * @param text the text to send - * @param callback the callback to call when the user inputs something - * @throws IllegalArgumentException if the text or callback is null - */ - void input(@Nonnull String text, @Nonnull Consumer callback) throws IllegalArgumentException; - - /** - * Sends a message to the receiver and waits for an input. - * - * @param text the text to send - * @param instruction the instruction to send - * @param callback the callback to call when the user inputs something - * @throws IllegalArgumentException if the text, instruction or callback is null - */ - void input(@Nonnull String text, @Nonnull Instruction instruction, @Nonnull Consumer callback) - throws IllegalArgumentException; - - /** - * Checks if the receiver is currently in a chat input. - * - * @return true if the receiver is in a chat input, false otherwise - */ - @Contract(pure = true) - boolean isInChatInput(); - - /** - * Leaves the current chat input. - *

- * If the receiver is not in a chat input, this method does nothing. - */ - void leaveChatInput(); - /** * Gets whether this user is currently logged in via labymod. *