Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.package.test;
- import org.bukkit.entity.Player;
- import org.bukkit.scoreboard.DisplaySlot;
- import org.bukkit.scoreboard.Objective;
- import org.bukkit.scoreboard.Scoreboard;
- import org.bukkit.scoreboard.ScoreboardManager;
- import org.bukkit.scoreboard.Team;
- public class Scoreboards {
- private ScoreboardManager manager;
- private Scoreboard board;
- private Team team;
- private Objective o;
- private Objective buffer;
- private Objective t;
- public Scoreboards() {
- // Setting up all the scoreboard variables
- this.manager = plugin.getServer().getScoreboardManager();
- this.board = manager.getNewScoreboard();
- this.team = board.registerNewTeam("team");
- // Two objectives for buffer & normal
- this.o = board.registerNewObjective("test", "dummy");
- this.buffer = board.registerNewObjective("buffer", "dummy");
- // Setting up the scoreboard display stuff
- this.o.setDisplaySlot(DisplaySlot.SIDEBAR);
- this.o.setDisplayName("SCOREBOARD!!!");
- }
- public void setScore(String name, int score) {
- // First you update the buffer
- buffer.getScore(name).setScore(score);
- // Then you tell the scoreboard to use the buffer
- // and swap the variables for our convenience
- swapBuffer();
- // And update the -what used to be objective- buffer
- buffer.getScore(name).setScore(score);
- }
- public void swapBuffer() {
- // Simply change the slot, the scoreboard will now
- // push all updating packets to the player
- // Thus wasting not a single ms on executing this at
- // a later time
- buffer.setDisplaySlot(o.getDisplaySlot());
- buffer.setDisplayName(o.getDisplayName());
- // Simply changing references for naming convenience
- t = o;
- o = buffer;
- buffer = t;
- }
- // A simple method to set the scores again, and therefore refresh it.
- public void refresh() {
- setScore("Red Team", Scores.redScore);
- setScore("Blue Team", Scores.blueScore);
- }
- // Adding the player to the scoreboard
- public void addPlayer(Player p) {
- team.addPlayer(p);
- p.setScoreboard(board);
- }
- // Removing the player from the scoreboard
- public void removePlayer(Player p) {
- team.removePlayer(p);
- p.setScoreboard(manager.getNewScoreboard());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement