API
This plugin offers an API for scoreboards. Here is a simple example how to use it. This example will display the join-count for players on the server (it does not save it to a database, so it will be reset each time the server restarts).
public class TestScoreboard extends JavaPlugin implements Listener { private ScoreboardManger scoreboardManger; private Objective playerJoins; @Override public void onEnable() { scoreboardManger = getServer().getServicesManager().getRegistration(ScoreboardManger.class).getProvider(); playerJoins = scoreboardManger.createObjective("joins", "Joins"); getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onJoin(PlayerJoinEvent e) { Player p = e.getPlayer(); Integer oldCount = playerJoins.getValue(p.getName()); playerJoins.updateScore(p.getName(), (oldCount != null ? oldCount : 0) + 1); PlayerScoreboard scoreboard = scoreboardManger.getScoreboard(p); if (scoreboard != null) { scoreboard.addObjective(playerJoins, ObjectiveDisplayPosition.SIDEBAR, 100); } } }
Some important points:
- You will have to add something like depend: [PVPStatsScoreboard] or softdepend: [PVPStatsScoreboard] to you plugin.yml.
- Get the scoreboard bei using the ServicesManager.
- Always check, if a PlayerScoreboard is not null. It may be null if a Player has already disconnected.
- Do not add more than 15 entries to an Objective that is shown in the SIDEBAR, or Minecraft will not display anything. This is a Minecraft client limitation.
- When you call PlayerScoreboard.addObjective or PlayerScoreboard.setObjectiveDisplay you will have to specify the display priority. Only the objective with the highest priority will be displayed at a given time. So if you want switching objectives you will have to modify the priority or remove the objective and readd it later.
- Objectives are not saved. You will have to recreate them on every server start.
- PlayerScoreboard will reset when the Player disconnects. You will have to add the objectives on rejoin.
Comments