Skip to content

Commit

Permalink
introduce DialogReceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier committed Jan 31, 2025
1 parent 367d1a9 commit 764e6d2
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 92 deletions.
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

0 comments on commit 764e6d2

Please sign in to comment.