Solved List<Itemstack> output

Discussion in 'Plugin Development' started by MieskeB, Oct 17, 2017.

Thread Status:
Not open for further replies.
  1. Code:
    Private List<ItemStack> items = new ArrayList<ItemStack>();
    
    
    for (String s : items) {
      //content
    }
    ERROR: Type mismatch: cannot convert from element type ItemStack to String

    I was following a tutorial on how to create bukkit plugins, I have created exactly the same as he does but it doesn't work for me... I have to make it a string because I was going to use the s.contains(":") function. Can someone help me fix this problem?

    Thanks in advance!
     
  2. Offline

    MightyOne

    Oh geez xD well of course you can not just cast an ItemStack to a String. But luckily there is the method ItemStack.toString().
    In the for-statement you will have to use ItemStack instead of String but inside you can create a String with item.toString();
     
  3. @MightyOne First of all thanks for the quick reply! I just tried to do what you've said but it gave the same error message :/
     
  4. Offline

    Zombie_Striker

    @MieskeB
    I don't think you really want to convert all the data, (lore, NBT tags, Attachments, ItemFlags, ect.) into one string. Its not really managable. If you want to convert the essence of the itemstack to a string, try changing the for loop from a Sting to an ItemStack, and use String string = ItemStack#getType().name()+" : "+ ItemStack#getDurability() to convert the basics to a string (Something like DIRT:0)
     
    MieskeB likes this.
  5. Havent thought of that! Thank you very much! It worked!
     
Thread Status:
Not open for further replies.

Share This Page