Solved Cancelling PlayerInventoryClickEvents while in a specific container

Discussion in 'Plugin Development' started by PureAspiration, Oct 20, 2020.

  1. Offline


    So I want to make a GUI which players can click on, but you can put stuff in there. Even after replacing all empty slots with glass, players can still shift-click items which the same metadata into the GUI.

    Here is my code for now
    public void event(InventoryClickEvent event) {
    if (event.getClickedInventory().getHolder() instanceof RecipesGUI) {
    However, this only stops moving of items in the inventory, not the players inventory. So how can I cancel player's inventory while in that GUI?

  2. Offline


    This would probably allow you to do something like this

    public void event(InventoryClickEvent e){
      if(e.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof RecipesGUI) event.setCancelled(true);
    The code above is not tested but the concept should be there?

    Also I'm a bit confused here... why is the RecipesGUI an InventoryHolder?
  3. Offline


    Thanks so much! Solved!

    btw its event.getWhoClicked()

Share This Page