Display the remaining time of the potion in XP bar.

Discussion in 'Plugin Development' started by PileAlkaline, Nov 24, 2015.

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

    PileAlkaline

    Hello !
    I need some help with a plugin I want to create. It's a PVP mini-game plugin and in the game, player get potion effect when they perform some actions so potion effect, ok, I codded that but the point is that the potion effect are short so I want to display the remaining time in the XP bar. I think I have to use the addXP function but I don't know how to get the potion time and how many XP point is needed to increase or decrease the number in the XP bar.

    I'm sorry if I am not very understandable, I am not English.
    Tell me if there is something you don't understand, I will try to be more precise.

    Thanks in advance for your help !

    Gauthier.
     
  2. Offline

    Zombie_Striker

    @PileAlkaline
    This is what you need to do:
    1. Create a repeating task "*" which will loop through all players online to update their XP.
    2. To get how long the potion is active for, get all their active potions (.getActivePotions), loop through it and find the potion that you added.
    3. Get the durration of that potion effect and store that somewhere.
    4. Use .setLevel() to set the player's XP Levels. It might register in ticks, so you may have to divide the number by 20.
    "*": Use the following:
    http://wiki.bukkit.org/Scheduler_Programming
     
    Lordloss likes this.
Thread Status:
Not open for further replies.

Share This Page