Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package storescore;
- import com.google.common.base.Splitter;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Random;
- import java.util.concurrent.ConcurrentHashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.entity.Player;
- import org.bukkit.scoreboard.DisplaySlot;
- import org.bukkit.scoreboard.Scoreboard;
- import org.bukkit.scoreboard.Team;
- public class API {
- public static final String objective = "NoFlicker";
- private Scoreboard scoreboard;
- private ConcurrentHashMap<Integer, String> storedLines = new ConcurrentHashMap();
- private Team[] teams;
- private List<ChatColor> chatMap;
- public API() {
- (this.scoreboard = Bukkit.getServer().getScoreboardManager().getNewScoreboard()).registerNewObjective("NoFlicker", "dummy");
- this.teams = new Team[16];
- this.chatMap = new ArrayList();
- ChatColor[] values;
- int length = (values = ChatColor.values()).length;
- for(int i = 0; i < length; ++i) {
- ChatColor chat = values[i];
- if (this.chatMap.size() + 1 > 15) {
- break;
- }
- this.chatMap.add(chat);
- }
- }
- private String translateToColorCode(String msg) {
- return ChatColor.translateAlternateColorCodes('&', msg);
- }
- public boolean hasLine(int lineID) {
- return this.storedLines.get(lineID) != null;
- }
- public void setSlot(DisplaySlot slot) {
- this.scoreboard.getObjective("NoFlicker").setDisplaySlot(slot);
- }
- public void setName(String name) {
- this.scoreboard.getObjective("NoFlicker").setDisplayName(name);
- }
- public String getName() {
- return this.scoreboard.getObjective("NoFlicker").getName();
- }
- private String fixDuplicates(String text) {
- while(this.storedLines.contains(text)) {
- text = String.valueOf(text) + "§r";
- }
- return text;
- }
- public void addLine(int scoreValue, String name) {
- name = this.fixDuplicates(name);
- this.teams[scoreValue] = this.scoreboard.registerNewTeam(String.valueOf(scoreValue));
- int rand = (new Random()).nextInt(this.chatMap.size());
- String idd = ((ChatColor)this.chatMap.get(rand)).toString();
- this.teams[scoreValue].addEntry(idd);
- this.storedLines.put(scoreValue, idd);
- this.scoreboard.getObjective("NoFlicker").getScore(idd).setScore(scoreValue);
- Iterator<String> iterator = Splitter.fixedLength(16).split(name).iterator();
- String prefix = (String)iterator.next();
- boolean shouldInsert = name.length() >= 16 && prefix.charAt(15) == 167;
- if (shouldInsert) {
- prefix = prefix.substring(0, 15);
- }
- this.teams[scoreValue].setPrefix(prefix);
- String chatcolor = ChatColor.getLastColors(prefix);
- if (name.length() > 16) {
- String suffix = (String)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(int id) {
- if (this.hasLine(id)) {
- this.teams[id].unregister();
- this.teams[id] = null;
- String idd = (String)this.storedLines.get(id);
- this.scoreboard.resetScores(idd);
- this.storedLines.remove(id);
- }
- }
- public void blankLine(int id) {
- if (!this.hasLine(id)) {
- this.addLine(id, " ");
- }
- }
- public void updateLine(int id, String newName) {
- if (this.hasLine(id)) {
- newName = this.fixDuplicates(newName);
- Iterator<String> iterator = Splitter.fixedLength(16).split(newName).iterator();
- String prefix = (String)iterator.next();
- boolean shouldInsert = newName.length() > 16 && prefix.charAt(15) == 167;
- if (shouldInsert) {
- prefix = prefix.substring(0, 15);
- }
- this.teams[id].setPrefix(prefix);
- String chatcolor = ChatColor.getLastColors(prefix);
- if (newName.length() > 16) {
- String suffix = (String)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(int id) {
- return String.valueOf(this.teams[id].getPrefix()) + this.teams[id].getSuffix();
- }
- public boolean hasBoard(Player player) {
- return player.getScoreboard().getObjective("NoFlicker") != null;
- }
- public void setForPlayer(Player player) {
- player.setScoreboard(this.scoreboard);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement