Developer API
Use the Command Panels API to make GUIs easily for your plugin or to interact with Command Panels.

API Methods

Introduction

Command Panels allows you to add it as a dependency in order to create GUIs for your plugin. Using either a File Object (Recommended) or a YamlConfiguration for the panel, you can save a YML file within your plugin and then use it for a GUI. The file which would be a YML file or the YamlConfiguration needs to follow the same syntax as any other panel. Its location for storing the panel, however, does not need to be in the panels folder, as it would instead be located within the code of your own plugin. If you then wanted to use your own code when an item was clicked, you would use the event= <message> tag as a command in the YAML of the item, which would cause the item to trigger the PanelCommandEvent event, meaning you can just make a listener for that event, then checking to ensure the message is equal to what you used in the item.
1
//Getting the Command Panels API
2
CommandPanelsAPI api = CommandPanels.getAPI();
Copied!
After you initialise the API using the above line of code, you will have access to the following methods
Method
Returns
Description
api.isPanelOpen(Player p);
Boolean
Check if a player has a panel open.
api.getOpenPanel(Player p, PanelPosition position);
Panel
Get the Panel Object of a currently opened panel for a player. PanelPosition is Top, Middle, Bottom of the inventory area. (Chest, Player, Hotbar)
api.getPanelsLoaded();
List<Panel>
Get the Panels loaded in the CommandPanels plugin.
api.addPanel(Panel panel);
-
Add a panel to the CommandPanels loaded plugins.
api.makeItem(ConfigurationSection item)
ItemStack
Get the configuration section of an item, for example the section of an item in a panel. Then the plugin will make a custom item and return the ItemStack.
api.removePanel(Panel panel);
-
Remove a panel from the CommandPanels loaded plugins.
api.hasNormalInventory(Player p);
boolean
Returns false if the player's inventory has a panel in it and is not the normal inventory.
api.getPanel(String panelName);
Panel
Get a loaded panel using the name of the panel.

If an item slot is a Stationary item

Command Panels may have items in the inventory in certain slots that are allocated to opening a panel when clicked, they cannot be moved. The following function will return an int ArrayList of the slots that are being used for Command Panels. 0-8 is for the Hotbar and 9-33 is for inside the inventory.
1
CommandPanelsAPI api = CommandPanels.getAPI();
2
api.getHotbarItems();
Copied!

Dealing with Panels

Panels are objects that can be created. There are numerous things you can do with a panel once one has been created.

Make a Panel

To make a panel, get a File or a YamlConfiguration of the panel. A File is recommended as they can be used to be added into the loaded panels in Command Panels.
1
File file = new File("panel.yml");
2
String panelName = "example";
3
Panel panel = new Panel(file, panelName);
Copied!

Panel Methods

General
Getting Values
Setting Values
Method
Returns
Description
panel.open(Player p, PanelPosition position);
-
Open a panel for the player. Ensure a panel isn't already open. Use the top panel position if there isn't already a panel open for the player.
panel.getHotbarItem(Player p)
ItemStack
Get the panels Hotbar Item
panel.hasHotbarItem()
Boolean
Check to see if the panel has a Hotbar Item
panel.getInventory()
Inventory
Get the panel as a plain inventory.
panel.getCustomItem(Player p, String itemName)
ItemStack
Get one of the panels Custom Items.
panel.getItem(Player p, int slot)
ItemStack
Get one of the items from inside the panel, depending on the slot.
Method
Returns
Description
panel.getName()
String
Get the panels name.
panel.getConfig()
ConfigurationSection
Get the panels ConfigurationSection.
panel.getFile()
File
Get the panel file.
Method
Returns
Description
panel.setName(String name);
-
Set a new name for the panel.
panel.setFile(File file);
-
Set a new file for the panel.
panel.setConfig(ConfigurationSection config);
-
Set a new config for the panel.

If a player has a panel open

If you want to check if a player has a panel open, you will first have to assign the API to a variable and then you may use the API. See the following examples.
The example below will return true if a certain player has any panel open, otherwise, it will return false.
1
CommandPanelsAPI api = CommandPanels.getAPI();
2
api.isPanelOpen(Player p);
Copied!
The example below will return a panel object, you can see what panel the player has open with this. It gives you access to see everything inside of the panel, where it is stored and even allow you to open the panel again.
1
CommandPanelsAPI api = CommandPanels.getAPI();
2
api.getPanel(Player p);
Copied!

API Events

PanelOpenedEvent

This event is called when a panel is opened. Below is an example class with the event inside of it. There are a variety of functions you can use, such as cancelling the event which will stop the panel from opening.
1
public class Utils implements Listener {
2
@EventHandler
3
public void onPanelOpen(PanelOpenedEvent e){
4
//do stuff here
5
}
Copied!
e.getPlayer(); Get the player who opened a panel.
e.getPanelName(); Returns the panel name that is being opened, as a String.
e.getPanel.getConfig(); This will return a ConfigurationSection containing the panels settings. for example if you want to get the title of the panel you would find it like this: e.getPanel.getConfig().getString("title").
e.isCancelled() is the event cancelled.
e.setCancelled() Cancel the event if you don't want the panel to open.

PanelClosedEvent

This event is called when a panel is closed. Below is an example class with the event inside of it. There are a variety of functions you can use.
1
public class Utils implements Listener {
2
@EventHandler
3
public void onPanelClose(PanelClosedEvent e){
4
//do stuff here
5
}
Copied!
e.getPlayer(); Get the player who opened a panel.
e.getPanelName(); Returns the panel name that is being opened, as a String.
e.getPanel.getConfig(); This will return a ConfigurationSection containing the panels settings. for example if you want to get the title of the panel you would find it like this: e.getPanel.getConfig().getString("title").

PanelCommandEvent

This event is called if the command tagevent= <message>is used in a panel. Below is an example class with the event inside of it. This will allow you to view the arguments/message that was left from inside the panel.
1
public class Utils implements Listener {
2
@EventHandler
3
public void onPanelCommand(PanelCommandEvent e){
4
//do stuff here
5
}
Copied!
e.getPlayer(); Get the player who opened a panel.
e.getMessage(); Returns the message left after the command tag as a String.