Guest User

Untitled

a guest
Jun 25th, 2016
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.bukkit.Bukkit;
  2. import org.bukkit.entity.Player;
  3. import org.bukkit.scoreboard.DisplaySlot;
  4. import org.bukkit.scoreboard.Objective;
  5. import org.bukkit.scoreboard.Scoreboard;
  6. import org.bukkit.scoreboard.ScoreboardManager;
  7.  
  8. import java.util.Arrays;
  9. import java.util.Collections;
  10. import java.util.List;
  11. import java.util.Set;
  12.  
  13. public class Board {
  14.  
  15. private static ScoreboardManager manager = Bukkit.getScoreboardManager();
  16.  
  17. private Scoreboard scoreboard;
  18. private Objective objective;
  19.  
  20. public Board(String name) {
  21. this.scoreboard = manager.getNewScoreboard();
  22. this.objective = scoreboard.registerNewObjective("Board", "dummy");
  23. this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
  24. }
  25.  
  26. public Board(Player player) {
  27. if(player.getScoreboard() != null && player.getScoreboard().getObjective(DisplaySlot.SIDEBAR) != null) {
  28. this.scoreboard = player.getScoreboard();
  29. this.objective = scoreboard.getObjective(DisplaySlot.SIDEBAR);
  30. } else {
  31. this.scoreboard = manager.getNewScoreboard();
  32. this.objective = scoreboard.registerNewObjective("Board", "dummy");
  33. this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
  34. }
  35. }
  36.  
  37. public String getDisplayName() {
  38. return objective.getDisplayName();
  39. }
  40.  
  41. public void setDisplayName(String displayName) {
  42. objective.setDisplayName(displayName);
  43. }
  44.  
  45. public void addEntry(int score, String text) {
  46. if(score > 15) {
  47. return;
  48. }
  49.  
  50. for(String entry : scoreboard.getEntries()) {
  51. if(objective.getScore(entry).getScore() == score) {
  52. if(entry.equals(text)) {
  53. return;
  54. }
  55.  
  56. scoreboard.resetScores(entry);
  57. break;
  58. }
  59. }
  60.  
  61. objective.getScore(text).setScore(score);
  62. }
  63.  
  64. public void removeEntry(int score) {
  65. if(score > 16) {
  66. return;
  67. }
  68.  
  69. for(String entry : scoreboard.getEntries()) {
  70. if(objective.getScore(entry).getScore() == score) {
  71. scoreboard.resetScores(entry);
  72. break;
  73. }
  74. }
  75. }
  76.  
  77. public void clear() {
  78. for(String entry : scoreboard.getEntries()) {
  79. scoreboard.resetScores(entry);
  80. }
  81. }
  82.  
  83. public Set<String> getEntries() {
  84. return Collections.unmodifiableSet(scoreboard.getEntries());
  85. }
  86.  
  87. public void send(Player... players) {
  88. if(players != null) {
  89. send(Arrays.asList(players));
  90. }
  91. }
  92.  
  93. public void send(List<Player> players) {
  94. for(Player player : players) {
  95. player.setScoreboard(scoreboard);
  96. }
  97. }
  98. }
RAW Paste Data