Class CoderyoGUIAPI

java.lang.Object
com.coderyo.coderyogui.api.CoderyoGUIAPI

public class CoderyoGUIAPI extends Object
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 Details

    • init

      public static void init(CoderyoGUI plugin)
      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

      public static CoderyoGUIAPI getInstance()
      Gets the singleton instance of the API.
      Returns:
      The API instance.
      Throws:
      IllegalStateException - if the API is not initialized.
    • createGUI

      public boolean createGUI(String name, int rows)
      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

      public boolean setGUIRows(String name, int rows)
      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

      public boolean addPage(String name, int pageId)
      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

      public boolean removePage(String name, int pageId)
      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

      public boolean setItem(String name, int pageId, int slot, GUIItem item)
      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

      public boolean removeItem(String name, int pageId, int slot)
      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

      public boolean setPageInteractable(String name, int pageId, boolean allowInteract)
      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

      public boolean deleteGUI(String name)
      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

      public boolean openGUI(org.bukkit.entity.Player player, String name, int pageId)
      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

      public CustomGUI getGUI(String name)
      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

      public Set<String> listGUIs()
      Lists the names of all existing GUIs.
      Returns:
      An unmodifiable set of GUI names.