Solved How to not take items out of gui

Discussion in 'Spigot Plugin Development' started by Ninjablader101, Mar 8, 2020.

  1. Please define the inventory you are clicking or something like :
    Code (Java):
    if(event.getView().getTitle().equals("TITLE")) {
    //code
    }
    if you done that u can easily cancel to take out items of the gui with
    Code (Java):
    if(event.getView().getTitle().equals("TITLE")) {
    event.setCancelled(true);
    //code
    }
     
  2. Use an IventoryClickEvent and if it is the right inventory and item then cancel the event.
    Something like:
    Code (Java):
    @EventHandler
    public void onInvClick(InventoryClickEvent e) {
      if(e.getInventory().getName().equals("YourInventoryName")) {
      e.setCancelled(true);
      }
    }
     
    • Agree Agree x 1
  3. It still does not work. https://sourceb.in/61d3859171
     
  4. Did you verify that your InventoryHolder is of type gui?
    Your style of coding (using the InventoryHolder as your way of verifying that the gui is a gui) is deprecated. Sadly there is no clean way of actually doing this, but it would be better to either check for the title (not my prefered way) or store it in a map. Did you properly register your event?
     
  5. getServer().getPluginManager().registerEvents(new Chef(), this);
    this.getCommand("Chef").setExecutor(new Chef());
    I think i did.
     
  6. Solved i put
    Code (Text):
            if (event.getInventory().getTitle().equals(ChatColor.GRAY + "Food")) {
                event.setCancelled(true);
            }
    in the wrong spot