v3 KamiMenuLoader - Jake-Moore/KamiCommon GitHub Wiki
See V4 Getting Started for more information.
The gui/menu feature is only available in spigot-jar
.
This wiki page will describe the format for loading a KamiMenu
from a configuration file.
This loading process is dividing into a few classes with their respective responsibilities.
See GUI-System#MenuSize for information on this class.
A MenuSize
is loaded via the keys: type
or rows
or row
.
If using type
, the string should match a known InventoryType
name. The type
field has loading priority over the rows.
type: HOPPER
rows: 3
The MenuSizeLoader
class will attempt to inform console with information about failures, specifically when a type is invalid, or the row count out of bounds.
See ItemBuilder Config Format for details on how items get loaded.
The MenuItemLoader
class is responsible for loading an ItemBuilder and then wrapping it into a MenuItem
with additional properties.
# This example aims to show all available properties that can be configured.
# Note, the bulk of the loading logic comes from IBuilder
myMenuItem:
# These properties get loaded by IBuilder
# This key can be any of: `material`, `materials`, `type`, `types`
materials: [DIAMOND, EMERALD]
name: "&6My Item"
lore: []
amount: 64
# These fields are specific to MenuItem
enabled: true # If the item is enabled (should be placed in the menu)
hideAttributes: true # Should we hide item attributes
typeCycleTicks: 20 # If multiple materials are configured, how many ticks between cycling
# Slot configuration can be one of two types:
# Note: only one of these should be configured, not both
# Regular slot(s) -> an Integer or Integer List
slot: [1, 2]
# Last Row Slot -> an Integer
slotInLastRow: 4
This is the primary class for loading a KamiMenu
from a configuration file. It utilizes the above loaders to load individual sections of the configuration.
Every sub-key in the icons
section in the menu will be loaded as a MenuItem
where its ID is set to the config key.
This means that a KamiMenu
loaded from a config can have click events added via the config keys.
This is a basic example of a full menu configuration.
myMenu:
# Options loaded by KamiMenuLoader
title: "&6My Menu"
# The next keys are loaded by MenuSize, and can vary by menu
# This could be swapped out with a type key
rows: 6
# All keys under this icons section will be loaded as MenuItems
icons:
diamond:
material: DIAMOND
name: "&6Diamond"
slot: 0
emerald:
material: EMERALD
name: "&aEmerald"
slot: 1
exit:
material: BARRIER
name: "&cExit"
slotInLastRow: 4
KamiMenu menu = KamiMenuLoader.loadMenu(config, "myMenu");
menu.setMenuClick("diamond", (plr, click) -> {
// Do something with the diamond
});
menu.setMenuClick("emerald", (plr, click) -> {
// Do something with the diamond
});
menu.setMenuClick("exit", (plr, click) -> {
plr.closeInventory();
});
// Don't forget to open the menu for the player!
menu.openMenu(player);