Solved Boss Health Bar not updating?

Discussion in 'Plugin Development' started by WafflesYumyum, Jun 24, 2013.

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

    WafflesYumyum

    Hey! I've got a wither, and I am using its health bar to display a value. I have confirmed that I properly have everything working as it should, but the health bar (The purple one that shows at the top of your screen) is always stuck at just 1/3 health, even when it is higher or lower than that. Here is the line of code that sets the health, and it is working to set the health to where it should be:
    Code:
    nameHolder.setHealth((health/2) * 3);
    //nameHolder being the wither.
    Any idea why this health bar is not properly updating?
    Thanks!
     
  2. Offline

    valon750

    try adding this after that

    nameHolder.setHealth(health);

    Can't see your other code so not sure if that's entirely accurate.
     
  3. Offline

    WafflesYumyum

    valon750 Sorry, should have explained a bit better! "health" is the value that I am trying to use the boss's health bar to show. The health variable can go up to 200, but a wither's health is up to 300, so basically I'm turning "health" into a percentage then using it to set the wither's health to that percentage. so nameHolder.setHealth(health) would just undo that little bit of math.

    So basically, all the code is doing what I want (and I checked the Wither's health, it is how I want it to work) but the health bar at the top of the screen on the client is not updating to show that change, it is always at about 1/3 health no matter what
     
  4. Offline

    valon750

    Eh... I hate percentages with java... I was using it for my FlightPack plugin and in the end just couldn't figure it out :/ I'd refer to you fireblast709 as he's a wizard with code.
     
  5. Offline

    chasechocolate

    WafflesYumyum are you ever changing the value of your health variable? Post some more of your code.
     
  6. Offline

    WafflesYumyum

    chasechocolate Yeah, the health variable is constantly changing unless it reaches 200. Here's my task that continues to bring the health upwards, which I can confirm is running:
    Code:java
    1. base.plugin
    2. .getServer()
    3. .getScheduler()
    4. .scheduleSyncRepeatingTask(base.plugin,
    5. new Runnable() {
    6.  
    7. @Override
    8. public void run() {
    9. if (health < 200) {
    10. health++;
    11. updateNameHolder();
    12. }
    13.  
    14. }
    15. }, 500L, 120L);

    And here is the method, updateNameHolder:
    Code:java
    1. public void updateNameHolder(){
    2. if((health/2)*3 > 0)
    3. nameHolder.setHealth((health/2) * 3); //(health/2) * 3
    4. base.plugin.getServer().broadcastMessage("" + base.getName() + ": " + nameHolder.getHealth());
    5. nameHolder.setCustomName(base.getTeam().getColor() + base.getName());
    6. }


    That broadcast is confirming that the wither's health is always going up (or down) and that my line that sets the health is working as intended; it's just not showing up on the health bar. The health bar is just always showing about 1/3 health, no matter what the wither's health actually is.

    I seem to have found the issue. I was blocking the l_() method in the NMS stuff for my wither, turns out that is also what handles the health, not just the movement!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page