Scoreboard Tutorial

Scoreboards are a nice tool, but often frustrating to work with due to their requirement for the numerical values along the side, their limited size per line, and the need to manually update custom stats. With this tutorial and the help of MCCore, hopefully these issues can be resolved!

Making A Scoreboard

If you want to use one of the two default implementations, it is very simple! Each one of the two scoreboards requires different parameters:

TextBoard

  • String title - this will be the header for the scoreboard over the messages that are added
  • String plugin - simply your plugin name for sorting purposes
  • boolean seperateMessages - Whether or not to separate messages with a line

StatBoard

  • String title - this will be the header for the scoreboard over the stats
  • String plugin - simply your plugin name for sorting purposes

The statboard won't show anything at first if you don't add stats to it. To add stats, simply do:
statBoard.addStats(statHolder)
The statBoard is the scoreboard you constructed above and the statHolder is whatever you use for your stats. statHolder should implement the StatHolder interface.

Example:
A stat holder for a StatBoard

public class ExampleStats implements StatHolder {
    
    private int level;
    private int exp;
    
    @Override
    public Map<String, Integer> getStats() {
        HashMap<String, Integer> stats = new HashMap<String, Integer>();
        stats.put("Level", level);
        stats.put("Exp", exp);
        return stats;
    }
}

And then creating the StatBoard for these stats

        StatBoard statBoard = new StatBoard("Example", plugin.getName());
        ExampleStats stats = new ExampleStats();
        statBoard.addStats(stats);



If you would like to create a different kind of scoreboard, then you have to create a new class and extend the class Board. Board requires the same things as StatBoard for its constructor (you just pass it into the super constructor). Here's a basic example of making a player kill counter scoreboard:

public class KillBoard extends Board {

    public KillBoard(String plugin, String title) {
        super(plugin, "playerKillCount", title);
    }
}

You would create this in the same way with the StatBoard, just without the need for the StatHolder

Once you have that, you are ready to assign the scoreboards to players!

PlayerBoards playerData = BoardManager.getPlayerBoards(player.getName());
playerData.addBoad(statBoard);

And then you're done! Cycling will now include your scoreboard and players can switch to it when they want by using the title you entered as the name in the /board show command!


Comments

Posts Quoted:
Reply
Clear All Quotes