Quick question about ItemMeta

Discussion in 'Plugin Development' started by Cabbage, Jul 27, 2013.

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

    Cabbage

    Hi, I know this is basic stuff for most of you, but I've got a little problem.
    I have an item (glass bottle) and want to turn it into a potion.
    I've ran into a problem where I don't know how to get the PotionMeta I will be modifying and setting to the ItemStack - I can't use getItemMeta(), nor can I cast it.
    How should I go about that?

    Thanks in advance :)
     
  2. Offline

    metalhedd

    PotionMeta extends ItemMeta so you should be able to use getItemMeta or cast the existing ItemMeta to a PotionMeta. Can you paste some code and an error message?
     
  3. Offline

    Cabbage

    Nvm I figured it out. Seemed weird to me that you can't cast a parent to an extension - I had imports mixed up, using the craftbukkit ItemMeta. Thanks for your time anyway :)
     
  4. Offline

    metalhedd

  5. Offline

    Cabbage

    yeah, I had a detailed post about the code and the error I was getting, but then I saw the error myself and decided to just strike that through and make it small.
    Note to self, the graphical editor doesn't handle multiple formatting tags at the same time very well if messy. :D
     
  6. Offline

    metalhedd

    I figured it was something like that :) glad you got it sorted out.
     
  7. Offline

    Cabbage

    alright, the problem still persists, somehow.
    Code:java
    1. PotionMeta meta = (PotionMeta) flask.getItemMeta();

    is the line that's causing trouble.
    Code:
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.inventor
    y.CraftMetaItem cannot be cast to org.bukkit.inventory.meta.PotionMeta
            at io.github.xcabbage.kindleflask.ItemInterface.createFlask(ItemInterfac
    e.java:21)
    Any help appreciated :confused:

    Seems to me that the getItemMeta() method is somehow returning something else than the ItemMeta it claims to return. >.>
     
  8. Offline

    metalhedd

    Pretty sure a glass bottle doesn't count as a potion. its a separate Material from the waterbottle and other potions, and doesn't use PotionMeta, just uses normal ItemMeta.

    Edit: Confirmed. Glass Bottle is BlockID 374, Water Bottle (and all potions) are 373
     
  9. Offline

    Cabbage

    Oh, so you can't cast it. Right. Then, how do you think I could go about making it a potion? I'm not entirely sure how to create a PotionMeta on my own :/
     
  10. Offline

    metalhedd

    You would just need to do the same thing but do it to a water bottle instead of a glass bottle.

    you can also use getServer().getItemFactory().getItemMeta(Material.POTION); to get a new 'blank' PotionMeta instance. but you wont be able to apply it to a glass bottle, only to a water bottle or other potion.
     
  11. Offline

    Cabbage

    Alright, will do. Thanks for the help :)
     
Thread Status:
Not open for further replies.

Share This Page