Disable player inventory click problem?

Discussion in 'Plugin Development' started by spurkle, Jul 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    spurkle

    Hi. It's me again, haha :3

    I am trying to make so player wont be able to move items in his inventory in slots 7 & 8 and i used this to do that:
    Code:java
    1. if (e.getSlot() == 8 || e.getSlot() == 7)
    2. e.setCancelled(true);


    But this turned out to disable the 7 & 8 slots in other inventories like chest. I tried fixing this with an if statement & inventory name check
    Code:java
    1. if(!(e.getInventory().getName() == "Chest") || !(e.getInventory().getName() == "Large Chest")){
    2. if (e.getSlot() == 8 || e.getSlot() == 7)
    3. e.setCancelled(true);
    4. }

    But it is not working. I tried to check if inventory name is "Inventory" and cancel the event, but it is not working either.

    Any help would be appreciated. Thanks ;3
     
  2. Offline

    Flegyas

    Don't use the "= =" operator on non-primitive /enum types, use the method equals.
     
  3. Offline

    hintss

    e.getInventory() always returns the top inventory. You want to use e.getSlot(), and if it's different from e.getRawSlot(), then it's the bottom inventory.
     
  4. Offline

    spurkle

    Okay. But it wont fix this problem.
    Code:java
    1. if(!(e.getInventory().getName().equals("Chest")) || !(e.getInventory().getName().equals("Large Chest"))){
     
  5. Offline

    Traks

    Just check if the inventory is a PlayerInventory using the instanceof keyword
     
  6. Offline

    stormneo7

    Code:java
    1. if(inv.getHolder() instanceof Player){
    2.  
    3. }
     
  7. Offline

    spurkle



    Thanks! This worked.

    EDIT: It worked with chests, but does not work with a custom inventory i created. Any Ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page