Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Scoreboard System #4

Description

@Manered

example usage:

public final class ExamplePlugin extends JavaPlugin implements Listener {

    private final Map<Player, CustomScoreboard> scoreboards = new HashMap<>();

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);

        /* Refreshes all scoreboards every 1 second */
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
            for (CustomScoreboard scoreboard : this.scoreboards.values()) {
                refreshScoreboard(scoreboard);
            }
        }, 0, 20L);
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();

        CustomScoreboard scoreboard = new CustomScoreboard(player);

        scoreboard.setTitle(ColorUtils.color("<#ff0000>Scoreboard API"));

        this.scoreboards.put(player, scoreboard);
    }

    @EventHandler
    public void onLeave(PlayerQuitEvent event) {
        Player player = event.getPlayer();

        CustomScoreboard scoreboard = this.scoreboards.remove(player);

        if (scoreboard != null) {
            scoreboard.delete();
        }
    }

    public void refreshScoreboard(CustomScoreboard scoreboard) {
        Player player = scoreboard.getPlayer();
        Spark spark = SparkProvider.get();

        // Get the TPS statistic (will be null on platforms that don't have ticks!)
        DoubleStatistic<StatisticWindow.TicksPerSecond> tps = spark.tps();

        double lastTps = tps.poll(StatisticWindow.TicksPerSecond.SECONDS_5);

        scoreboard.setLines(
                ScoreboardUtils.emptyLine(),
                "Ping: " + player.getPing() + "ms",
                "TPS: " + lastTps,
                ScoreboardUtils.emptyLine()
        );
    }
}

or:

CustomScoreboard scoreboard = new CustomScoreboard(player)
  .setTitle("Hello!")
  .setLines("test", "")

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

suggestionNew feature or request/suggestion

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions