Guest User

Untitled

a guest
Mar 6th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.84 KB | None | 0 0
  1. package me.icodetits.vkoth.kothsb;
  2.  
  3. import java.util.concurrent.*;
  4. import me.icodetits.vkoth.*;
  5. import com.google.common.base.*;
  6. import java.util.*;
  7. import org.bukkit.entity.*;
  8. import org.bukkit.*;
  9. import org.bukkit.scoreboard.*;
  10.  
  11. public class Board
  12. {
  13. public static final String objective = "kothScoreboard";
  14. private Scoreboard scoreboard;
  15. private ConcurrentHashMap<Integer, String> storedLines;
  16. private Team[] teams;
  17. private List<ChatColor> chatMap;
  18.  
  19. protected Board() {
  20. this.storedLines = new ConcurrentHashMap<Integer, String>();
  21. (this.scoreboard = Main.getInstance().getServer().getScoreboardManager().getMainScoreboard()).registerNewObjective("kothScoreboard", "dummy");
  22. this.teams = new Team[16];
  23. this.chatMap = new ArrayList<ChatColor>();
  24. ChatColor[] values;
  25. for (int length = (values = ChatColor.values()).length, i = 0; i < length; ++i) {
  26. final ChatColor chat = values[i];
  27. if (this.chatMap.size() + 1 > 15) {
  28. break;
  29. }
  30. this.chatMap.add(chat);
  31. }
  32. }
  33.  
  34. public void reset() {
  35. this.teams = null;
  36. this.scoreboard = null;
  37. this.chatMap.clear();
  38. this.chatMap = null;
  39. this.storedLines.clear();
  40. this.storedLines = null;
  41. }
  42.  
  43. private String translateToColorCode(final String msg) {
  44. return ChatColor.translateAlternateColorCodes('&', msg);
  45. }
  46.  
  47. public boolean hasLine(final int lineID) {
  48. return this.storedLines.get(lineID) != null;
  49. }
  50.  
  51. public void setSlot(final DisplaySlot slot) {
  52. this.scoreboard.getObjective("kothScoreboard").setDisplaySlot(slot);
  53. }
  54.  
  55. public void setName(final String name) {
  56. this.scoreboard.getObjective("kothScoreboard").setDisplayName(this.translateToColorCode(name));
  57. }
  58.  
  59. public String getName() {
  60. return this.scoreboard.getObjective("kothScoreboard").getDisplayName();
  61. }
  62.  
  63. private String fixDuplicates(String text) {
  64. while (this.storedLines.containsValue(text)) {
  65. text = String.valueOf(text) + "�r";
  66. }
  67. return text;
  68. }
  69.  
  70. public void addLine(final int scoreValue, String name) {
  71. name = this.fixDuplicates(name);
  72. this.teams[scoreValue] = this.scoreboard.registerNewTeam(String.valueOf(scoreValue));
  73. final int rand = new Random().nextInt(this.chatMap.size());
  74. final String idd = this.chatMap.get(rand).toString();
  75. this.teams[scoreValue].addEntry(idd);
  76. this.storedLines.put(scoreValue, idd);
  77. this.scoreboard.getObjective("kothScoreboard").getScore(idd).setScore(scoreValue);
  78. final Iterator<String> iterator = Splitter.fixedLength(16).split((CharSequence)name).iterator();
  79. String prefix = iterator.next();
  80. final boolean shouldInsert = name.length() >= 16 && prefix.charAt(15) == '�';
  81. if (shouldInsert) {
  82. prefix = prefix.substring(0, 15);
  83. }
  84. this.teams[scoreValue].setPrefix(prefix);
  85. final String chatcolor = ChatColor.getLastColors(prefix);
  86. if (name.length() > 16) {
  87. String suffix = iterator.next();
  88. if (shouldInsert) {
  89. suffix = "�" + suffix;
  90. }
  91. else {
  92. suffix = String.valueOf(chatcolor) + suffix;
  93. }
  94. if (suffix.length() > 16) {
  95. suffix = suffix.substring(0, 16);
  96. }
  97. this.teams[scoreValue].setSuffix(suffix);
  98. }
  99. this.chatMap.remove(rand);
  100. }
  101.  
  102. public void removeLine(final int id) {
  103. if (!this.hasLine(id)) {
  104. return;
  105. }
  106. this.teams[id].unregister();
  107. this.teams[id] = null;
  108. final String idd = this.storedLines.get(id);
  109. this.scoreboard.resetScores(idd);
  110. this.storedLines.remove(id);
  111. }
  112.  
  113. public void blankLine(final int id) {
  114. if (!this.hasLine(id)) {
  115. this.addLine(id, " ");
  116. }
  117. }
  118.  
  119. public void updateLine(final int id, String newName) {
  120. if (!this.hasLine(id)) {
  121. return;
  122. }
  123. newName = this.fixDuplicates(newName);
  124. final Iterator<String> iterator = Splitter.fixedLength(16).split((CharSequence)newName).iterator();
  125. String prefix = iterator.next();
  126. final boolean shouldInsert = newName.length() > 16 && prefix.charAt(15) == '�';
  127. if (shouldInsert) {
  128. prefix = prefix.substring(0, 15);
  129. }
  130. this.teams[id].setPrefix(prefix);
  131. final String chatcolor = ChatColor.getLastColors(prefix);
  132. if (newName.length() > 16) {
  133. String suffix = iterator.next();
  134. if (shouldInsert) {
  135. suffix = "�" + suffix;
  136. }
  137. else {
  138. suffix = String.valueOf(chatcolor) + suffix;
  139. }
  140. if (suffix.length() > 16) {
  141. suffix = suffix.substring(0, 16);
  142. }
  143. this.teams[id].setSuffix(suffix);
  144. }
  145. else {
  146. this.teams[id].setSuffix("");
  147. }
  148. }
  149.  
  150. public String getLine(final int id) {
  151. return String.valueOf(this.teams[id].getPrefix()) + this.teams[id].getSuffix();
  152. }
  153.  
  154. public boolean hasBoard(final Player player) {
  155. return player.getScoreboard().getObjective("kothScoreboard") != null;
  156. }
  157.  
  158. public void setForPlayer(final Player player) {
  159. player.setScoreboard(this.scoreboard);
  160. }
  161.  
  162. private static boolean isInteger(final String s) {
  163. try {
  164. Integer.parseInt(s);
  165. }
  166. catch (NumberFormatException e) {
  167. return false;
  168. }
  169. catch (NullPointerException e2) {
  170. return false;
  171. }
  172. return true;
  173. }
  174.  
  175. public static void main(final String[] args) {
  176. System.out.println(ChatColor.BLUE.toString());
  177. }
  178.  
  179. public static void wipe() {
  180. final Scoreboard main = Bukkit.getScoreboardManager().getMainScoreboard();
  181. final Objective obj = main.getObjective("kothScoreboard");
  182. if (obj != null) {
  183. obj.unregister();
  184. if (main.getEntries() != null && !main.getEntries().isEmpty()) {
  185. for (final String entry : main.getEntries()) {
  186. if (entry.startsWith("�")) {
  187. main.resetScores(entry);
  188. }
  189. }
  190. }
  191. if (main.getTeams() != null && !main.getTeams().isEmpty()) {
  192. for (final Team team : main.getTeams()) {
  193. if (isInteger(team.getName())) {
  194. team.unregister();
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment