Solved BossBar not appearing

Discussion in 'Spigot Plugin Development' started by mlgcraftnetwork, Jun 17, 2016.

  1. I'm trying to create a bossbar broadcasting system so I'm spawning an enderdragon with custom name, the dragon is being spawned but the bossbar doesn't appear. Does anyone know why? Thanks!

    Code (Text):
        public void newBar() {
            World w = Bukkit.getWorld(Main.plugin.getConfig().getString("spawn.World"));
            double x = Main.plugin.getConfig().getDouble("spawn.X");
            double y = Main.plugin.getConfig().getDouble("spawn.Y");
            double z = Main.plugin.getConfig().getDouble("spawn.Z");
            Location loc = new Location(w,x,y + 3,z);
            Entity dragon = (EnderDragon) w.spawn(loc, EnderDragon.class);
            dragon.setCustomName("§a§lSALE! §2§l50% OFF!");
            //((LivingEntity) dragon).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999999, 1));//
    #1 mlgcraftnetwork, Jun 17, 2016
    Last edited: Jun 17, 2016
  2. You can do this easier if you'd create a CraftBossBar and add a player as a receiver so he sees it. You won't need the dragon then.
    • Agree Agree x 1
  3. Thanks for the tip! How would I craft a boss bar? I just googled it, is this an api feature of spigot?
  4. No it's the implementation, not the api. BossBar is the interface of the Spigot API, CraftBossBar is an implementation from CraftBukkit/Spigot.
    It looks like that:
    Code (Text):
    public CraftBossBar(String title, BarColor color, BarStyle style, BarFlag... flags)
    So you can create something like
    Code (Text):
    Bossbar bar = new CraftBossBar(/*See above for the parameters*/);
    • Winner Winner x 1
  5. I'm going to try that, it seems so simple. Thanks a lot!
  6. It works so perfectly and its SO simple, THANKS! I can't thank you enough!
  7. One more question, I want to change the text on the bossbar every x seconds. Can I just add a new one to the player or should I change the text of the existing one?
  8. Your welcome^^

    There's a setTitle method, so maybe try that one first instead of creating new objects every few seconds.
    If you add a new one you will have to remove the old one, otherwise two boss bars will be displayed at the same time.
  9. MiniDigger


    dont create a craftbossbar, use the right api method for it...
  10. What is wrong with using a CraftBossBar?
  11. ...since when does that method exist? I didn't find it when I searched on how to do it^^
  12. MiniDigger


    that method was added with the same pr that introduced the CraftBossBar...
    everything labeled Craft* is part of Craftbukkit and should not be used in plugins, build against bukkit/spigot-api. The apis allow maximum compability while craftbukkit can change.
  13. Hm can't believe I didn't find that method. My bad. Thanks for the enlightenment.

    @mlgcraftnetwork Always try programming against interfaces and not the implementation so you are independent from it. That way they are decoupled and changing the implementation of the Spigot API for example won't affect your code -> less work for you
  14. Thanks for your help guys! We all learnt something new today :)! I'm now using this:
    Code (Text):
            BossBar bar = Bukkit.createBossBar("§a§lSALE! §2§l50% OFF!", BarColor.GREEN, BarStyle.SEGMENTED_6);
  15. Maybe you could use ChatColors instead of color codes to make it perfect^^
  16. I know about ChatColor but color codes are nice and simple :p. Why is ChatColor better then using color codes?

    Also, how would I remove an bossbar? and does the bossbar stay after restart/reload?
    #16 mlgcraftnetwork, Jun 17, 2016
    Last edited: Jun 17, 2016
  17. ChatColors are easier to read. I've also heard of people ran into issues with color codes but I can't find that thread anymore. So no prove of that^^

    You can use BossBar#remove(Player player) or BossBar#removeAll() to not show it to players anymore. There's also a BossBar#setVisible method.
    Not sure how to remove it the nice way. It probably doesn't survive a server restart because there are no references to it. If you want to make sure that it's gone you can set it to null and let GC free the space.
  18. Choco


    @BillyGalbreath had a great speech about why ChatColor vs. section symbols. Can't seem to find the thread where he had talked about it, though I'm sure he'd be more than happy to let us all know again, perhaps.
    I remember that it had to do with the operating system. Not all operating systems follow the same encoding format
    • Like Like x 1
  19. MiniDigger


    yeah, your code will not be protable if you use § all over the place. most ppl don't change their file encoding to utf-8 so stuff can break very easily if they move files.
    • Agree Agree x 1
  20. Choco


    :D I mean sure. You'll be our temporary Billy for the moment. Haha. If I'm not mistaken, often a question mark in a gray box is displayed if the encoding isn't set to UTF-8. ChatColor enum fixes that for us :)