Skip to content

Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20.4 support.

License

Notifications You must be signed in to change notification settings

JAHMCR/AsyncScoreboard

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastBoard

Java CI Maven Central Discord

Lightweight packet-based scoreboard API for Bukkit plugins, compatible with all Minecraft versions starting with 1.7.10.

Important

To use FastBoard on a 1.8 server, the server must be on 1.8.8.

Features

  • No flickering (without using a buffer)
  • Compatible with all Minecraft versions starting with 1.7.10
  • Small (around 750 lines of code with the JavaDoc) and no dependencies
  • Easy to use
  • Dynamic scoreboard size: you don't need to add/remove lines, you can directly give a string list (or array) to change all the lines
  • Everything is at the packet level, so it works with other plugins using scoreboard and/or teams
  • Can be used asynchronously
  • Supports up to 30 characters per line on 1.12.2 and below
  • No character limit on 1.13 and higher
  • RGB HEX colors support on 1.16 and higher
  • Custom number formatting (including blank) for scores on 1.20.3 and higher
  • Adventure components support
  • Support for both Spigot and Mojang mappings

Installation

Maven

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <relocations>
                    <relocation>
                        <pattern>fr.mrmicky.fastboard</pattern>
                        <!-- Replace 'com.yourpackage' with the package of your plugin ! -->
                        <shadedPattern>com.yourpackage.fastboard</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>fr.mrmicky</groupId>
        <artifactId>fastboard</artifactId>
        <version>2.1.3</version>
    </dependency>
</dependencies>

Note

When using Maven, make sure to build directly with Maven and not with your IDE configuration (on IntelliJ IDEA: in the Maven tab on the right, in Lifecycle, use package).

Gradle

plugins {
    id 'com.gradleup.shadow' version '8.3.0'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'fr.mrmicky:fastboard:2.1.3'
}

shadowJar {
    // Replace 'com.yourpackage' with the package of your plugin 
    relocate 'fr.mrmicky.fastboard', 'com.yourpackage.fastboard'
}

Manual

Copy FastBoardBase.java, FastBoard.java and FastReflection.java in your plugin.

Usage

Creating a scoreboard

Simply create a new FastBoard and update the title and the lines:

FastBoard board = new FastBoard(player);

// Set the title
board.updateTitle(ChatColor.GOLD + "FastBoard");

// Change the lines
board.updateLines(
        "", // Empty line
        "One line",
        "",
        "Second line"
);

Example

Small example plugin with a scoreboard that refreshes every second:

package fr.mrmicky.fastboard.example;

import fr.mrmicky.fastboard.FastBoard;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class ExamplePlugin extends JavaPlugin implements Listener {

    private final Map<UUID, FastBoard> boards = new HashMap<>();

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

        getServer().getScheduler().runTaskTimer(this, () -> {
            for (FastBoard board : this.boards.values()) {
                updateBoard(board);
            }
        }, 0, 20);
    }

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

        FastBoard board = new FastBoard(player);

        board.updateTitle(ChatColor.RED + "FastBoard");

        this.boards.put(player.getUniqueId(), board);
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent e) {
        Player player = e.getPlayer();

        FastBoard board = this.boards.remove(player.getUniqueId());

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

    private void updateBoard(FastBoard board) {
        board.updateLines(
                "",
                "Players: " + getServer().getOnlinePlayers().size(),
                "",
                "Kills: " + board.getPlayer().getStatistic(Statistic.PLAYER_KILLS),
                ""
        );
    }
}

Adventure support

For servers on modern PaperMC versions, FastBoard supports using Adventure components instead of strings, by using the fr.mrmicky.fastboard.adventure.FastBoard class.

Warning

With Adventure, on servers below Minecraft 1.13, lines are truncated to a maximum of 16 characters. To get around this limit, upgrade to a newer version of Minecraft or use the non-Adventure version (fr.mrmicky.fastboard.FastBoard).

RGB colors

When using the non-Adventure version of FastBoard, RGB colors can be added on 1.16 and higher with ChatColor.of("#RRGGBB") (net.md_5.bungee.api.ChatColor import).

Custom number formatting

For servers on Minecraft 1.20.3 and above, FastBoard supports custom number formatting for scores. By default, it uses the blank format, so that no score is visible, but it's also possible to set custom scores using FastBoard#updateLine(line, text, scoreText), FastBoard#updateLines(lines, scores) and FastBoard#updateScore(line, text).

Passing a null value as a score will result in a reset to the default blank formatting.

ViaBackwards compatibility

When using ViaBackwards on a post-1.13 server with pre-1.13 clients, older clients may receive incomplete lines. To solve this problem, you can override the hasLinesMaxLength() method and return true for older clients. For example using the ViaVersion API:

FastBoard board = new FastBoard(player) {
    @Override
    public boolean hasLinesMaxLength() {
        return Via.getAPI().getPlayerVersion(getPlayer()) < ProtocolVersion.v1_13.getVersion(); // or just 'return true;'
    }
});

About

Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20.4 support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%