Solved Add air/empty slot to player's inventory?

Discussion in 'Plugin Development' started by TigerHix, Aug 2, 2013.

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

    TigerHix

    I tried player.addItem(new ItemStack(Material.AIR, 1)), but it doesn't add inventory an empty slot.. It just like nothing happens with this code.

    What should I do? I want the first slot to be a block, third slot to be a sword. How to skip second block if I can't set second slot to air?

    Thanks :)
     
  2. Offline

    Tirelessly

    Just don't do anything to the second slot..? addItem won't do it, you need to set the specific slot numbers.
     
  3. Offline

    tommycake50

    so you want a permanently empty slot?
    just use listeners to stop stuff going in.
     
  4. Offline

    TigerHix

    nope, i mean addItem will add item according to your slots; I want to skip some of the slots.
     
  5. Offline

    tommycake50

    Ohh, right i get it.
    you can add items in an array for the slots i believe.
     
  6. Offline

    clienthax

    you need to use null for empty slot
     
  7. Offline

    TigerHix

    It will throws NullPointerException..
     
  8. Offline

    clienthax

    No it won't. use null instead of the itemstack
     
  9. Offline

    TigerHix

    Error: The validated object is null
     
  10. Offline

    clienthax

    you need to set, not add
     
  11. Offline

    callum2904

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    3. if(commandLabel.equalsIgnoreCase("FillInventory")){
    4. if(sender instanceof Player == false){
    5. sender.sendMessage("Command Must Be Used As A Player!");
    6. }else{
    7. if(args.length == 0){
    8. Player player = (Player) sender;
    9. PlayerInventory inv = player.getInventory();
    10. inv.setItem(1, new ItemStack(null, 1)); //1 being the slot and null leaving the slot empty
    11. //doing it this way means you dont have to set it to null you can just set the slots that you want
    12. }
    13. }
    14. }
    15. return false;
    16. }
     
  12. Offline

    TigerHix

    Still, NullPointerException.. :(
     
  13. Offline

    clienthax

  14. Offline

    TigerHix

Thread Status:
Not open for further replies.

Share This Page