Guest User

Untitled

a guest
Sep 8th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class Board {
  2.  
  3. private final Scoreboard scoreboard;
  4. private final Objective objective;
  5.  
  6. public Board() {
  7. this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
  8. this.objective = scoreboard.registerNewObjective("Board", "dummy");
  9.  
  10. this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
  11. }
  12.  
  13. public Board(Player player) {
  14. this.scoreboard = player.getScoreboard();
  15. this.objective = scoreboard.getObjective(DisplaySlot.SIDEBAR);
  16. }
  17.  
  18. public Scoreboard getScoreboard() {
  19. return scoreboard;
  20. }
  21.  
  22. public String getTitle() {
  23. return objective.getDisplayName();
  24. }
  25.  
  26. public void setTitle(String name) {
  27. this.objective.setDisplayName(name);
  28. }
  29.  
  30. public void set(int row, String text) {
  31. Validate.isTrue(16 > row, "Row can't be higher than 16");
  32. if(text.length() > 32) { text = text.substring(0, 32); }
  33.  
  34. for(String entry : this.scoreboard.getEntries()) {
  35. if(this.objective.getScore(entry).getScore() == row) {
  36. this.scoreboard.resetScores(entry);
  37. break;
  38. }
  39. }
  40.  
  41. this.objective.getScore(text).setScore(row);
  42. }
  43.  
  44. public void remove(int row) {
  45. for(String entry : this.scoreboard.getEntries()) {
  46. if(this.objective.getScore(entry).getScore() == row) {
  47. this.scoreboard.resetScores(entry);
  48. break;
  49. }
  50. }
  51. }
  52. }
Add Comment
Please, Sign In to add comment