Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aaron1998ish
Created July 18, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaron1998ish/33c4e1836bd5cf79501d163a1b5c8304 to your computer and use it in GitHub Desktop.
Save aaron1998ish/33c4e1836bd5cf79501d163a1b5c8304 to your computer and use it in GitHub Desktop.
/**
* 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;
}
@BananaFructa
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment