Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.97 KB

README.md

File metadata and controls

59 lines (44 loc) · 1.97 KB

ScoreboardAPI

Refine's ScoreboardAPI | Uses MegavexNetwork's scoreboard-library

Example Listener

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

import xyz.refinedev.api.scoreboard.ScoreboardHandler;
import xyz.refinedev.api.scoreboard.component.DefaultScoreboardComponent;

@Getter @Ignore
@RequiredArgsConstructor
public class ScoreboardListener implements Listener {

    private final ScoreboardHandler scoreboardHandler;

    @EventHandler(priority = EventPriority.HIGHEST) // Create later, after everything has been setup
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();

        Sidebar sidebar = this.scoreboardHandler.getScoreboardLibrary().createSidebar();
        DefaultScoreboardComponent board = new DefaultScoreboardComponent(this.scoreboardHandler.getAdapter(), sidebar, player);

        sidebar.addPlayer(player);

        board.setup();
        board.tick();

        this.scoreboardHandler.registerScoreboard(player, board);

        // Completely optional, I do this so any bukkit-based objectives are per-player only.
        // Don't do this if you do not use any type of objectives like health display under name.
        if (player.getScoreboard() == Bukkit.getScoreboardManager().getMainScoreboard()) {
            player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerQuit(PlayerQuitEvent event) {
        Player player = event.getPlayer();
        DefaultScoreboardComponent board = this.scoreboardHandler.unregisterScoreboard(player);
        if (board != null) {
            board.getSidebar().close();
        }
    }

}