🧬
Metadata
View how to use Metadata in Menus.
Relevant Classes: Menu​
​MenuItem​
​MenuData​
​
Metadata allows you to define key-value data in a Menu. This allows you to retrieve information that can be changed or removed.
Metadata is primarily useful for allowing external modification via a configuration file. For example, allowing a user to define a custom message.
Did you know? You can define Metadata on Menus and Menu Items!

Examples

Configuration
Code
Metadata keys must be spelled case-sensitive to be recognized.
​
For Metadata to be defined in a configuration file, it must defined on a valid Menu or Menu Item.
​
​
Example-Menu:
Title: "&eExample Menu"
Size: 9
# This is the list of meta data for the Menu
Metadata:
Example-Message: "&aHello there!"

​

​
Example-Item:
Slot: 0
Material: "GRAY_STAINED_GLASS_PANE"
Name: "&cExample"
Lore:
- "&7Example Item"
- ""
- "&aSecond Line"
# This is the list of meta data for the Menu Item
Metadata:
Example-Message: "&aHello there!"
​
This allows the Developer to retrieve information the user can actively modify. Without needing to rewrite portions of the Menu code.
It's currently known that Metadata returns String for MenuItem and Object for Menu. This will change in a future update!
Adding Metadata to an item via code is easy, and familiar!

​

Adding Metadata

Menu menu;
​
menu.getData().getMetaData().put("Example-Key", "Value");
​
MenuItem item;
​
item.getMetaData().put("Example-Key", "Value");
​

Retrieving Metadata

Menu menu;
​
Object data = menu.getData().getMetaData().get("Example-Key");
​
MenuItem item;
​
String value = item.getMetaData().get("Example-Key");
​
That's it! That's how easy it is to add and retrieve Metadata from a Menu & Menu Item!
Last modified 7mo ago
Copy link