-
Notifications
You must be signed in to change notification settings - Fork 0
MenuManager
timsixth edited this page Aug 8, 2023
·
3 revisions
You don't have to configure manager if you use InMemoryMenuManager (default).
If do you want to use YAMLMenuManger you must extend by this class.
public class MenuManager extends YAMLMenuManager {
private final ConfigFile configFile; //inject ConfigFile or other class where you have initialized files.
//You can use config.yml, to do that inject your main class, but I don't recommend to use config.yml.
public MenuManager(ActionRegistration actionRegistration, ConfigFile configFile) {
super(actionRegistration);
this.configFile = configFile; //init your config class in constructor
}
@Override
public void load() {
load(configFile.getYmlGuis()); //load your file. The method expects YamlConfiguration.
}
}
Override two methods 'enableSectionActions' and 'addSectionActions'
@Override
public boolean enableSectionActions() {
return true; //false to disable, section actions are disabled by default
}
@Override
protected void addSectionActions(ConfigurationSection slotSection, MenuItem menuItem, ClickAction action) {
ConfigurationSection clickActionSection = slotSection.getConfigurationSection("click_action"); //get action section from YAML
if (action instanceof GiveItemsAction) { //checks instance of action
ClickAction giveItemsClickAction = setItemsToGive(clickActionSection);
menuItem.setAction(giveItemsClickAction); //set this action
}
}