Solved Night vision potion

Discussion in 'Plugin Development' started by Markyroson, Jul 5, 2015.

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

    Markyroson

    How do I make a night vision potion that lasts for 8 minutes (in code)?
     
  2. Offline

    BladeFireTurtle

    What do you want to do, give a physical potion or just the potion effects?

    A similar question was asked regarding physical potions here. You can find the potion data values here.
     
  3. Offline

    Markyroson

    I want to give the physical potion
     
  4. Offline

    BladeFireTurtle

    Alright, what code have you got so far?
     
    Markyroson likes this.
  5. Offline

    Markyroson

    This is obviously not the entire code for my plugin ;-) But this is the code relating to my question (the relevant code).
    Code:
    final Inventory inventory = Bukkit.createInventory(null, 9, "The Explorer");
    Potion nightVision = new Potion(PotionType.NIGHT_VISION, 8);
    ItemStack night = nightVision.toItemStack(1);
    inventory.setItem(5, night);
    
    player.openInventory(inventory);
     
  6. Offline

    teej107

    @Markyroson The int parameter for the Potion constructor is in ticks and not minutes.
     
  7. Offline

    Markyroson

    so how many ticks are in 8 minutes? ;-) And running that code gets a java.lang.IllegalArgumentException: Level must be 1 or 2 exception
     
  8. Offline

    BladeFireTurtle

    20 ticks = 1 second so 9600 ticks = 8 min.
     
  9. Offline

    teej107

    Maybe that particular int specifies the level but I know you can set the potion duration too. Just look in the JavaDocs for the right constructor to use.
     
  10. Offline

    Markyroson

    the int parameter is in levels and apparently 2 is the max? If so then how do I set it to last 8 minutes?
    org.bukkit.potion.Potion.Potion(PotionType type, int level)
     
  11. Offline

    BladeFireTurtle

    Code:
    extend()
    Chain this to the constructor to extend the potion's duration.
     
  12. Offline

    Markyroson

    i added it, do I put the ticks in the extend or?

    Potion nightVision = new Potion(PotionType.NIGHT_VISION, 2).extend();
     
  13. Offline

    teej107

    When in doubt,
     
    BladeFireTurtle likes this.
  14. Offline

    BladeFireTurtle

    Does it work without it? I think it should. If it doesn't I'll look it up.
     
  15. Offline

    Destroyer7712

    it works 8^)
     
  16. Offline

    Markyroson

    Thanks guys. With the 2 it lasts 3 minutes and with the extend() it lasts 8 minutes :)
     
Thread Status:
Not open for further replies.

Share This Page