Class DefaultInterpreter

java.lang.Object
io.github.toberocat.guiengine.interpreter.DefaultInterpreter
All Implemented Interfaces:
GuiEvents, GuiInterpreter

public class DefaultInterpreter extends Object implements GuiInterpreter
DefaultInterpreter is an implementation of the GuiInterpreter interface that provides default interpretation and handling of GUI components defined in XML format.

Created: 05/02/2023 Author: Tobias Madlberger (Tobias)

  • Constructor Details

    • DefaultInterpreter

      public DefaultInterpreter()
  • Method Details

    • interpreterId

      @NotNull public @NotNull String interpreterId()
      Returns the identifier for this interpreter.
      Specified by:
      interpreterId in interface GuiInterpreter
      Returns:
      The identifier "default" for this interpreter.
    • getRenderEngine

      @NotNull public @NotNull DefaultGuiRenderEngine getRenderEngine()
      Retrieves the DefaultGuiRenderEngine used by this interpreter to render GUI components.
      Specified by:
      getRenderEngine in interface GuiInterpreter
      Returns:
      A new instance of DefaultGuiRenderEngine.
    • loadContent

      @NotNull public @NotNull GuiContext loadContent(@NotNull @NotNull GuiEngineApi api, @NotNull @NotNull org.bukkit.entity.Player viewer, @NotNull @NotNull XmlGui xmlGui)
      Loads the GUI content from the given XmlGui and creates a GuiContext with the associated components.
      Specified by:
      loadContent in interface GuiInterpreter
      Parameters:
      api - The GuiEngineApi instance used for interacting with the GUI engine.
      viewer - The Player who will view the GUI.
      xmlGui - The XmlGui instance representing the GUI layout.
      Returns:
      A GuiContext object representing the loaded GUI context.
    • createComponent

      @Nullable public @Nullable GuiComponent createComponent(@NotNull @NotNull XmlComponent xmlComponent, @NotNull @NotNull GuiEngineApi api, @NotNull @NotNull GuiContext context)
      Creates a GuiComponent from the given XmlComponent and binds it to the provided GuiEngineApi and GuiContext.
      Specified by:
      createComponent in interface GuiInterpreter
      Parameters:
      xmlComponent - The XmlComponent to create the GuiComponent from.
      api - The GuiEngineApi instance used for interacting with the GUI engine.
      context - The GuiContext in which the GuiComponent will be bound.
      Returns:
      The created GuiComponent instance, or null if creation failed.
      Throws:
      InvalidGuiComponentException - If the XmlComponent type is not recognized as a valid component.
    • bindComponent

      @NotNull public @NotNull GuiComponent bindComponent(@NotNull @NotNull GuiComponent component, @NotNull @NotNull GuiEngineApi api, @NotNull @NotNull GuiContext context)
      Binds a GuiComponent to the provided GuiEngineApi and GuiContext, and adds actions from the context's local actions.
      Specified by:
      bindComponent in interface GuiInterpreter
      Parameters:
      component - The GuiComponent to bind.
      api - The GuiEngineApi instance used for interacting with the GUI engine.
      context - The GuiContext to which the GuiComponent will be bound.
      Returns:
      The bound GuiComponent.
    • xmlComponent

      @NotNull public @NotNull XmlComponent xmlComponent(@NotNull @NotNull com.fasterxml.jackson.databind.JsonNode node, @NotNull @NotNull GuiEngineApi api) throws com.fasterxml.jackson.core.JsonProcessingException
      Converts a JsonNode to an XmlComponent using the provided GuiEngineApi.
      Specified by:
      xmlComponent in interface GuiInterpreter
      Parameters:
      node - The JsonNode to convert to XmlComponent.
      api - The GuiEngineApi instance used for converting the JsonNode.
      Returns:
      The converted XmlComponent.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If there is an issue processing the JsonNode.
    • componentToXml

      @NotNull public @NotNull XmlComponent componentToXml(@NotNull @NotNull GuiEngineApi api, @NotNull @NotNull GuiComponent component)
      Converts a GuiComponent to an XmlComponent using the provided GuiEngineApi.
      Specified by:
      componentToXml in interface GuiInterpreter
      Parameters:
      api - The GuiEngineApi instance used for converting the GuiComponent.
      component - The GuiComponent to convert to XmlComponent.
      Returns:
      The converted XmlComponent.