()
| 77 | } |
| 78 | |
| 79 | public void update() { |
| 80 | // Checking if we are ready to start updating the Scoreboard. |
| 81 | if (!ready) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | // Making sure the player is connected. |
| 86 | if (!player.isOnline()) { |
| 87 | remove(); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | // Making sure the Scoreboard Provider is set. |
| 92 | if (boardSettings == null) { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | // Getting their Scoreboard display from the Scoreboard Provider. |
| 97 | final List<String> entries = boardSettings.getBoardProvider().getLines(player).stream().map(APPLY_COLOR_TRANSLATION).collect(Collectors.toList()); |
| 98 | |
| 99 | if (boardSettings.getScoreDirection() == ScoreDirection.UP) { |
| 100 | Collections.reverse(entries); |
| 101 | } |
| 102 | |
| 103 | // Setting the Scoreboard title |
| 104 | String title = boardSettings.getBoardProvider().getTitle(player); |
| 105 | if (title.length() > 32) { |
| 106 | Bukkit.getLogger().warning("The title " + title + " is over 32 characters in length, substringing to prevent errors."); |
| 107 | title = title.substring(0, 32); |
| 108 | } |
| 109 | objective.setDisplayName(C.translateAlternateColorCodes('&', title)); |
| 110 | |
| 111 | // Clearing previous Scoreboard values if entry sizes don't match. |
| 112 | if (this.getScoreboard().getEntries().size() != entries.size()) |
| 113 | this.getScoreboard().getEntries().forEach(this::removeEntry); |
| 114 | |
| 115 | // Setting Scoreboard lines. |
| 116 | for (int i = 0; i < entries.size(); i++) { |
| 117 | String str = entries.get(i); |
| 118 | BoardEntry entry = BoardEntry.translateToEntry(str); |
| 119 | Team team = getScoreboard().getTeam(CACHED_ENTRIES[i]); |
| 120 | |
| 121 | if (team == null) { |
| 122 | team = this.getScoreboard().registerNewTeam(CACHED_ENTRIES[i]); |
| 123 | team.addEntry(team.getName()); |
| 124 | } |
| 125 | |
| 126 | team.setPrefix(entry.getPrefix()); |
| 127 | team.setSuffix(entry.getSuffix()); |
| 128 | |
| 129 | switch (boardSettings.getScoreDirection()) { |
| 130 | case UP: |
| 131 | objective.getScore(team.getName()).setScore(1 + i); |
| 132 | break; |
| 133 | case DOWN: |
| 134 | objective.getScore(team.getName()).setScore(15 - i); |
| 135 | break; |
| 136 | } |
no test coverage detected