Package com.coderyo.coderyogui.api
Class CoderyoGUIAPI
java.lang.Object
com.coderyo.coderyogui.api.CoderyoGUIAPI
The main API for interacting with the CoderyoGUI plugin, providing methods to
create, modify, delete, and open custom graphical user interfaces (GUIs) in a
Minecraft server.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a new page to the specified GUI.booleanCreates a new GUI with the specified name and number of rows.booleanDeletes a GUI from the system.Retrieves a read-only copy of a GUI's data.static CoderyoGUIAPIGets the singleton instance of the API.static voidinit(CoderyoGUI plugin) Initializes the API with the given plugin instance.listGUIs()Lists the names of all existing GUIs.booleanOpens a specific page of a GUI for a player.booleanremoveItem(String name, int pageId, int slot) Removes an item from a specific slot on a GUI page.booleanremovePage(String name, int pageId) Removes a page from the specified GUI.booleansetGUIRows(String name, int rows) Updates the number of rows for an existing GUI.booleanSets an item in a specific slot on a GUI page.booleansetPageInteractable(String name, int pageId, boolean allowInteract) Sets whether a GUI page allows player interactions (e.g., taking items).
-
Method Details
-
init
Initializes the API with the given plugin instance. This method must be called by the CoderyoGUI plugin during its enable phase.- Parameters:
plugin- The CoderyoGUI plugin instance.
-
getInstance
Gets the singleton instance of the API.- Returns:
- The API instance.
- Throws:
IllegalStateException- if the API is not initialized.
-
createGUI
Creates a new GUI with the specified name and number of rows.- Parameters:
name- The unique name of the GUI (1-32 characters, non-null, non-empty).rows- The number of rows in the GUI (1-6).- Returns:
- true if the GUI was created successfully, false if the name is invalid, rows are out of range, or the GUI already exists.
-
setGUIRows
Updates the number of rows for an existing GUI.- Parameters:
name- The name of the GUI to modify.rows- The new number of rows (1-6).- Returns:
- true if the rows were updated successfully, false if the GUI does not exist or rows are out of range.
-
addPage
Adds a new page to the specified GUI.- Parameters:
name- The name of the GUI.pageId- The ID of the new page (positive integer, must not already exist).- Returns:
- true if the page was added successfully, false if the GUI does not exist or the pageId is invalid or already exists.
-
removePage
Removes a page from the specified GUI. The GUI must retain at least one page.- Parameters:
name- The name of the GUI.pageId- The ID of the page to remove.- Returns:
- true if the page was removed successfully, false if the GUI does not exist, the pageId does not exist, or it is the last page.
-
setItem
Sets an item in a specific slot on a GUI page.- Parameters:
name- The name of the GUI.pageId- The ID of the page.slot- The slot index (9 to rows * 9 - 1).item- The GUIItem to place (non-null).- Returns:
- true if the item was set successfully, false if the GUI, page, or slot is invalid, or the item is null.
-
removeItem
Removes an item from a specific slot on a GUI page.- Parameters:
name- The name of the GUI.pageId- The ID of the page.slot- The slot index (9 to rows * 9 - 1).- Returns:
- true if the item was removed successfully, false if the GUI, page, or slot is invalid.
-
setPageInteractable
Sets whether a GUI page allows player interactions (e.g., taking items).- Parameters:
name- The name of the GUI.pageId- The ID of the page.allowInteract- true to allow interactions, false to prevent them.- Returns:
- true if the interactability was set successfully, false if the GUI or page does not exist.
-
deleteGUI
Deletes a GUI from the system.- Parameters:
name- The name of the GUI to delete.- Returns:
- true if the GUI was deleted successfully, false if the GUI does not exist.
-
openGUI
Opens a specific page of a GUI for a player.- Parameters:
player- The player to open the GUI for (non-null).name- The name of the GUI.pageId- The ID of the page to open.- Returns:
- true if the GUI was opened successfully, false if the player, GUI, or page is invalid.
-
getGUI
Retrieves a read-only copy of a GUI's data.- Parameters:
name- The name of the GUI.- Returns:
- A read-only CustomGUI object, or null if the GUI does not exist.
-
listGUIs
Lists the names of all existing GUIs.- Returns:
- An unmodifiable set of GUI names.
-