Skip to content

Instantly share code, notes, and snippets.

@lualzockt
Created January 2, 2014 16:12
Show Gist options
  • Save lualzockt/8221573 to your computer and use it in GitHub Desktop.
Save lualzockt/8221573 to your computer and use it in GitHub Desktop.
public class ScoreboardHelper {
public static void displayObjective(Player player, String id, String title, DisplaySlot slot ,Map<String, Integer> values) {
Scoreboard board = player.getScoreboard();
if(board == null) {
board = Bukkit.getScoreboardManager().getNewScoreboard();
}
Objective obj = board.getObjective(id);
if(obj == null) {
obj = board.registerNewObjective(id, "dummy");
}
if(title.length > 32) {
title = title.substring(0, 31);
}
obj.setDisplaySlot(slot);
obj.setDisplayName(title);
for(String s : values.keySet()) {
if(s.length > 16) {
s = s.substring(0, 15);
}
OfflinePlayer op = Bukkit.getOfflinePlayer(s);
obj.getScore(op).setScore(values.get(s));
}
player.setScoreboard(board);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment