Class Input

java.lang.Object
dev.crafty.core.util.Input

public class Input extends Object
Utility class for collecting input from players using SignGUI. Provides methods to collect simple string inputs and typed inputs with validation.
  • 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 from
      title - The title of the SignGUI
      prompt - The initial prompt text in the SignGUI
      plugin - The CraftyPlugin instance for the SignGUI
      parser - A function to parse the input string into the desired type
      validator - A predicate to validate the parsed input
      errorMessage - The error message to display if validation fails

      Example 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
           }
       });