BossBar per player

Discussion in 'Spigot Plugin Development' started by cercus, Aug 6, 2018.

  1. Hello, I am working on a plugin of spells with a system of mana displayed on the bossbar (One different bossbar per player) . However, I have one error that I can't résolve. I use spigot 1.13.

    Here is my code :

    And the error :

    When I join for the first time, there is not error but when I join after , this error occur.
  2. The error has been removed from
  3. The error has been removed from
    • Creative Creative x 1
  4. Do not put your BossBar in static it is useless.
    Create rather an informative class which will contain your BossBar and full of information on the player.
    Which then you can store in static in your main class.

    Code (Java):
     public static BossBar barMana = Bukkit.createBossBar("§aVotre mana :", BarColor.GREEN, BarStyle.SOLID, new BarFlag[0]);
    • Agree Agree x 1
  5. The problem you have is that you store a Bossbar that is static for each player, so the bar and the same for all players.
    Already for each make sure to create a bar, so that each and its BossBar independence of the others ...
  6. The only way that I found is a hashmap<Player, BossBar> for the independance
  7. here is an example

    Basically you will store this class in a hahmap

    Hashmap <Playeer, Example>

    Then you have just got the class compared to the player.

    Code (Java):
    import org.bukkit.Bukkit;
    import org.bukkit.boss.BossBar;

    public class Exemple {
        private BossBar bossBar;
        public Exemple() {
            bossBar = Bukkit.createBossBar(title, color, style, flags);
        public BossBar getBossBar() {
            return bossBar;

  8. Thanks for your help and I will test tomorrow because actually, I don't have access to my PC.