Scoreboard for invalid objective shouldn't fail since objective names are not fixed and provided by players.

This commit is contained in:
gnembon committed 2020-11-23 22:08:06 -04:00
1 parent a297fd1441
commit 550e53aec7
2 files changed
+6 -4

No files matched your search

+4 -2
View File
@@ -3,7 +3,8 @@
### `scoreboard()`, `scoreboard(objective)`, `scoreboard(objective, key)`, `scoreboard(objective, key, value)` ### `scoreboard()`, `scoreboard(objective)`, `scoreboard(objective, key)`, `scoreboard(objective, key, value)`
Displays or modifies individual scoreboard values. With no arguments, returns the list of current objectives. Displays or modifies individual scoreboard values. With no arguments, returns the list of current objectives.
With specified `objective`, lists all keys (players) associated with current objective. With specified `objective`, With specified `objective`, lists all keys (players) associated with current objective, or `null` if objective does not exist.
With specified `objective` and
`key`, returns current value of the objective for a given player (key). With additional `value` sets a new scoreboard `key`, returns current value of the objective for a given player (key). With additional `value` sets a new scoreboard
value, returning previous value associated with the `key`. value, returning previous value associated with the `key`.
@@ -26,4 +27,5 @@ for the objective.
### `scoreboard_display(place, objective)` ### `scoreboard_display(place, objective)`
sets display location for a specified `objective`. If `objective` is `null`, then display is cleared. sets display location for a specified `objective`. If `objective` is `null`, then display is cleared. If objective is invalid,
returns `null`.
@@ -56,7 +56,7 @@ public class Scoreboards {
} }
String objectiveName = lv.get(0).evalValue(c).getString(); String objectiveName = lv.get(0).evalValue(c).getString();
ScoreboardObjective objective = scoreboard.getObjective(objectiveName); ScoreboardObjective objective = scoreboard.getObjective(objectiveName);
if (objective == null) throw new InternalExpressionException("Unknown objective: "+objectiveName); if (objective == null) return LazyValue.NULL;
if (lv.size()==1) if (lv.size()==1)
{ {
Value ret = ListValue.wrap(scoreboard.getAllPlayerScores(objective).stream().map(s -> new StringValue(s.getPlayerName())).collect(Collectors.toList())); Value ret = ListValue.wrap(scoreboard.getAllPlayerScores(objective).stream().map(s -> new StringValue(s.getPlayerName())).collect(Collectors.toList()));
@@ -143,7 +143,7 @@ public class Scoreboards {
} }
String objectiveString = target.getString(); String objectiveString = target.getString();
ScoreboardObjective objective = scoreboard.getObjective(objectiveString); ScoreboardObjective objective = scoreboard.getObjective(objectiveString);
if (objective == null) throw new InternalExpressionException("Objective doesn't exist: "+objectiveString); if (objective == null) return LazyValue.NULL;
scoreboard.setObjectiveSlot(slot, objective); scoreboard.setObjectiveSlot(slot, objective);
return (_c, _t) -> new NumericValue(slot); return (_c, _t) -> new NumericValue(slot);
}); });