CraftScoreboard(Scoreboard board) { this.board = board; for (ScoreboardObjective objective : (Iterable<ScoreboardObjective>) board.getObjectives()) { new CraftObjective(this, objective); // It adds itself to map } for (ScoreboardTeam team : (Iterable<ScoreboardTeam>) board.getTeams()) { new CraftTeam(this, team); // It adds itself to map } }
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException { Validate.notNull(name, "Objective name cannot be null"); Validate.notNull(criteria, "Criteria cannot be null"); Validate.isTrue(name.length() <= 16, "The name '" + name + "' is longer than the limit of 16 characters"); Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists"); CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria); ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria); return new CraftObjective(this, objective); }
public Objective getObjective(DisplaySlot slot) throws IllegalArgumentException { Validate.notNull(slot, "Display slot cannot be null"); ScoreboardObjective objective = board.getObjectiveForSlot(CraftScoreboardTranslations.fromBukkitSlot(slot)); if (objective == null) { return null; } return this.objectives.get(objective.getName()); }
CraftObjective(CraftScoreboard scoreboard, ScoreboardObjective objective) { super(scoreboard); this.objective = objective; this.criteria = CraftCriteria.getFromNMS(objective); scoreboard.objectives.put(objective.getName(), this); }
public void setDisplaySlot(DisplaySlot slot) throws IllegalStateException { CraftScoreboard scoreboard = checkState(); Scoreboard board = scoreboard.board; ScoreboardObjective objective = this.objective; for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) { if (board.getObjectiveForSlot(i) == objective) { board.setDisplaySlot(i, null); } } if (slot != null) { int slotNumber = CraftScoreboardTranslations.fromBukkitSlot(slot); board.setDisplaySlot(slotNumber, getHandle()); } }
public DisplaySlot getDisplaySlot() throws IllegalStateException { CraftScoreboard scoreboard = checkState(); Scoreboard board = scoreboard.board; ScoreboardObjective objective = this.objective; for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) { if (board.getObjectiveForSlot(i) == objective) { return CraftScoreboardTranslations.toBukkitSlot(i); } } return null; }
public Collection<ScoreboardScore> getScoreboardScores(IScoreboardCriteria criteria, String name, Collection<ScoreboardScore> collection) { for (CraftScoreboard scoreboard : scoreboards) { Scoreboard board = scoreboard.board; for (ScoreboardObjective objective : (Iterable<ScoreboardObjective>) board.getObjectivesForCriteria(criteria)) { collection.add(board.getPlayerScoreForObjective(name, objective)); } } return collection; }
public int getScore() throws IllegalStateException { Scoreboard board = objective.checkState().board; if (board.getPlayers().contains(entry)) { // Lazy Map<ScoreboardObjective, ScoreboardScore> scores = board.getPlayerObjectives(entry); ScoreboardScore score = scores.get(objective.getHandle()); if (score != null) { // Lazy return score.getScore(); } } return 0; // Lazy }
public ImmutableSet<Objective> getObjectivesByCriteria(String criteria) throws IllegalArgumentException { Validate.notNull(criteria, "Criteria cannot be null"); ImmutableSet.Builder<Objective> objectives = ImmutableSet.builder(); for (ScoreboardObjective netObjective : (Collection<ScoreboardObjective>) this.board.getObjectives()) { CraftObjective objective = new CraftObjective(this, netObjective); if (objective.getCriteria().equals(criteria)) { objectives.add(objective); } } return objectives.build(); }
public ImmutableSet<Objective> getObjectives() { return ImmutableSet.copyOf(Iterables.transform((Collection<ScoreboardObjective>) this.board.getObjectives(), new Function<ScoreboardObjective, Objective>() { @Override public Objective apply(ScoreboardObjective input) { return new CraftObjective(CraftScoreboard.this, input); } })); }
public Objective getObjective(DisplaySlot slot) throws IllegalArgumentException { Validate.notNull(slot, "Display slot cannot be null"); ScoreboardObjective objective = board.getObjectiveForSlot(CraftScoreboardTranslations.fromBukkitSlot(slot)); if (objective == null) { return null; } return new CraftObjective(this, objective); }
public ImmutableSet<Score> getScores(String entry) throws IllegalArgumentException { Validate.notNull(entry, "Entry cannot be null"); ImmutableSet.Builder<Score> scores = ImmutableSet.builder(); for (ScoreboardObjective objective : (Collection<ScoreboardObjective>) this.board.getObjectives()) { scores.add(new CraftScore(new CraftObjective(this, objective), entry)); } return scores.build(); }
public void resetScores(String entry) throws IllegalArgumentException { Validate.notNull(entry, "Entry cannot be null"); for (ScoreboardObjective objective : (Collection<ScoreboardObjective>) this.board.getObjectives()) { board.resetPlayerScores(entry, objective); } }
public void reset() throws IllegalStateException { CraftScoreboard myBoard = objective.checkState(); Map<ScoreboardObjective, ScoreboardScore> savedScores = myBoard.board.getPlayerObjectives(playerName); if (savedScores.remove(objective.getHandle()) == null) { // If they don't have a score to delete, don't delete it. return; } myBoard.board.resetPlayerScores(playerName); for (Map.Entry<ScoreboardObjective, ScoreboardScore> e : savedScores.entrySet()) { myBoard.board.getPlayerScoreForObjective(playerName, e.getKey()).setScore(e.getValue().getScore()); } }