Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.icodetits.vkoth.kothsb;
- import java.util.concurrent.*;
- import me.icodetits.vkoth.*;
- import com.google.common.base.*;
- import java.util.*;
- import org.bukkit.entity.*;
- import org.bukkit.*;
- import org.bukkit.scoreboard.*;
- public class Board
- {
- public static final String objective = "kothScoreboard";
- private Scoreboard scoreboard;
- private ConcurrentHashMap<Integer, String> storedLines;
- private Team[] teams;
- private List<ChatColor> chatMap;
- protected Board() {
- this.storedLines = new ConcurrentHashMap<Integer, String>();
- (this.scoreboard = Main.getInstance().getServer().getScoreboardManager().getMainScoreboard()).registerNewObjective("kothScoreboard", "dummy");
- this.teams = new Team[16];
- this.chatMap = new ArrayList<ChatColor>();
- ChatColor[] values;
- for (int length = (values = ChatColor.values()).length, i = 0; i < length; ++i) {
- final ChatColor chat = values[i];
- if (this.chatMap.size() + 1 > 15) {
- break;
- }
- this.chatMap.add(chat);
- }
- }
- public void reset() {
- this.teams = null;
- this.scoreboard = null;
- this.chatMap.clear();
- this.chatMap = null;
- this.storedLines.clear();
- this.storedLines = null;
- }
- private String translateToColorCode(final String msg) {
- return ChatColor.translateAlternateColorCodes('&', msg);
- }
- public boolean hasLine(final int lineID) {
- return this.storedLines.get(lineID) != null;
- }
- public void setSlot(final DisplaySlot slot) {
- this.scoreboard.getObjective("kothScoreboard").setDisplaySlot(slot);
- }
- public void setName(final String name) {
- this.scoreboard.getObjective("kothScoreboard").setDisplayName(this.translateToColorCode(name));
- }
- public String getName() {
- return this.scoreboard.getObjective("kothScoreboard").getDisplayName();
- }
- private String fixDuplicates(String text) {
- while (this.storedLines.containsValue(text)) {
- text = String.valueOf(text) + "�r";
- }
- return text;
- }
- public void addLine(final int scoreValue, String name) {
- name = this.fixDuplicates(name);
- this.teams[scoreValue] = this.scoreboard.registerNewTeam(String.valueOf(scoreValue));
- final int rand = new Random().nextInt(this.chatMap.size());
- final String idd = this.chatMap.get(rand).toString();
- this.teams[scoreValue].addEntry(idd);
- this.storedLines.put(scoreValue, idd);
- this.scoreboard.getObjective("kothScoreboard").getScore(idd).setScore(scoreValue);
- final Iterator<String> iterator = Splitter.fixedLength(16).split((CharSequence)name).iterator();
- String prefix = iterator.next();
- final boolean shouldInsert = name.length() >= 16 && prefix.charAt(15) == '�';
- if (shouldInsert) {
- prefix = prefix.substring(0, 15);
- }
- this.teams[scoreValue].setPrefix(prefix);
- final String chatcolor = ChatColor.getLastColors(prefix);
- if (name.length() > 16) {
- String suffix = iterator.next();
- if (shouldInsert) {
- suffix = "�" + suffix;
- }
- else {
- suffix = String.valueOf(chatcolor) + suffix;
- }
- if (suffix.length() > 16) {
- suffix = suffix.substring(0, 16);
- }
- this.teams[scoreValue].setSuffix(suffix);
- }
- this.chatMap.remove(rand);
- }
- public void removeLine(final int id) {
- if (!this.hasLine(id)) {
- return;
- }
- this.teams[id].unregister();
- this.teams[id] = null;
- final String idd = this.storedLines.get(id);
- this.scoreboard.resetScores(idd);
- this.storedLines.remove(id);
- }
- public void blankLine(final int id) {
- if (!this.hasLine(id)) {
- this.addLine(id, " ");
- }
- }
- public void updateLine(final int id, String newName) {
- if (!this.hasLine(id)) {
- return;
- }
- newName = this.fixDuplicates(newName);
- final Iterator<String> iterator = Splitter.fixedLength(16).split((CharSequence)newName).iterator();
- String prefix = iterator.next();
- final boolean shouldInsert = newName.length() > 16 && prefix.charAt(15) == '�';
- if (shouldInsert) {
- prefix = prefix.substring(0, 15);
- }
- this.teams[id].setPrefix(prefix);
- final String chatcolor = ChatColor.getLastColors(prefix);
- if (newName.length() > 16) {
- String suffix = iterator.next();
- if (shouldInsert) {
- suffix = "�" + suffix;
- }
- else {
- suffix = String.valueOf(chatcolor) + suffix;
- }
- if (suffix.length() > 16) {
- suffix = suffix.substring(0, 16);
- }
- this.teams[id].setSuffix(suffix);
- }
- else {
- this.teams[id].setSuffix("");
- }
- }
- public String getLine(final int id) {
- return String.valueOf(this.teams[id].getPrefix()) + this.teams[id].getSuffix();
- }
- public boolean hasBoard(final Player player) {
- return player.getScoreboard().getObjective("kothScoreboard") != null;
- }
- public void setForPlayer(final Player player) {
- player.setScoreboard(this.scoreboard);
- }
- private static boolean isInteger(final String s) {
- try {
- Integer.parseInt(s);
- }
- catch (NumberFormatException e) {
- return false;
- }
- catch (NullPointerException e2) {
- return false;
- }
- return true;
- }
- public static void main(final String[] args) {
- System.out.println(ChatColor.BLUE.toString());
- }
- public static void wipe() {
- final Scoreboard main = Bukkit.getScoreboardManager().getMainScoreboard();
- final Objective obj = main.getObjective("kothScoreboard");
- if (obj != null) {
- obj.unregister();
- if (main.getEntries() != null && !main.getEntries().isEmpty()) {
- for (final String entry : main.getEntries()) {
- if (entry.startsWith("�")) {
- main.resetScores(entry);
- }
- }
- }
- if (main.getTeams() != null && !main.getTeams().isEmpty()) {
- for (final Team team : main.getTeams()) {
- if (isInteger(team.getName())) {
- team.unregister();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment