GUI Disable click

Discussion in 'Spigot Plugin Development' started by Stevie212, Apr 18, 2017.

  1. Hello everyone,

    I am trying to disable a player from clicking items that are set in a GUI, but for some reason the items in the GUI mess up with the ones in my inventory.

    Inventory inv;
    inv = Bukkit.createInventory(null, 54, "Test");

    ItemStack Seperate = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.BLACK.getData());

    inv.setItem(4, Seperate);
    player.openInventory(inv);

    So when I open the inventory I disable clicking on the 4th slot on the gui with if(e.getSlot() == 4){ e.setCancel(true);

    But it cancels the 4th slot in my inventory and my GUI how do I make it cancel the 4th slot only in the GUI and not in my Inventory

    Thanks. Sorry About the English
     
  2. You could check in the inventory's name and if it matches 'Test' and it's the 4th slot cancel it.


    Or check the holder, I'm 93% sure if you create one vs the players the holders are different. Don't quote me though...

    Something like
    Code (Text):
    if(e.getInventory().getHolder() instanceof Player){
        //Do nothing, it's owner is a player, so it should be their inv...
    } else {
        //In the constructor you use you set the holder to null, so we should be here. Then cancel it.
    }
     
    #2 Nateb1121, Apr 18, 2017
    Last edited: Apr 18, 2017

  3. Yup I am creating one vs players
     
  4. You should be able to something like...
    Code (Text):
    if(e.getInventory().getHolder() instanceof Player){
        //Do nothing, it's owner is a player, so it should be their inv...
    } else {
        //In the constructor you use you set the holder to null. So this should be where you check the slot and what not.
    }
     

  5. So how would I disable clicking from a slot with that inventory?
     
  6. Try getting the raw slot instead of just the slot
     
  7. Ok thanks ill try that.
     
  8. On the event firing when a slot is clicked (I don't remember which one it is) add a first if statement checking if that's your inventory and not any other one at all. To do this I suggest you to follow this little tip which I found really useful: https://www.spigotmc.org/threads/qu...r-is-interacting-with-your-custom-gui.225871/
    After that check, get the raw slot and check if it is the one you have assigned the custom item you want not to be moved to.
    Also, little suggestion, don't capitalize variable names ("Seperate").
     

  9. alright thanks so much
     
    • Like Like x 1