Package io.github.toberocat.guiengine
Class GuiEngineApi
java.lang.Object
io.github.toberocat.guiengine.GuiEngineApi
The `GuiEngineApi` class provides an API to manage and interact with graphical user interfaces (GUIs).
It allows you to register and manage various GUI components, load XML-based GUI definitions,
and display GUIs to players in the game.
This class is licensed under the GNU General Public License.
- Since:
- 05/02/2023
- Author:
- Tobias Madlberger (Tobias)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Map<String,
GuiEngineApi> static final @NotNull FileFilter
static final Pattern
static final @NotNull Map<UUID,
GuiContext> static final Map<String,
Class<? extends GuiComponent>> static final List<com.fasterxml.jackson.databind.module.SimpleModule>
-
Constructor Summary
ConstructorsConstructorDescriptionGuiEngineApi
(@NotNull String id, @NotNull File guiFolder) Constructs a new `GuiEngineApi` instance with the specified ID and GUI folder.GuiEngineApi
(@NotNull String id, @NotNull File guiFolder, @NotNull FileFilter guiFilter) Constructs a new `GuiEngineApi` instance with the specified ID, GUI folder, and GUI filter.GuiEngineApi
(@NotNull org.bukkit.plugin.java.JavaPlugin plugin) Constructs a new `GuiEngineApi` instance for the specified plugin. -
Method Summary
Modifier and TypeMethodDescriptionReturns the set of available GUI IDs within the GUI folder.@NotNull Map<String,
Class<? extends GuiComponent>> Returns the map of GUI component IDs and their associated classes for this `GuiEngineApi`.@NotNull FileFilter
Returns the GUI filter used to determine which files are considered GUI files.@NotNull DefaultGuiViewManager
Returns the `DefaultGuiViewManager` instance associated with this `GuiEngineApi`.@NotNull String
getId()
Returns the ID of this `GuiEngineApi` instance.@NotNull InterpreterManager
Returns the `InterpreterManager` instance associated with this `GuiEngineApi`.@NotNull com.fasterxml.jackson.databind.ObjectMapper
Returns the `ObjectMapper` used for XML serialization/deserialization of GUI components.@NotNull String
guiIdFromFile
(@NotNull File file) Converts a file into it's guiId.@NotNull XmlGui
loadXmlGui
(@NotNull Map<String, String> placeholders, @NotNull String guiId) Loads and returns the XML-based GUI definition with the specified ID, substituting the placeholders.@NotNull GuiContext
Opens a GUI with the specified ID for the given player, using the default placeholders.@NotNull GuiContext
openGui
(@NotNull org.bukkit.entity.Player player, @NotNull String guiId, @NotNull Map<String, String> placeholders) Opens a GUI with the specified ID for the given player, using the provided placeholders.<T extends GuiComponent,
B extends GuiComponentBuilder>
voidregisterFactory
(@NotNull String id, @NotNull Class<T> clazz, @NotNull Class<B> builderClazz) Registers a GUI component factory with the given ID, class, and builder class.static <T extends GuiComponent,
B extends GuiComponentBuilder>
voidregisterSharedFactory
(@NotNull String id, @NotNull Class<T> clazz, @NotNull Class<B> builderClazz) Registers a shared GUI component factory with the given ID, class, and builder class.void
reload()
Reloads the available GUIs from the GUI folder.
-
Field Details
-
APIS
-
LOADED_CONTEXTS
-
DEFAULT_GUI_FILTER
-
SHARED_MODULES
-
GUI_ID_REGEX
-
SHARED_COMPONENT_ID_MAPS
-
-
Constructor Details
-
GuiEngineApi
Constructs a new `GuiEngineApi` instance with the specified ID and GUI folder.- Parameters:
id
- The ID for this `GuiEngineApi` instance.guiFolder
- The folder where GUI files are stored.
-
GuiEngineApi
public GuiEngineApi(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin) throws IOException, URISyntaxException Constructs a new `GuiEngineApi` instance for the specified plugin. The ID will be automatically set to the plugin's name, and the gui folder will be the data-folder/guisThis has the advantage that GuiEngine automatically copies the guis folder from the resources
- Parameters:
plugin
- The plugin this API owns to- Throws:
IOException
URISyntaxException
-
GuiEngineApi
public GuiEngineApi(@NotNull @NotNull String id, @NotNull @NotNull File guiFolder, @NotNull @NotNull FileFilter guiFilter) Constructs a new `GuiEngineApi` instance with the specified ID, GUI folder, and GUI filter.- Parameters:
id
- The ID for this `GuiEngineApi` instance.guiFolder
- The folder where GUI files are stored.guiFilter
- The filter used to determine which files are considered GUI files.
-
-
Method Details
-
registerFactory
public <T extends GuiComponent,B extends GuiComponentBuilder> void registerFactory(@NotNull @NotNull String id, @NotNull @NotNull Class<T> clazz, @NotNull @NotNull Class<B> builderClazz) Registers a GUI component factory with the given ID, class, and builder class.- Type Parameters:
T
- The type of the GUI component.B
- The type of the GUI component builder.- Parameters:
id
- The ID of the GUI component factory.clazz
- The class representing the GUI component.builderClazz
- The class representing the GUI component builder.
-
reload
Reloads the available GUIs from the GUI folder.- Throws:
GuiIORuntimeException
- If there is an I/O error while loading or validating GUIs.
-
openGui
@NotNull public @NotNull GuiContext openGui(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String guiId) throws GuiNotFoundRuntimeException, GuiIORuntimeException Opens a GUI with the specified ID for the given player, using the default placeholders.- Parameters:
player
- The player to whom the GUI should be displayed.guiId
- The ID of the GUI to open.- Returns:
- The `GuiContext` representing the opened GUI.
- Throws:
GuiNotFoundRuntimeException
- If the specified GUI ID does not correspond to an existing GUI.GuiIORuntimeException
- If there is an I/O error while loading or rendering the GUI.
-
openGui
@NotNull public @NotNull GuiContext openGui(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String guiId, @NotNull @NotNull Map<String, String> placeholders) throws GuiNotFoundRuntimeException, GuiIORuntimeExceptionOpens a GUI with the specified ID for the given player, using the provided placeholders.- Parameters:
player
- The player to whom the GUI should be displayed.guiId
- The ID of the GUI to open.placeholders
- The map of placeholders to be substituted in the GUI content.- Returns:
- The `GuiContext` representing the opened GUI.
- Throws:
GuiNotFoundRuntimeException
- If the specified GUI ID does not correspond to an existing GUI.GuiIORuntimeException
- If there is an I/O error while loading or rendering the GUI.
-
loadXmlGui
@NotNull public @NotNull XmlGui loadXmlGui(@NotNull @NotNull Map<String, String> placeholders, @NotNull @NotNull String guiId) throws GuiNotFoundRuntimeException, GuiIORuntimeExceptionLoads and returns the XML-based GUI definition with the specified ID, substituting the placeholders.- Parameters:
placeholders
- The map of placeholders to be substituted in the GUI content.guiId
- The ID of the GUI to load.- Returns:
- The loaded `XmlGui` instance representing the GUI.
- Throws:
GuiNotFoundRuntimeException
- If the specified GUI ID does not correspond to an existing GUI.GuiIORuntimeException
- If there is an I/O error while loading the GUI.
-
guiIdFromFile
Converts a file into it's guiId. This takes the extension away and returns the part before- Parameters:
file
- The input file- Returns:
- The guiId of this file
-
getAvailableGuis
Returns the set of available GUI IDs within the GUI folder.- Returns:
- The set of available GUI IDs.
-
getInterpreterManager
Returns the `InterpreterManager` instance associated with this `GuiEngineApi`.- Returns:
- The `InterpreterManager` instance.
-
getGuiViewManager
Returns the `DefaultGuiViewManager` instance associated with this `GuiEngineApi`.- Returns:
- The `DefaultGuiViewManager` instance.
-
getXmlMapper
@NotNull public @NotNull com.fasterxml.jackson.databind.ObjectMapper getXmlMapper()Returns the `ObjectMapper` used for XML serialization/deserialization of GUI components.- Returns:
- The `ObjectMapper` instance for XML handling.
-
getGuiFilter
Returns the GUI filter used to determine which files are considered GUI files.- Returns:
- The `FileFilter` instance representing the GUI filter.
-
getComponentIdMap
Returns the map of GUI component IDs and their associated classes for this `GuiEngineApi`.- Returns:
- The map of GUI component IDs and their associated classes.
-
getId
Returns the ID of this `GuiEngineApi` instance.- Returns:
- The ID of this `GuiEngineApi` instance.