Making item unclickable in inventory GUI?

Hi again, I’m kinda spamming this website out. Sorry for that!

I have successfully created a GUI inventory that is opened by a command. But I don’t want players to be able to grab the items from the GUI and place it in their inventory.
What is the easiest way to solve this?

There are many inventory-events you can listen to…
I have never tried this, but my first idea would be to listen to AffectSlotEvent and invalidate all transactions that affect slots from your gui-inventory. :slight_smile:

That kind of helped me, I still don’t really know how to prevent the click from happening though ¯_(シ)_/¯
Like, how would that look code-wise?

Im confused on what your struggling with? Check that the event occured on the slot that the item that you dont want moving is on, if so cancel the event.

Are you struggling with events in general? Getting it so the event applies to only your custom inventory? Getting the slot pos of the slot in question? Cancelling the event?

I’d probably say all of the above except for getting the slot, I’m super new to this kind of stuff and I can’t find anything that helps me online.

Try this for information to help you. Its the official Sponge Docs on creating a plugin.

With custom inventories, there is a really easy way to handle events for that inventory. In the inventory builder you can do this.

inventory.builder().listener(AffectSlotEvent.class, event -> {
  //Code for when the event fires on the build inventory the builder provides
  //This gets around needing to check the event for if its your inventory

As for cancelling the event, its as simple as this


This worked fantastically! Thank you dearly!

1 Like

The website is for help with sponge. You need help with sponge. Therefore, you are using the site for its intended purpose.
However, if you still feel bad, you can always join us on Discord.