Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement DialogReceiver #295

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions src/main/java/minevalley/core/api/messaging/DialogReceiver.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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.
* <p>
* If the receiver is not in a chat input, this method does nothing.
*/
void leaveChatInput();
}
56 changes: 0 additions & 56 deletions src/main/java/minevalley/core/api/messaging/MessageReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
38 changes: 2 additions & 36 deletions src/main/java/minevalley/core/api/users/OnlineUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<String> 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<String> 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.
* <p>
* 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.
* <br>
Expand Down