Skip to content
WolfyScript edited this page Apr 15, 2021 · 8 revisions

CustomCache

You'll see that many components part of the InventoryAPI are using the CustomCache object.
It allows to cache data for players, which might be important for the functionality of your GUI.
For each player, the API will create a new CustomCache instance.

By default, the CustomCache class doesn't contain lots of flexibility, so for more advanced usage, you should create your own class.

public class YourCache extends CustomCache {
    
    public CCCache() {
        super();
    }   

}

And then set your class to the InventoryAPI. (Best in your plugins constructor!)

api.setInventoryAPI(new InventoryAPI<>(plugin, api, YourCache.class));

Structure

The GUI API follows a structure to make it consistent as possible and easily manageable.

It has the following main parts:

  • InventoryAPI - contains all of the data and is the parent of everything.
  • GuiCluster - a cluster of multiple GuiWindows.
  • GuiWindow - a window that contains all the logic and buttons to render the items into the Inventory.

InventoryAPI

You can get the instance via the WolfyUtilities object.
If you use the default CustomCache you need to use InventoryAPI<CustomCache> else InventoryAPI<YourCache>. Same for every object that requires the cache type.

//For default cache
InventoryAPI<CustomCache> invAPI = api.getInventoryAPI(CustomCache.class);

//For your custom cache
InventoryAPI<YourCache> invAPI = api.getInventoryAPI(YourCache.class);

GuiCluster

They contain multiple GuiWindows and Buttons. To create a GuiCluster you need to create a class that extends it.

public class YourCluster extends GuiCluster<YourCache> {

    public YourCluster (InventoryAPI<YourCache> inventoryAPI, String id) {
        super(inventoryAPI, id);
    }

    @Override
    public void onInit() {
        //Called on initialization! Used to register GuiWindows and Buttons.
        registerWindow();
        registerButton();
    }

}

GuiWindow

They contain local Buttons and manage the logic to render the Buttons into the inventory. They are very similar to the GuiCluster and you need to create a class and extend it.

public class YourWindow extends GuiWindow<YourCache> {

    public YourWindow(GuiCluster<YourCache> guiCluster, String key, int size) {
        super(guiCluster, key, size);
    }

    @Override
    public void onInit() {
        //Called on initialization. Used to register Buttons.
        registerButton();
    }

    @Override
    public void onUpdateSync(GuiUpdate<YourCache> guiUpdate) {
        //Updated sync
    }

    @Override
    public void onUpdateAsync(GuiUpdate<YourCache> update) {
        //Updated async
    }

}

| Home

| GUIs

| NBT Tools

Clone this wiki locally