Solved Close inventory at click

Discussion in 'Spigot Plugin Development' started by HockeyFreak062, Jul 11, 2021.

  1. I'm trying to make an Admin tool, everything works except for the closing of the inventory after clicking a certain item... This is my code. Can someone help?

    Code (Java):

    if (p.getOpenInventory().getTitle().equalsIgnoreCase("              Admin Tool")) {
        if (event.getCurrentItem().equals(crea)){
            p.sendMessage("&6Changed your gamemode to &a&lCreative&6."));

    if (event.getCurrentItem().equals(sur)){
        p.sendMessage("&6Changed your gamemode to &a&lSurvival&6."));

  2. I don't think you should cancel the event, in your case I'd rather use event.setResult(Result.DENY);. Aside that, why are you reinventing a wheel? There are tons of plugins like this.
  3. I'm making one because I need to put stuff in there thats needed for my plugin.
    I'll try and use event.setResult
  4. event.setresult(Result.DENY) doens't change anything. It still closes the inventory and reopens it
  5. If you're using InventoryClickEvent then e.setCancelled(true) should work fine. However I would suggest using else ifs or returning in each if statement for efficiency. Can you please provide the whole listener class?

    EDIT: Also, how do you open this menu? I've had situations where I accidently reopen menus like this.
    • Like Like x 1
  6. I open the menu by Clicking in the air/against a block with a item in the main hand
  7. I thought that clicking the inventory to close it may be triggering the item in hand again and thus reopening the menu but I can't replicate it. Your code should work fine. My advice would be to create another menu like you've done here, but in this one don't add any items to it. Just keep it as simple as possible and see if you're still having the same problem. If you are then there is something very wrong, but if you're not, slowly add the features back until you replicate the issue and then you know what's causing it.
    If you still can't fix the problem then please post all the code involved with this menu for further examination.
    • Agree Agree x 1
  8. I got it to work, Changed the click event for opening the tool. p.closeinventory() works now, Thanks for the help!