Inputs
Description
The askForInput
function is a utility method that allows you to prompt a player for input in a GUI. It adds the player to a list of players waiting for input, closes their current inventory, and sends them a message requesting input. The function returns a CompletableFuture<String>
that will be completed with the player's response once they have entered it.
The function uses a CompletableFuture
to handle the asynchronous nature of player input. It continuously checks for the player's response in a loop until it is received, sleeping for 1 millisecond between each check. Once the response is received, the CompletableFuture
is completed with the response.
How to use
You can use the askForInput
function to prompt a player for input and receive the response as a CompletableFuture<String>
. The function takes two parameters:
player
: ThePlayer
object representing the player you want to prompt.request
: The message you want to display to the player as the input request.
Here is an example of how to use the askForInput
function in Kotlin:
In this example, we create a GUI with a button that, when clicked, prompts the player to enter their name. The response is then displayed to the player in a chat message.
Summary
The askForInput
function is a useful utility method for handling player input in a GUI. It allows you to prompt players for input and receive their responses asynchronously, making it easy to create interactive and engaging user interfaces in your Minecraft plugin or mod.