SamJakob / SpiGUI

A comprehensive GUI API for Spigot with pages support.
MIT License
110 stars 22 forks source link

No items in close event #16

Closed NotroDev closed 2 years ago

NotroDev commented 2 years ago

Hi.

This code:

addingMenu.setOnClose(event ->
{
    p.getInventory().setContents(event.getInventory().getContents());
});

clears my inventory, because getInventory in this event is empty... Can i somehow get it contents? Or maybe this is just wrong?

SamJakob commented 2 years ago

What exactly are you trying to achieve with this?

NotroDev commented 2 years ago

What exactly are you trying to achieve with this?

I have a GUI to put items in, then I want to save them, for example to the ItemStack list

PS. And, let me add that I need to configure the page buttons, e.g. replace icons or text, could you add that? I think I can do it manually by editing getInventory(), but it would be appreciated anyway.

NotroDev commented 2 years ago

PS. And, let me add that I need to configure the page buttons, e.g. replace icons or text, could you add that? I think I can do it manually by editing getInventory(), but it would be appreciated anyway. obraz

Ah, okay, sorry!

// Idk how to use it xd

NotroDev commented 2 years ago

Okay, items in close event solved - i've used bukkit event. But now, i can't make this work:

SGPaginationButtonBuilder builder = Main.instance.spiGUI.getDefaultPaginationButtonBuilder();
builder.buildPaginationButton(SGPaginationButtonType.CURRENT_BUTTON, shopMenu).setIcon(new ItemBuilder(Material.EMERALD).build());

shopMenu.setPaginationButtonBuilder(builder);
SamJakob commented 2 years ago

Okay, items in close event solved - i've used bukkit event. But now, i can't make this work:

SGPaginationButtonBuilder builder = Main.instance.spiGUI.getDefaultPaginationButtonBuilder();
builder.buildPaginationButton(SGPaginationButtonType.CURRENT_BUTTON, shopMenu).setIcon(new ItemBuilder(Material.EMERALD).build());

shopMenu.setPaginationButtonBuilder(builder);

buildPaginationButton is used internally by SpiGUI to render the pagination buttons, you wouldn't usually call it as you are here.

What you would instead do is create your own SGPaginationButtonBuilder, similar to the way SpiGUI does it internally and then use setPaginationButtonBuilder to use your created pagination button builder instead.

For any buttons you don't want to override (let's say you're only overriding CURRENT_BUTTON, you could use the default instead by simply calling Main.instance.spiGUI.getDefaultPaginationButtonBuilder().buildPaginationButton inside your own pagination builder (e.g., in the default block of the switch/case).

Overall this API is a bit of a mess and won't even let you add new buttons - you can only override existing ones which is a bit of a silly oversight on my part. I will try and work on fixing it today if I have time.

SamJakob commented 2 years ago

Will also double check onClose functionality.

NotroDev commented 2 years ago

Thanks, it's working perfectly.