Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
Add ability to add a string to a scoreboard instead of a player
Dieser Commit ist enthalten in:
Ursprung
e9980aa94f
Commit
55202e1f99
@ -110,6 +110,13 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|||||||
return team == null ? null : new CraftTeam(this, team);
|
return team == null ? null : new CraftTeam(this, team);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Team getEntryTeam(String entry) throws IllegalArgumentException {
|
||||||
|
Validate.notNull(entry, "Entry cannot be null");
|
||||||
|
|
||||||
|
ScoreboardTeam team = board.getPlayerTeam(entry);
|
||||||
|
return team == null ? null : new CraftTeam(this, team);
|
||||||
|
}
|
||||||
|
|
||||||
public Team getTeam(String teamName) throws IllegalArgumentException {
|
public Team getTeam(String teamName) throws IllegalArgumentException {
|
||||||
Validate.notNull(teamName, "Team name cannot be null");
|
Validate.notNull(teamName, "Team name cannot be null");
|
||||||
|
|
||||||
|
@ -102,19 +102,30 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
|||||||
public void setNameTagVisibility(NameTagVisibility visibility) throws IllegalArgumentException {
|
public void setNameTagVisibility(NameTagVisibility visibility) throws IllegalArgumentException {
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
team.setNameTagVisibility(bukkitToNotch(visibility));
|
team.setNameTagVisibility(bukkitToNotch(visibility));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<OfflinePlayer> getPlayers() throws IllegalStateException {
|
public Set<OfflinePlayer> getPlayers() throws IllegalStateException {
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
ImmutableSet.Builder<OfflinePlayer> players = ImmutableSet.builder();
|
ImmutableSet.Builder<OfflinePlayer> players = ImmutableSet.builder();
|
||||||
for (Object o : team.getPlayerNameSet()) {
|
for (String playerName : team.getPlayerNameSet()) {
|
||||||
players.add(Bukkit.getOfflinePlayer(o.toString()));
|
players.add(Bukkit.getOfflinePlayer(playerName));
|
||||||
}
|
}
|
||||||
return players.build();
|
return players.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getEntries() throws IllegalStateException {
|
||||||
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
|
ImmutableSet.Builder<String> entries = ImmutableSet.builder();
|
||||||
|
for (String playerName: team.getPlayerNameSet()){
|
||||||
|
entries.add(playerName);
|
||||||
|
}
|
||||||
|
return entries.build();
|
||||||
|
}
|
||||||
|
|
||||||
public int getSize() throws IllegalStateException {
|
public int getSize() throws IllegalStateException {
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
@ -123,28 +134,44 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
|||||||
|
|
||||||
public void addPlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException {
|
public void addPlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException {
|
||||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||||
|
addEntry(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEntry(String entry) throws IllegalStateException, IllegalArgumentException {
|
||||||
|
Validate.notNull(entry, "Entry cannot be null");
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
scoreboard.board.addPlayerToTeam(player.getName(), team.getName());
|
scoreboard.board.addPlayerToTeam(entry, team.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removePlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException {
|
public boolean removePlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException {
|
||||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||||
|
return removeEntry(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeEntry(String entry) throws IllegalStateException, IllegalArgumentException {
|
||||||
|
Validate.notNull(entry, "Entry cannot be null");
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
if (!team.getPlayerNameSet().contains(player.getName())) {
|
if (!team.getPlayerNameSet().contains(entry)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreboard.board.removePlayerFromTeam(player.getName(), team);
|
scoreboard.board.removePlayerFromTeam(entry, team);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPlayer(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
|
public boolean hasPlayer(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
|
||||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||||
|
return hasEntry(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasEntry(String entry) throws IllegalArgumentException, IllegalStateException {
|
||||||
|
Validate.notNull("Entry cannot be null");
|
||||||
|
|
||||||
CraftScoreboard scoreboard = checkState();
|
CraftScoreboard scoreboard = checkState();
|
||||||
|
|
||||||
return team.getPlayerNameSet().contains(player.getName());
|
return team.getPlayerNameSet().contains(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -212,5 +239,4 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
|||||||
return !(this.team != other.team && (this.team == null || !this.team.equals(other.team)));
|
return !(this.team != other.team && (this.team == null || !this.team.equals(other.team)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren