SHARE
TWEET

Untitled

a guest May 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package storescore;
  2.  
  3. import com.google.common.base.Splitter;
  4. import java.util.ArrayList;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Random;
  8. import java.util.concurrent.ConcurrentHashMap;
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.scoreboard.DisplaySlot;
  13. import org.bukkit.scoreboard.Scoreboard;
  14. import org.bukkit.scoreboard.Team;
  15.  
  16. public class API {
  17.    public static final String objective = "NoFlicker";
  18.    private Scoreboard scoreboard;
  19.    private ConcurrentHashMap<Integer, String> storedLines = new ConcurrentHashMap();
  20.    private Team[] teams;
  21.    private List<ChatColor> chatMap;
  22.  
  23.    public API() {
  24.       (this.scoreboard = Bukkit.getServer().getScoreboardManager().getNewScoreboard()).registerNewObjective("NoFlicker", "dummy");
  25.       this.teams = new Team[16];
  26.       this.chatMap = new ArrayList();
  27.       ChatColor[] values;
  28.       int length = (values = ChatColor.values()).length;
  29.  
  30.       for(int i = 0; i < length; ++i) {
  31.          ChatColor chat = values[i];
  32.          if (this.chatMap.size() + 1 > 15) {
  33.             break;
  34.          }
  35.  
  36.          this.chatMap.add(chat);
  37.       }
  38.  
  39.    }
  40.  
  41.    private String translateToColorCode(String msg) {
  42.       return ChatColor.translateAlternateColorCodes('&', msg);
  43.    }
  44.  
  45.    public boolean hasLine(int lineID) {
  46.       return this.storedLines.get(lineID) != null;
  47.    }
  48.  
  49.    public void setSlot(DisplaySlot slot) {
  50.       this.scoreboard.getObjective("NoFlicker").setDisplaySlot(slot);
  51.    }
  52.  
  53.    public void setName(String name) {
  54.       this.scoreboard.getObjective("NoFlicker").setDisplayName(name);
  55.    }
  56.  
  57.    public String getName() {
  58.       return this.scoreboard.getObjective("NoFlicker").getName();
  59.    }
  60.  
  61.    private String fixDuplicates(String text) {
  62.       while(this.storedLines.contains(text)) {
  63.          text = String.valueOf(text) + "§r";
  64.       }
  65.  
  66.       return text;
  67.    }
  68.  
  69.    public void addLine(int scoreValue, String name) {
  70.       name = this.fixDuplicates(name);
  71.       this.teams[scoreValue] = this.scoreboard.registerNewTeam(String.valueOf(scoreValue));
  72.       int rand = (new Random()).nextInt(this.chatMap.size());
  73.       String idd = ((ChatColor)this.chatMap.get(rand)).toString();
  74.       this.teams[scoreValue].addEntry(idd);
  75.       this.storedLines.put(scoreValue, idd);
  76.       this.scoreboard.getObjective("NoFlicker").getScore(idd).setScore(scoreValue);
  77.       Iterator<String> iterator = Splitter.fixedLength(16).split(name).iterator();
  78.       String prefix = (String)iterator.next();
  79.       boolean shouldInsert = name.length() >= 16 && prefix.charAt(15) == 167;
  80.       if (shouldInsert) {
  81.          prefix = prefix.substring(0, 15);
  82.       }
  83.  
  84.       this.teams[scoreValue].setPrefix(prefix);
  85.       String chatcolor = ChatColor.getLastColors(prefix);
  86.       if (name.length() > 16) {
  87.          String suffix = (String)iterator.next();
  88.          if (shouldInsert) {
  89.             suffix = "§" + suffix;
  90.          } else {
  91.             suffix = String.valueOf(chatcolor) + suffix;
  92.          }
  93.  
  94.          if (suffix.length() > 16) {
  95.             suffix = suffix.substring(0, 16);
  96.          }
  97.  
  98.          this.teams[scoreValue].setSuffix(suffix);
  99.       }
  100.  
  101.       this.chatMap.remove(rand);
  102.    }
  103.  
  104.    public void removeLine(int id) {
  105.       if (this.hasLine(id)) {
  106.          this.teams[id].unregister();
  107.          this.teams[id] = null;
  108.          String idd = (String)this.storedLines.get(id);
  109.          this.scoreboard.resetScores(idd);
  110.          this.storedLines.remove(id);
  111.       }
  112.    }
  113.  
  114.    public void blankLine(int id) {
  115.       if (!this.hasLine(id)) {
  116.          this.addLine(id, " ");
  117.       }
  118.  
  119.    }
  120.  
  121.    public void updateLine(int id, String newName) {
  122.       if (this.hasLine(id)) {
  123.          newName = this.fixDuplicates(newName);
  124.          Iterator<String> iterator = Splitter.fixedLength(16).split(newName).iterator();
  125.          String prefix = (String)iterator.next();
  126.          boolean shouldInsert = newName.length() > 16 && prefix.charAt(15) == 167;
  127.          if (shouldInsert) {
  128.             prefix = prefix.substring(0, 15);
  129.          }
  130.  
  131.          this.teams[id].setPrefix(prefix);
  132.          String chatcolor = ChatColor.getLastColors(prefix);
  133.          if (newName.length() > 16) {
  134.             String suffix = (String)iterator.next();
  135.             if (shouldInsert) {
  136.                suffix = "§" + suffix;
  137.             } else {
  138.                suffix = String.valueOf(chatcolor) + suffix;
  139.             }
  140.  
  141.             if (suffix.length() > 16) {
  142.                suffix = suffix.substring(0, 16);
  143.             }
  144.  
  145.             this.teams[id].setSuffix(suffix);
  146.          } else {
  147.             this.teams[id].setSuffix("");
  148.          }
  149.  
  150.       }
  151.    }
  152.  
  153.    public String getLine(int id) {
  154.       return String.valueOf(this.teams[id].getPrefix()) + this.teams[id].getSuffix();
  155.    }
  156.  
  157.    public boolean hasBoard(Player player) {
  158.       return player.getScoreboard().getObjective("NoFlicker") != null;
  159.    }
  160.  
  161.    public void setForPlayer(Player player) {
  162.       player.setScoreboard(this.scoreboard);
  163.    }
  164. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top