Skip to content

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

Notifications You must be signed in to change notification settings

RefineDevelopment/ScoreboardAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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();
        }
    }

}

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages