// Delete the contents of the scoreboardMap and viewerMap
scoreboardMap.clear();
viewerMap.clear();
ConfigurationSection rootSection = DenizenAPI.getCurrentInstance()
.getScoreboards().getConfigurationSection("Scoreboards");
// Go no further if we have no scoreboards saved
if (rootSection == null) return;
Scoreboard board = null;
// Iterate through scoreboards
for (String id : rootSection.getKeys(false)) {
// Create a scoreboard with this id
board = createScoreboard(id);
// Get the list of viewers
List<String> viewerList = rootSection.getStringList(id + ".Viewers");
// Iterate through viewers, store them in the viewerMap,
// and make them see this scoreboard if they are online
for (String viewer : viewerList) {
if (dPlayer.matches(viewer)) {
dPlayer player = dPlayer.valueOf(viewer);
viewerMap.put(player.getName(), id);
if (player.isOnline())
player.getPlayerEntity().setScoreboard(board);
}
}
ConfigurationSection objSection = rootSection
.getConfigurationSection(id + ".Objectives");
// Go no further if we have no objectives saved
if (objSection == null) return;
// Iterate through objectives
for (String obj : objSection.getKeys(false)) {
// Get display slot and criteria for this objective
String displaySlot = objSection.getString(obj + ".Display slot");
String criteria = objSection.getString(obj + ".Criteria");
// Use default criteria if necessary
if (criteria == null)
criteria = "dummy";
// Use default display slot if necessary
if (displaySlot == null)
displaySlot = "NONE";
// Register the objective and set it up
Objective o = board.registerNewObjective(obj, criteria);
o.setDisplayName(obj);
// Only set display slot if it's valid
if (Argument.valueOf(displaySlot).matchesEnum(DisplaySlot.values())) {
o.setDisplaySlot(DisplaySlot.valueOf(displaySlot.toUpperCase()));
}
ConfigurationSection scoreSection = objSection
.getConfigurationSection(obj + ".Scores");
if (scoreSection != null) {
// Iterate through scores and add them to this objective
for (String scoreName : scoreSection.getKeys(false)) {
int scoreInt = scoreSection.getInt(scoreName);
addScore(o, ScoreboardCommand.getOfflinePlayer(scoreName), scoreInt);
}
}
}
}