Solved Player doesn't get BossBar updates.

Discussion in 'Spigot Plugin Development' started by Itaquito, Jan 20, 2021.

  1. Hello!

    When I add a player to a BossBar on joining (with the event PlayerJoinEvent), he doesn't seem to be getting the updates I'm constantly doing to the BossBar with .setTitle(). He only sees the default text of the BossBar (the text I defined when I created it).
    I tried delaying the task a few ticks, this didn't solve the problem.

    This problem doesn't happen if I add the player manually to the bossbar via a command

    Here is where the bar gets created and updated https://paste.itaqui.to/AOVk1_jWR2.java
    My PlayerJoinEvent https://paste.itaqui.to/_RHe52K6eN.java (On this code, there is a
    runTaskLater. The problem persists with and without it)

    Thanks.
     
    • Like Like x 1
  2. Are you sure that StatsManager#getTime() changes it's value?
     
  3. Yes! It should be.
    I recorded a video about this

    In this case I'm using System#currentTimeMillis() to update the bossbar, just in case if StatsManager#getTime() is not updating.
     
  4. Thank you. I looked into your code and found a mistake (maybe you wanted to have it like that?). When you register the command using class TimerCommand (in which the bossbar logic is), you create one instance of the class (because you use Bukkit.getCommand("...").setExecutor(new TimerCommand()) or something like that). If you use the command, you get added to the bossbar created in the instance of that class and the repeating task is scheduled (which updates the title). We can see this on the video, it is working correctly.

    Same as you register commands, you register the join event in class ListenerPlayerJoin - you create an instance of the class. That has a field of type TimerCommand, which is initialized when you create a new instance of the class. The TimerCommand class there creates a new bossbar (TimerCommand instance registered as the command has created one instance, TimerCommand instance in timerManager field in ListenerPlayerJoin class has created another instance). So after 100 ticks you use the second instance of TimerCommand to add yourself to the bossbar, but in that instance onCommand() method has never been called, so the updating task is not running.

    Simply, there are two instances of the TimerCommand class, both have their own bossbars.
     
  5. Ohhh! Thanks!

    I changed the BossBar variable to a class variable and now it works properly. That actually makes sense.

    I guess I should make a separate class to manage the boss bar and not use the command class tho...
    Thanks for your support!