Advertisement
Guest User

ScoreBoard API

a guest
Apr 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package me.BrokeMyHeart.LookUp;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.scoreboard.DisplaySlot;
  7. import org.bukkit.scoreboard.Objective;
  8. import org.bukkit.scoreboard.Scoreboard;
  9.  
  10. class ScoreBoard {
  11. Player recebidor = null;
  12. String titulo = ChatColor.GRAY + "Titulo indefinido.";
  13.  
  14. public ScoreBoard(Player recebidor, String titulo) {
  15. definirRecebidor(recebidor);
  16. definirTitulo(titulo);
  17. }
  18.  
  19. public void definirRecebidor(Player recebidor) {
  20. this.recebidor = recebidor;
  21. }
  22.  
  23. public void definirTitulo(String titulo) {
  24. if (titulo.length() > 40) {
  25. this.titulo = ChatColor.translateAlternateColorCodes('&', titulo.substring(0, 40));
  26. } else {
  27. this.titulo = ChatColor.translateAlternateColorCodes('&', titulo);
  28. }
  29. }
  30.  
  31. public void definirLinha(String texto, int linha) {
  32. if (b(c(), linha)) {
  33. if (a(c(), linha).equalsIgnoreCase(texto)) {
  34. return;
  35. }
  36. if (!a(c(), linha).equalsIgnoreCase(texto)) {
  37. c().getScoreboard().resetScores(a(c(), linha));
  38. }
  39. }
  40. c().getScore(texto).setScore(linha);
  41. }
  42.  
  43. public void enviar() {
  44. if (this.recebidor == null) {
  45. return;
  46. }
  47. if (this.recebidor.getScoreboard().equals(Bukkit.getServer().getScoreboardManager().getMainScoreboard())) {
  48. this.recebidor.setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard());
  49. }
  50. c().setDisplayName(this.titulo);
  51. if (c().getDisplaySlot() != DisplaySlot.SIDEBAR) {
  52. c().setDisplaySlot(DisplaySlot.SIDEBAR);
  53. }
  54. this.recebidor.setScoreboard(this.recebidor.getScoreboard());
  55. }
  56.  
  57. private static String a(Objective o, int score) {
  58. if (o == null) {
  59. return null;
  60. }
  61. if (!b(o, score)) {
  62. return null;
  63. }
  64. for (String s : o.getScoreboard().getEntries()) {
  65. if (o.getScore(s).getScore() == score) {
  66. return o.getScore(s).getEntry();
  67. }
  68. }
  69. return null;
  70. }
  71.  
  72. private static boolean b(Objective o, int score) {
  73. for (String s : o.getScoreboard().getEntries()) {
  74. if (o.getScore(s).getScore() == score) {
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80.  
  81. private Objective c() {
  82. Scoreboard score = this.recebidor.getScoreboard();
  83. return score.getObjective(this.recebidor.getName()) == null
  84. ? score.registerNewObjective(this.recebidor.getName(), "dummy")
  85. : score.getObjective(this.recebidor.getName());
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement