DevNatan / inventory-framework

Minecraft Inventory API framework
MIT License
117 stars 21 forks source link

click.closeForPlayer(): Container is not available in current context [Bukkit 1.8.9] #651

Open sqlongithub opened 2 months ago

sqlongithub commented 2 months ago

Is there an existing issue for this?

🐛 Describe the bug

When rendering a (layout) item with .withItem(), and setting an onClick handler with .onClick(click -> {}), closing the inventory with click.closeForPlayer() throws an exception with the message:

Container is not available in the current context: some.package.inventoryframework.context.SlotClickContext 
   at some.package.inventoryframework.context.PlatformContext.getContainerOrThrow(PlatformContext.java:111)

I'm not sure if this is because of layouts, but I wouldn't assume so.

✔️ Expected behavior

The inventory should close normally.

👣 Steps to Reproduce

  1. Compile the latest version of inventory-framework from github, and include it in your project
  2. Create a View
  3. In onInit() define a Layout for the View
  4. In onFirstRender(RenderContext render), render an item in the Layout with
    render.layoutSlot('A').withItem(new ItemStack(Material.STICK)).onClick(click -> {
    click.setCancelled(true);
    click.closeForPlayer();
    }).cancelOnClick();
  5. Open the GUI somehow
  6. Click on an item that is rendered as layoutSlot A
  7. Check the server console or logs

💻 Platform

⭐ Server Version

1.8.9

📚 Library Version

v3.1.0-rc (compiled from github)

✍️ Additional context

No response

DevNatan commented 2 months ago

Thx!! Working on it 🤙🏽