Skip to content

MenuManager

timsixth edited this page Aug 8, 2023 · 3 revisions

Getting started

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.

Configure MenuManager

ConfigFile: https://github.com/timsixth/T-GuiApi/blob/main/example-plugin/src/main/java/pl/timsixth/guilibrary/example/config/ConfigFile.java

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.
    }
}

How to setup section actions?

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
        }
    }
Clone this wiki locally