Class DefaultInterpreter
java.lang.Object
io.github.toberocat.guiengine.interpreter.DefaultInterpreter
- All Implemented Interfaces:
GuiEvents
,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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull GuiComponent
bindComponent
(@NotNull GuiComponent component, @NotNull GuiEngineApi api, @NotNull GuiContext context) Binds a GuiComponent to the provided GuiEngineApi and GuiContext, and adds actions from the context's local actions.@NotNull XmlComponent
componentToXml
(@NotNull GuiEngineApi api, @NotNull GuiComponent component) Converts a GuiComponent to an XmlComponent using the provided GuiEngineApi.@Nullable GuiComponent
createComponent
(@NotNull XmlComponent xmlComponent, @NotNull GuiEngineApi api, @NotNull GuiContext context) Creates a GuiComponent from the given XmlComponent and binds it to the provided GuiEngineApi and GuiContext.@NotNull DefaultGuiRenderEngine
Retrieves the DefaultGuiRenderEngine used by this interpreter to render GUI components.@NotNull String
Returns the identifier for this interpreter.@NotNull GuiContext
loadContent
(@NotNull GuiEngineApi api, @NotNull org.bukkit.entity.Player viewer, @NotNull XmlGui xmlGui) Loads the GUI content from the given XmlGui and creates a GuiContext with the associated components.@NotNull XmlComponent
xmlComponent
(@NotNull com.fasterxml.jackson.databind.JsonNode node, @NotNull GuiEngineApi api) Converts a JsonNode to an XmlComponent using the provided GuiEngineApi.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.toberocat.guiengine.event.GuiEvents
clickedComponent, closedComponent, draggedComponent, onViewInit
-
Constructor Details
-
DefaultInterpreter
public DefaultInterpreter()
-
-
Method Details
-
interpreterId
Returns the identifier for this interpreter.- Specified by:
interpreterId
in interfaceGuiInterpreter
- Returns:
- The identifier "default" for this interpreter.
-
getRenderEngine
Retrieves the DefaultGuiRenderEngine used by this interpreter to render GUI components.- Specified by:
getRenderEngine
in interfaceGuiInterpreter
- 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 interfaceGuiInterpreter
- 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 interfaceGuiInterpreter
- 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 interfaceGuiInterpreter
- 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 interfaceGuiInterpreter
- 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 interfaceGuiInterpreter
- Parameters:
api
- The GuiEngineApi instance used for converting the GuiComponent.component
- The GuiComponent to convert to XmlComponent.- Returns:
- The converted XmlComponent.
-