Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-21 05:50:05 +01:00
Add methods to use arbitrary entries in scoreboards. Adds BUKKIT-3977
Dieser Commit ist enthalten in:
Ursprung
3dcf159ec1
Commit
5557856144
@ -93,6 +93,13 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
|
|||||||
return new CraftScore(this, player.getName());
|
return new CraftScore(this, player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Score getScore(String entry) throws IllegalArgumentException, IllegalStateException {
|
||||||
|
Validate.notNull(entry, "Entry cannot be null");
|
||||||
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
|
return new CraftScore(this, entry);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregister() throws IllegalStateException {
|
public void unregister() throws IllegalStateException {
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
@ -17,16 +17,20 @@ import org.bukkit.scoreboard.Score;
|
|||||||
* Also, as an added perk, a CraftScore will (intentionally) stay a valid reference so long as objective is valid.
|
* Also, as an added perk, a CraftScore will (intentionally) stay a valid reference so long as objective is valid.
|
||||||
*/
|
*/
|
||||||
final class CraftScore implements Score {
|
final class CraftScore implements Score {
|
||||||
private final String playerName;
|
private final String entry;
|
||||||
private final CraftObjective objective;
|
private final CraftObjective objective;
|
||||||
|
|
||||||
CraftScore(CraftObjective objective, String playerName) {
|
CraftScore(CraftObjective objective, String entry) {
|
||||||
this.objective = objective;
|
this.objective = objective;
|
||||||
this.playerName = playerName;
|
this.entry = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfflinePlayer getPlayer() {
|
public OfflinePlayer getPlayer() {
|
||||||
return Bukkit.getOfflinePlayer(playerName);
|
return Bukkit.getOfflinePlayer(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntry() {
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Objective getObjective() {
|
public Objective getObjective() {
|
||||||
@ -36,18 +40,19 @@ final class CraftScore implements Score {
|
|||||||
public int getScore() throws IllegalStateException {
|
public int getScore() throws IllegalStateException {
|
||||||
Scoreboard board = objective.checkState().board;
|
Scoreboard board = objective.checkState().board;
|
||||||
|
|
||||||
if (board.getPlayers().contains(playerName)) { // Lazy
|
if (board.getPlayers().contains(entry)) { // Lazy
|
||||||
Map<String, ScoreboardScore> scores = board.getPlayerObjectives(playerName);
|
Map<String, ScoreboardScore> scores = board.getPlayerObjectives(entry);
|
||||||
ScoreboardScore score = scores.get(objective.getHandle());
|
ScoreboardScore score = scores.get(objective.getHandle());
|
||||||
if (score != null) { // Lazy
|
if (score != null) { // Lazy
|
||||||
return score.getScore();
|
return score.getScore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // Lazy
|
return 0; // Lazy
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(int score) throws IllegalStateException {
|
public void setScore(int score) throws IllegalStateException {
|
||||||
objective.checkState().board.getPlayerScoreForObjective(playerName, objective.getHandle()).setScore(score);
|
objective.checkState().board.getPlayerScoreForObjective(entry, objective.getHandle()).setScore(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftScoreboard getScoreboard() {
|
public CraftScoreboard getScoreboard() {
|
||||||
|
@ -84,12 +84,28 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|||||||
return scores.build();
|
return scores.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImmutableSet<Score> getScores(String entry) throws IllegalArgumentException {
|
||||||
|
Validate.notNull(entry, "Entry cannot be null");
|
||||||
|
|
||||||
|
ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
|
||||||
|
for (CraftObjective objective : objectives.values()) {
|
||||||
|
scores.add(objective.getScore(entry));
|
||||||
|
}
|
||||||
|
return scores.build();
|
||||||
|
}
|
||||||
|
|
||||||
public void resetScores(OfflinePlayer player) throws IllegalArgumentException {
|
public void resetScores(OfflinePlayer player) throws IllegalArgumentException {
|
||||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||||
|
|
||||||
board.resetPlayerScores(player.getName());
|
board.resetPlayerScores(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetScores(String entry) throws IllegalArgumentException {
|
||||||
|
Validate.notNull(entry, "Entry cannot be null");
|
||||||
|
|
||||||
|
board.resetPlayerScores(entry);
|
||||||
|
}
|
||||||
|
|
||||||
public Team getPlayerTeam(OfflinePlayer player) throws IllegalArgumentException {
|
public Team getPlayerTeam(OfflinePlayer player) throws IllegalArgumentException {
|
||||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||||
|
|
||||||
@ -123,6 +139,14 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|||||||
return players.build();
|
return players.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImmutableSet<String> getEntries() {
|
||||||
|
ImmutableSet.Builder<String> entries = ImmutableSet.builder();
|
||||||
|
for (Object entry : board.getPlayers()) {
|
||||||
|
entries.add(entry.toString());
|
||||||
|
}
|
||||||
|
return entries.build();
|
||||||
|
}
|
||||||
|
|
||||||
public void clearSlot(DisplaySlot slot) throws IllegalArgumentException {
|
public void clearSlot(DisplaySlot slot) throws IllegalArgumentException {
|
||||||
Validate.notNull(slot, "Slot cannot be null");
|
Validate.notNull(slot, "Slot cannot be null");
|
||||||
board.setDisplaySlot(CraftScoreboardTranslations.fromBukkitSlot(slot), null);
|
board.setDisplaySlot(CraftScoreboardTranslations.fromBukkitSlot(slot), null);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren