Skip to content

Instantly share code, notes, and snippets.

@riking
Last active December 20, 2015 11:49
Show Gist options
  • Save riking/6125966 to your computer and use it in GitHub Desktop.
Save riking/6125966 to your computer and use it in GitHub Desktop.
Pseudocode for Faction scoreboards
This is pseudocode.
Faction {
private transient Scoreboard scoreboard = makenewscoreboard()
}
updateScoreboards() {
Set<Faction> toUpdate;
for (Player p : onlinePlayers) {
UPlayer up = UPlayer.get(p);
Faction pfaction = up.getFaction();
if (p.getScoreboard() == pfaction.getScoreboard()) {
toUpdate.add(pfaction);
}
}
Set<Faction> online = getOnlineFactions();
for (Faction fac : toUpdate) {
Scoreboard board = fac.getScoreboard();
for (Faction other : online) {
Team t = board.getTeam(compressName(other));
t.setPrefix(other.getColorTo(fac));
StringBuilder suffix = new StringBuilder(" [");
suffix.append(other.getName());
if (suffix.length() > (16 - 1)) {
suffix.delete(16 - 1, suffix.length());
}
suffix.append("]");
t.setSuffix(suffix.toString());
t.setDisplayName(other.getName()); // Unused, but still sent to client
t.setAllowFriendlyFire(fac == other);
t.setCanSeeFriendlyInvisibles(fac == other);
for (Player p : other.getOnlinePlayers()) {
t.addPlayer(p);
}
}
}
}
/**
* Compress the Faction's UUID into a unique string form that is less than 16 characters.
*
* @param Faction to get unique string for
* @return String of 16 characters or less
*/
private String compressName(Faction faction) {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment