Solved How to make cmd freak out on inventory click.

Discussion in 'Plugin Development' started by euller12, Aug 24, 2013.

?

How to make cmd freak out on inventory click.

  1. how to help me.

    0 vote(s)
    0.0%
  2. Can help me.

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    euller12

    I am having problems with my plugin that uses InventoryClickEvent and I have Item that you click on but, when you click on air, the console FREAKS out.
     
  2. Offline

    Axe2760

    When you click on an empty slot, the clicked type is null.

    Add null checks, before running the code make sure it != null.
     
  3. Offline

    euller12

    Okay I will try that.

    (e.getCurrentItem().getType().equals(air) || e.getCurrentItem().getType().equals(null)) {

    Would this work?

    didn't work and I need help with != null.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    xTrollxDudex

    euller12
    air cannot be resolved to a type...
     
  5. Offline

    Axe2760

    euller12 I believe Material.AIR literally is null, no need for the or in the if statement.
    Maybe try something like this
    Code:
    if (e.getCurrentItem().getType() != null){
      player.getInventory().addItem(new ItemStack(e.getCurrentItem().getType()));
    }
    
    So as you can see in the example above if you didn't check for != null, you would be trying to add null to the inventory, which would throw an NPE ofc.
     
  6. Offline

    euller12

    OMG THANK YOU!!!! It worked with the help of your example Axe2760, also thanks xTrollxDudex.
     
Thread Status:
Not open for further replies.

Share This Page