Change list<ItemStack> to ItemStack[]

Discussion in 'Plugin Development' started by youngbawss22, Jan 5, 2013.

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

    youngbawss22

    Hello everyone.

    I have never used arraylists and such until now, and I have absolutely no idea what to do. Currently, my objective is to get the drops on the players death, and somehow convert it to ItemStack[] so i can set the blockinventory's contents to the drops.
     
  2. Offline

    puyttre

    Code:java
    1. List<ItemStack> itemStackList = new ArrayList<>();
    2. ItemStack[] itemStackArray = {};
    3.  
    4. for (ItemStack is : itemStackList) {
    5. itemStackArray[itemStackList.get(is)] = is;
    6. itemStackList.clear(); // (optional)
    7. }
    I think this should work. Please let me know how it turns out :)
     
  3. Offline

    youngbawss22

    Hmm, no luck. I believe the argument inside of get() is not an int
     
  4. Offline

    gyroninja

    list.toArray(); I believe should work.
     
    puyttre likes this.
  5. Offline

    youngbawss22

    Doesn't work. I can only use Object[] and not itemstack[]. If i try casting i get an error. Any ideas?
    Error:
    Code:
    Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lorg.bukkit.inventory.ItemStack;
    
     
  6. Offline

    fireblast709

    ItemStack[] stackArray = stackList.toArray(new ItemStack[0]);
     
    MnMaxon likes this.
  7. Offline

    caseif

    Maybe:
    Code:java
    1. ItemStack[] array = new ItemStack[list.size()];
    2. int i = 0;
    3. for (ItemStack is : list){
    4. array[i] = is;
    5. i += 1;
    6. }[/i]

    Let me know if that code works. :D
     
  8. Offline

    youngbawss22

    Once again, you save the day! Thanks so much :D
     
Thread Status:
Not open for further replies.

Share This Page