Skip to content

Developer API

Xitee edited this page Jun 25, 2022 · 17 revisions

Things you can do with the API:

  • Create custom placeholders
  • Update a score or set your own scoreboard
  • Set a custom prefix/suffix (coming soon)
  • Set a custom tablist (planned)

Don't forget to put "PowerBoard" as depend or softdepend.

Custom Placeholders

CustomPlaceholders ph = new CustomPlaceholders() {
    @Override
    public String replace(Player p, String s) {
        if(s.contains("%my_placeholder%")) { // Check if placeholder is in string to prevent unnecessary code executions
           // In here you can put any code that is necessary for the replacement

            s = s.replace("%my_placeholder%", "It works!"); // Replace the placeholder
        }

        // Here you can add as many placeholders as you like

        return s; // Return the string with replaced placeholders
    }
};
PowerBoardAPI.registerCustomPlaceholders(ph);

Scoreboard API

Set or remove the scoreboard

Set the boolean to false if you want to use a PowerBoard scoreboard (a scoreboard that is configured in the PB config). This can be useful if you don't want that everyone gets a scoreboard when he joins. But for this you also have to disable the scoreboard in PB's config.yml. If it is disabled in the config.yml no player gets a scoreboard clearly. But you can then use this API to give a specific player a scoreboard which is configured in PB.

If you want a completely custom scoreboard (which is only set and changed trough the API), set it to true. Then the scoreboards from PB won't be applied. You have to set it yourself with the setTitle and setScore methods.

PowerBoardAPI.setScoreboard(p, true/false);
PowerBoardAPI.removeScoreboard(p);



Set or update a single scoreboard line

Set the boolean to true if you have placeholders in the string.
This can also be used to update a line. Works with scoreboards from PB itself too (the ones that are configured in PB's folder).

// Change the text of the score with the ID (red number) 2 to "Hello World"
PowerBoardAPI.setScoreboardScore(p, "Hello World", 2, false);



You can also set all scores at once, which I recommend if you want to set a custom scoreboard.
Better use the above method (a single line) only if you want to update a line, set a custom score value (the red number) or if it is better in your use-case.

Set the boolean to true if you have placeholders from PAPI or PB in the string.

ArrayList<String> scores = new ArrayList<>();
scores.add("Score 1");
scores.add("Score 2");
scores.add("Score 3");
PowerBoardAPI.setScoreboardScores(p, scores, false);

Ranks

Coming soon

Tablist

Planned, can take a while

Clone this wiki locally