Solved Question

Discussion in 'Plugin Development' started by InspectorFacepalm, May 31, 2013.

Thread Status:
Not open for further replies.
  1. How do I make it so when I make a kit like /warrior the iron sword goes into the first slot instead of making the sword go to the slot that you have your hand to, like it goes to the first slot when I do /kit warrior, if you could understand me ;/
     
  2. Offline

    Skyshayde

    First available slot, or first slot period? I'll have to check it, but I think this is fairly easy. Run getContents() on an inventory, it returns an itemstack array. Change the first one in that array to whichever itemstack you wish, and then set it with setContents(). If you wish to store it in the first available one, compare the array to an empty itemstack perhaps? Or, you might need to compare it to one with Air.
     
  3. I want to make it the first slot

    example

    your hot bar has like 9 slots
    I want it to be the first slot
    1 2 3 4 5 6 7 8 9
    ^
    where i want the sword to be
     
  4. Offline

    Skyshayde



    Code:java
    1.  
    2. // this code is written with no guarantees, may very well be wrong, and assumes that you have a player stored in the // object "player" and the desired itemstack is stored in an object called "item"
    3. PlayerInventory inv = player.getInventory();
    4. ItemStack[] item2 = inv.getContents()
    5. item2[0] = item;
    6. inv.setContents(item2);
    7.  
     
    InspectorFacepalm likes this.
  5. Offline

    kreashenz

    Isn't the first slot '0' ? That's what I thought, and that's what has been working.
     
  6. Omg, I love you so much!!!efbgfryew
    also kreashenz yeah I just remembered :p
     
Thread Status:
Not open for further replies.

Share This Page