Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. package me.package.test;
  2.  
  3. import org.bukkit.entity.Player;
  4. import org.bukkit.scoreboard.DisplaySlot;
  5. import org.bukkit.scoreboard.Objective;
  6. import org.bukkit.scoreboard.Scoreboard;
  7. import org.bukkit.scoreboard.ScoreboardManager;
  8. import org.bukkit.scoreboard.Team;
  9.  
  10. public class Scoreboards {
  11.  
  12.     private ScoreboardManager manager;
  13.     private Scoreboard board;
  14.     private Team team;
  15.     private Objective o;
  16.     private Objective buffer;
  17.     private Objective t;
  18.  
  19.     public Scoreboards() {
  20.         // Setting up all the scoreboard variables
  21.         this.manager = plugin.getServer().getScoreboardManager();
  22.         this.board = manager.getNewScoreboard();
  23.         this.team = board.registerNewTeam("team");
  24.         // Two objectives for buffer & normal
  25.         this.o = board.registerNewObjective("test", "dummy");
  26.         this.buffer = board.registerNewObjective("buffer", "dummy");
  27.      
  28.         // Setting up the scoreboard display stuff
  29.         this.o.setDisplaySlot(DisplaySlot.SIDEBAR);
  30.         this.o.setDisplayName("SCOREBOARD!!!");
  31.     }
  32.    
  33.     public void setScore(String name, int score) {
  34.         // First you update the buffer
  35.         buffer.getScore(name).setScore(score);
  36.         // Then you tell the scoreboard to use the buffer
  37.         // and swap the variables for our convenience
  38.         swapBuffer();
  39.         // And update the -what used to be objective- buffer
  40.         buffer.getScore(name).setScore(score);
  41.     }
  42.    
  43.     public void swapBuffer() {
  44.         // Simply change the slot, the scoreboard will now
  45.         // push all updating packets to the player
  46.         // Thus wasting not a single ms on executing this at
  47.         // a later time
  48.         buffer.setDisplaySlot(o.getDisplaySlot());
  49.         buffer.setDisplayName(o.getDisplayName());
  50.         // Simply changing references for naming convenience
  51.         t = o;
  52.         o = buffer;
  53.         buffer = t;
  54.     }
  55.  
  56.     // A simple method to set the scores again, and therefore refresh it.
  57.     public void refresh() {
  58.         setScore("Red Team", Scores.redScore);
  59.         setScore("Blue Team", Scores.blueScore);
  60.     }
  61.  
  62.     // Adding the player to the scoreboard
  63.     public void addPlayer(Player p) {
  64.         team.addPlayer(p);
  65.         p.setScoreboard(board);
  66.     }
  67.  
  68.     // Removing the player from the scoreboard
  69.     public void removePlayer(Player p) {
  70.         team.removePlayer(p);
  71.         p.setScoreboard(manager.getNewScoreboard());
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement