-
-
Save aaron1998ish/33c4e1836bd5cf79501d163a1b5c8304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Fetching lines are based on how they're visually seen on your sidebar | |
* and not based on the actual value score. | |
* | |
* Written around Minecraft 1.8 Scoreboards, modify to work with your | |
* current version of Minecraft. | |
* | |
* <3 aaron1998ish | |
* | |
* @return a list of lines for a given scoreboard or empty | |
* if the worlds not loaded, scoreboard isnt present | |
* or if the sidebar objective isnt created. | |
*/ | |
public static List<String> getSidebarLines() { | |
List<String> lines = new ArrayList<>(); | |
Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard(); | |
if (scoreboard == null) { | |
return lines; | |
} | |
ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1); | |
if (objective == null) { | |
return lines; | |
} | |
Collection<Score> scores = scoreboard.getSortedScores(objective); | |
List<Score> list = Lists.newArrayList(scores.stream() | |
.filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName().startsWith("#")) | |
.collect(Collectors.toList())); | |
if (list.size() > 15) { | |
scores = Lists.newArrayList(Iterables.skip(list, scores.size() - 15)); | |
} else { | |
scores = list; | |
} | |
for (Score score : scores) { | |
ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); | |
lines.add(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName())); | |
} | |
return lines; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you this is very cool. I didnt know you have to format the name with the team data and i was trying to directly parse the name. Either way thanks.