Setting the duration of a Potion ItemStack

Discussion in 'Plugin Development' started by travja, Jun 12, 2013.

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

    travja

    How would I go about setting the duration and level of a potion before adding it to a players inventory? Right now I can give them a potion with max level and the regular time.... I've been trying all sorts of things with the Potion and PotionEffect and PotionEffectType stuff and it isn't working.. I'm trying to use something that I won't have to use NBT code for. Any help would be much appreciated.

    Bump... Sorry, I really need to figure this out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    kreashenz

    Get the ID of the potion you want, then set it like
    Code:java
    1. new ItemStack(Material.POTION, 1, (short)<data>);
     
  3. Offline

    travja

    Code:java
    1.  
    2.  
    3. That sets the potion type doesn't it? I need something that will set the duration of the effect.
     
  4. Offline

    Haias

  5. Offline

    kreashenz

    Oh, sorry. I misread, I thought it said durability. xD. You could cancel the event when they are drinking the potion, then get the item ID and check if it's X then set the duration of it.
     
  6. Offline

    travja

  7. Offline

    sheigutn

    You could cast its ItemMeta to PotionMeta and add a custom effect that will overwrite the main effect.
     
    travja likes this.
  8. Offline

    travja

    Thx!! PotionMeta makes quite the difference!!
     
  9. Offline

    sheigutn

    no problem :) you can like my post if you want ;)
     
  10. Offline

    ethanandasher

    Can you give me a code sample for setting the duration with PotionMeta? Thanks.
     
Thread Status:
Not open for further replies.

Share This Page