TriggerReactor

TriggerReactor

24.6k Downloads

Adding set title function to InventoryTrigger

RookieAND opened this issue ยท 8 comments

commented

There's only one way to change inventory's title (by changing file's name) when InventoryTrigger has been called.
So I think it's better to add title option to set Inventory's title before InventoryTrigger is loaded.

commented

We can set the title of the inventory in the following ways:

public IInventory openGUI(IPlayer player, String name) {
    InventoryTrigger trigger = get(name);
    if (trigger == null)
        return null;


                    /* Changed Part - START*/
    String title = trigger.getInfo().getConfig().get(TITLE, String.class).orElse(name);

    IInventory inventory = createInventory(trigger.getItems().length, title); 
                    /* Changed Part - END */


    inventoryMap.put(inventory, trigger);

    Map<String, Object> varMap = new HashMap<>();
    varMap.put("inventory", inventory.get());
    inventorySharedVars.put(inventory, varMap);

    fillInventory(trigger, trigger.getItems().length, inventory);

    player.openInventory(inventory);

    return inventory;
}

@wysohn

commented

We can set the title of the inventory in the following ways:

public IInventory openGUI(IPlayer player, String name) {
    InventoryTrigger trigger = get(name);
    if (trigger == null)
        return null;


                    /* Changed Part - START*/
    String title = trigger.getInfo().getConfig().get(TITLE, String.class).orElse(name);

    IInventory inventory = createInventory(trigger.getItems().length, title); 
                    /* Changed Part - END */


    inventoryMap.put(inventory, trigger);

    Map<String, Object> varMap = new HashMap<>();
    varMap.put("inventory", inventory.get());
    inventorySharedVars.put(inventory, varMap);

    fillInventory(trigger, trigger.getItems().length, inventory);

    player.openInventory(inventory);

    return inventory;
}

@wysohn

Looking good to me!

Why not open a PR for that? That would help all of us!

commented

It's simply because I didn't know how to use GitHub. I'm going to open a PR soon.

commented

I truly appreciate to add this feature. I can't wait for it!

commented

It's simply because I didn't know how to use GitHub. I'm going to open a PR soon.

Practice makes perfect

And neither I know everything about git. Google search is your friend :p

commented

There seems to be a way to do this with the packets, yet it will have to send all the contents of the inventory again.

https://www.spigotmc.org/threads/how-to-set-the-title-of-an-open-inventory-itemgui.95572/

maybe we can have good use of the protocollib support we have right now, so we can optionally support such function only when protocollib is available.

I would suggest doing this in Executor

commented

Why don't you close this issue?
because this issue resolved at #423

commented

Why don't you close this issue? because this issue resolved at #423

Oh it has to close itself but I guess it was linked to the different PR