Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleBossBarExample.java
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.ViaVersionAPI;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle;

public class BossBarExample extends JavaPlugin implements Listener {
    private BossBar bossBar;

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this); // Register Bukkit events

        ViaAPI api = Via.getAPI(); // Get the API
        bossBar = api.legacyAPI().createBossBar(
                "Hi! This BossBar is created using the ViaVersion API!", // BossBar title
                1F, // Boss health (Float between 0 and 1)
                BossColor.BLUE,  // BossBar color
                BossStyle.SOLID); // BossBar Style
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
		// When we added the BossBar, we supported addPlayer with a Player object, that is deprecated since 1.0.0. 
		// Get the player UUID instead.
        bossBar.addPlayer(e.getPlayer().getUniqueId()); // Show the BossBar when a player joins 
    }
}

...