Solved Getting Data of ItemStack

Discussion in 'Plugin Development' started by meowxiik, Oct 27, 2014.

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

    meowxiik

    I need to save & rebuild ItemStack (ItemStack -> String -> ItemStack), but if I save something like Purple wool it saves: PURPLE WOOL(10), and Material.getMaterial(string.split("\\(")[0]); is returning null with it.

    So, I need get String like this:
    WOOL(10)
    OR
    get that getMaterial working with PURPLE WOOL(10)
     
  2. Offline

    Joiner

    You can use ItemStack.setData(byte).
    Code:java
    1. String type = "wool";
    2. String data = "10";
    3. ItemStack output = new ItemStack(Material.getMaterial(type.toUpperCase()));
    4. output.setData((byte)data);
     
  3. Offline

    meowxiik

    I think, you did not understand, I have String (PURPLE WOOL(10)) and I need get ItemStack contains that.
    (Well, I could use something like split it with " " and then with "(", and then extract digits, but this wont work, if some other material would have "DARKWOOD(3)"(<- example, it just wont work, if there wont be a space))
    OR
    Get from ItemStack.getData() instead of : "PURPLE WOOL(10)", "WOOL(10)"
     
  4. Offline

    Joiner

    I answered the Bukkit question. Java questions are not good on this forum I think.
     
  5. Offline

    meowxiik

    Can you please tell me, where you see that "Java question"? :)
     
  6. Offline

    ProtoTempus

    meowxiik Look at using .substring() or .replace()
     
  7. Offline

    meowxiik

    Ok, I'll try
     
  8. Offline

    Joiner

    meowxiik How to split strings is a Java question.
     
  9. Offline

    meowxiik

    I am a horrible at English, I know hot to split in Java :), and this actually removed the problem BUT what if there will be something , what does NOT have the last word same as the basic material? (PUPRLE WOOL(10) -> PURPLE WOOL(10)<- last word same as the basic material)
     
  10. Offline

    Joiner

    meowxiik So use Java strings manipulation.
    Material.getMaterial(String) is a simple lookup, you need to give the enum name. Maybe you could try to look for a library that allows you to use different search terms - Essentials has it.
     
Thread Status:
Not open for further replies.

Share This Page