public static boolean unrankedSidebarDisplay( Collection<Player> players, String[] elements, Scoreboard board) { try { String objName = "COLLAB-SB-WINTER"; if (board == null) board = Bukkit.getScoreboardManager().getNewScoreboard(); elements = cutUnranked(elements); for (Player player : players) if (player.getScoreboard() != board) player.setScoreboard(board); if (board.getObjective(objName) == null) { board.registerNewObjective(objName, "dummy"); board.getObjective(objName).setDisplaySlot(DisplaySlot.SIDEBAR); } board.getObjective(DisplaySlot.SIDEBAR).setDisplayName(elements[0]); for (int i = 1; i < elements.length; i++) if (elements[i] != null && board.getObjective(DisplaySlot.SIDEBAR).getScore(elements[i]).getScore() != 16 - i) { board.getObjective(DisplaySlot.SIDEBAR).getScore(elements[i]).setScore(16 - i); for (String string : board.getEntries()) if (board.getObjective(objName).getScore(string).getScore() == 16 - i) if (!string.equals(elements[i])) board.resetScores(string); } for (String entry : board.getEntries()) { boolean toErase = true; for (String element : elements) { if (element != null && element.equals(entry) && board.getObjective(objName).getScore(entry).getScore() == 16 - Arrays.asList(elements).indexOf(element)) { toErase = false; break; } } if (toErase) board.resetScores(entry); } return true; } catch (Exception e) { e.printStackTrace(); return false; } }
public void updateLabel(XLabel label) { resetScores(label); if (label.isVisible()) { if (label.getValue().equals("")) { return; } if (label.getValue().equals("§a ")) { // Is a spacer label, no need to make a team and shit for it as teams // don't seem to like the name only being a space and color scoreboard .getObjective(DisplaySlot.SIDEBAR) .getScore(label.getValue()) .setScore(label.getScore()); } else { int split = Math.round(label.getValue().length() / 2); final String key = label.getValue().substring(0, split); if (key.equals("")) { return; } final String value = label.getValue().substring(split, label.getValue().length()); scoreboard.getObjective(DisplaySlot.SIDEBAR).getScore(key).setScore(label.getScore()); if (scoreboard.getEntries().toArray().length != 0) { Team team = this.scoreboard.getTeam(key); if (team == null) { team = this.scoreboard.registerNewTeam(key); team.addPlayer(new FakeOfflinePlayer(key)); } team.setSuffix(value); } } } scores.put(label.getScore(), label); label.setUpdated(true); }
public static boolean rankedSidebarDisplay( Collection<Player> players, String title, HashMap<String, Integer> elements, Scoreboard board) { try { title = cutRankedTitle(title); elements = cutRanked(elements); String objName = "COLLAB-SB-WINTER"; if (board == null) board = Bukkit.getScoreboardManager().getNewScoreboard(); for (Player player : players) if (player.getScoreboard() != board) player.setScoreboard(board); if (board.getObjective(objName) == null) { board.registerNewObjective(objName, "dummy"); board.getObjective(objName).setDisplaySlot(DisplaySlot.SIDEBAR); } board.getObjective(DisplaySlot.SIDEBAR).setDisplayName(title); for (String string : elements.keySet()) if (board.getObjective(DisplaySlot.SIDEBAR).getScore(string).getScore() != elements.get(string)) board.getObjective(DisplaySlot.SIDEBAR).getScore(string).setScore(elements.get(string)); for (String string : new ArrayList<>(board.getEntries())) if (!elements.keySet().contains(string)) board.resetScores(string); return true; } catch (Exception e) { e.printStackTrace(); return false; } }