Class FunctionProcessor

java.lang.Object
io.github.toberocat.guiengine.function.FunctionProcessor

public class FunctionProcessor extends Object
Utility class for processing and handling GUI functions.

Created: 29.04.2023 Author: Tobias Madlberger (Tobias)

  • Field Details

    • FUNCTIONS

      public static final Map<String,Class<? extends GuiFunction>> FUNCTIONS
    • COMPUTE_FUNCTIONS

      public static final Set<ComputeFunction> COMPUTE_FUNCTIONS
    • OBJECT_MAPPER

      public static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
  • Constructor Details

    • FunctionProcessor

      public FunctionProcessor()
  • Method Details

    • registerFunction

      public static void registerFunction(@NotNull @NotNull String id, @NotNull @NotNull Class<? extends GuiFunction> clazz)
      Registers a custom GUI function.
      Parameters:
      id - The ID of the function.
      clazz - The class implementing the custom GUI function.
    • registerComputeFunction

      public static void registerComputeFunction(@NotNull @NotNull ComputeFunction computeFunction)
      Registers a custom compute function.
      Parameters:
      computeFunction - The custom compute function to register.
    • createFunction

      @Nullable public static @Nullable GuiFunction createFunction(@NotNull @NotNull com.fasterxml.jackson.databind.JsonNode node) throws com.fasterxml.jackson.core.JsonProcessingException
      Creates a GUI function from a JSON node.
      Parameters:
      node - The JSON node containing the function information.
      Returns:
      The created `GuiFunction` instance, or null if the function could not be created.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If there is an issue with processing the JSON node.
    • callFunctions

      public static void callFunctions(@NotNull @NotNull Collection<GuiFunction> functions, @NotNull @NotNull GuiEngineApi api, @NotNull @NotNull GuiContext context)
      Calls a collection of GUI functions with the specified API and context.
      Parameters:
      functions - The collection of GUI functions to call.
      api - The `GuiEngineApi` instance used to interact with the GUI engine.
      context - The `GuiContext` instance representing the GUI context on which the functions are called.
    • applyFunctions

      @NotNull public static @NotNull String applyFunctions(@NotNull @NotNull GuiEngineApi api, @NotNull @NotNull GuiContext context, @NotNull @NotNull String value)
      Applies to compute functions to the provided value, replacing placeholders with their computed values.
      Parameters:
      api - The `GuiEngineApi` instance used to interact with the GUI engine.
      context - The `GuiContext` instance representing the GUI context for which the computation is performed.
      value - The input value containing placeholders to compute.
      Returns:
      The computed value with placeholders replaced by their computed values.