Package dev.crafty.core.util
Class Input
java.lang.Object
dev.crafty.core.util.Input
Utility class for collecting input from players using SignGUI.
Provides methods to collect simple string inputs and typed inputs with validation.
- Since:
- 1.0.30
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CompletableFuture
<String> collect
(org.bukkit.entity.Player player, String title, String prompt, CraftyPlugin plugin) Collects a string input from a player using SignGUI.static <T> CompletableFuture
<T> collectTyped
(org.bukkit.entity.Player player, String title, String prompt, CraftyPlugin plugin, Function<String, T> parser, Predicate<T> validator, String errorMessage) Collects an input of a specified type from a player using SignGUI.
-
Constructor Details
-
Input
public Input()
-
-
Method Details
-
collect
public static CompletableFuture<String> collect(org.bukkit.entity.Player player, String title, String prompt, CraftyPlugin plugin) Collects a string input from a player using SignGUI. Returns a CompletableFuture that completes with the input, or null if closed/cancelled. -
collectTyped
public static <T> CompletableFuture<T> collectTyped(org.bukkit.entity.Player player, String title, String prompt, CraftyPlugin plugin, Function<String, T> parser, Predicate<T> validator, String errorMessage) Collects an input of a specified type from a player using SignGUI. The input is validated using the provided predicate. If invalid, the GUI reopens with an error message. Returns a CompletableFuture that completes with the valid input, or null if closed/cancelled.- Type Parameters:
T
- The type of the input to collect- Parameters:
player
- The player to collect input fromtitle
- The title of the SignGUIprompt
- The initial prompt text in the SignGUIplugin
- The CraftyPlugin instance for the SignGUIparser
- A function to parse the input string into the desired typevalidator
- A predicate to validate the parsed inputerrorMessage
- The error message to display if validation failsExample usage:
Input.collectTyped( player, "Enter Number", "Number here", plugin, Integer::parseInt, i -> i > 0, "Please enter a valid positive number" ).thenAccept(number -> { if (number != null) { // Handle number } });
-