下面列出了怎么用org.bukkit.scoreboard.Score的API类实例代码及写法,或者点击链接到github查看源代码。
public void updateScoreboard() {
if (!getOriginalOrInheritedScoreaboard()) {
return;
}
Objective obj = this.gameScoreboard.getObjective("display");
if (obj == null) {
obj = this.gameScoreboard.registerNewObjective("display", "dummy");
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(this.formatScoreboardTitle());
for (CurrentTeam team : teamsInGame) {
this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, false));
this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, true));
this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, true, false));
Score score = obj.getScore(this.formatScoreboardTeam(team, !team.isBed, team.isBed && "RESPAWN_ANCHOR".equals(team.teamInfo.bed.getBlock().getType().name()) && Player116ListenerUtils.isAnchorEmpty(team.teamInfo.bed.getBlock())));
score.setScore(team.players.size());
}
for (GamePlayer player : players) {
player.player.setScoreboard(gameScoreboard);
}
}
public void updateScoreboard() {
if (!getOriginalOrInheritedScoreaboard()) {
return;
}
Objective obj = this.gameScoreboard.getObjective("display");
if (obj == null) {
obj = this.gameScoreboard.registerNewObjective("display", "dummy");
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(this.formatScoreboardTitle());
for (CurrentTeam team : teamsInGame) {
this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, false));
this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, false, true));
this.gameScoreboard.resetScores(this.formatScoreboardTeam(team, true, false));
Score score = obj.getScore(this.formatScoreboardTeam(team, !team.isBed, team.isBed && "RESPAWN_ANCHOR".equals(team.teamInfo.bed.getBlock().getType().name()) && Player116ListenerUtils.isAnchorEmpty(team.teamInfo.bed.getBlock())));
score.setScore(team.players.size());
}
for (GamePlayer player : players) {
player.player.setScoreboard(gameScoreboard);
}
}
public void decrementTimer() {
if (timeleft <= 0) {
if (!ended) {
CivMessage.sendArena(this, "Time is up! Nobody Wins!");
ArenaManager.declareDraw(this);
ended = true;
}
} else {
this.timeleft--;
for (ArenaTeam team : this.teams.values()) {
Objective obj = objectives.get(team.getName()+";score");
Score score = obj.getScore("Time Left");
score.setScore(timeleft);
}
}
}
@Override
protected void execute(Event evt) {
if (player == null || num == null || player.getSingle(evt).getScoreboard() == null) {
Skript.error("This player is either not online or has yet to have a scoreboard set for them");
return;
}
Scoreboard sb = player.getSingle(evt).getScoreboard();
Objective objective = sb.getObjective(DisplaySlot.SIDEBAR);
Score score;
if (name.getSingle(evt) == null){
Skript.warning("First arg in \"set score %string% in sidebar of %player% to %number%\" was null. " +
"Objective will now be named null.");
score = objective.getScore("null");
} else {
score = objective.getScore(name.getSingle(evt).replace("\"", ""));
}
score.setScore(num.getSingle(evt).intValue());
}
private void updateLobbyScoreboard() {
if (status != GameStatus.WAITING || !getOriginalOrInheritedLobbyScoreaboard()) {
return;
}
gameScoreboard.clearSlot(DisplaySlot.SIDEBAR);
Objective obj = gameScoreboard.getObjective("lobby");
if (obj != null) {
obj.unregister();
}
obj = gameScoreboard.registerNewObjective("lobby", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(this.formatLobbyScoreboardString(
Main.getConfigurator().config.getString("lobby-scoreboard.title", "§eBEDWARS")));
List<String> rows = Main.getConfigurator().config.getStringList("lobby-scoreboard.content");
int rowMax = rows.size();
if (rows == null || rows.isEmpty()) {
return;
}
for (String row : rows) {
if (row.trim().equals("")) {
for (int i = 0; i <= rowMax; i++) {
row = row + " ";
}
}
Score score = obj.getScore(this.formatLobbyScoreboardString(row));
score.setScore(rowMax);
rowMax--;
}
for (GamePlayer player : players) {
player.player.setScoreboard(gameScoreboard);
}
}
public void send(int position) {
if (this.text.length() > 16) {
String prefix = this.text.substring(0, 16);
String suffix;
if (prefix.charAt(15) == ChatColor.COLOR_CHAR) {
prefix = prefix.substring(0, 15);
suffix = this.text.substring(15, this.text.length());
} else if (prefix.charAt(14) == ChatColor.COLOR_CHAR) {
prefix = prefix.substring(0, 14);
suffix = this.text.substring(14, this.text.length());
} else {
if (ChatColor.getLastColors(prefix).equalsIgnoreCase(ChatColor.getLastColors(this.identifier))) {
suffix = this.text.substring(16, this.text.length());
} else {
suffix = ChatColor.getLastColors(prefix) + this.text.substring(16, this.text.length());
}
}
if (suffix.length() > 16) {
suffix = suffix.substring(0, 16);
}
this.team.setPrefix(prefix);
this.team.setSuffix(suffix);
} else {
this.team.setPrefix(this.text);
this.team.setSuffix("");
}
Score score = this.board.getObjective().getScore(this.identifier);
score.setScore(position);
}
private void updateLobbyScoreboard() {
if (status != GameStatus.WAITING || !getOriginalOrInheritedLobbyScoreaboard()) {
return;
}
gameScoreboard.clearSlot(DisplaySlot.SIDEBAR);
Objective obj = gameScoreboard.getObjective("lobby");
if (obj != null) {
obj.unregister();
}
obj = gameScoreboard.registerNewObjective("lobby", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(this.formatLobbyScoreboardString(
Main.getConfigurator().config.getString("lobby-scoreboard.title", "§eBEDWARS")));
List<String> rows = Main.getConfigurator().config.getStringList("lobby-scoreboard.content");
int rowMax = rows.size();
if (rows == null || rows.isEmpty()) {
return;
}
for (String row : rows) {
if (row.trim().equals("")) {
for (int i = 0; i <= rowMax; i++) {
row = row + " ";
}
}
Score score = obj.getScore(this.formatLobbyScoreboardString(row));
score.setScore(rowMax);
rowMax--;
}
for (GamePlayer player : players) {
player.player.setScoreboard(gameScoreboard);
}
}
public int getScore() throws IllegalStateException {
Scoreboard board = objective.checkState().board;
if (board.getObjectiveNames().contains(entry)) { // Lazy
Map<ScoreObjective, net.minecraft.scoreboard.Score> scores = board.getObjectivesForEntity(entry);
net.minecraft.scoreboard.Score score = scores.get(objective.getHandle());
if (score != null) { // Lazy
return score.getScorePoints();
}
}
return 0; // Lazy
}
public ImmutableSet<Score> getScores(String entry) throws IllegalArgumentException {
Validate.notNull(entry, "Entry cannot be null");
ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
for (ScoreObjective objective : (Collection<ScoreObjective>) this.board.getScoreObjectives()) {
scores.add(new CraftScore(new CraftObjective(this, objective), entry));
}
return scores.build();
}
public void Scoreboard(Player player) {
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective objective = board.registerNewObjective("test", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName("Scoreboard");
objective.getName();
Score score = objective.getScore(ChatColor.GREEN + "Kills:"); //Get a fake offline player
score.setScore(1);
}
public static void updatePhase()
{
if(Game.isGameRunning() && Game.getGameMap() != null)
{
Score score = obj.getScore(Util.shortenString(Lang.SCOREBOARDPHASE.toString(), 16));
score.setScore(Game.getGameMap().getCurrentPhase());
}
}
public int getScore() throws IllegalStateException {
net.minecraft.scoreboard.Scoreboard board = objective.checkState().board;
if (board.getObjectiveNames().contains(entry)) { // Lazy
Map<String, net.minecraft.scoreboard.Score> scores = board.func_96510_d(entry);
net.minecraft.scoreboard.Score score = scores.get(objective.getHandle());
if (score != null) { // Lazy
return score.getScorePoints();
}
}
return 0; // Lazy
}
public ImmutableSet<Score> getScores(OfflinePlayer player) throws IllegalArgumentException {
Validate.notNull(player, "OfflinePlayer cannot be null");
ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
for (CraftObjective objective : objectives.values()) {
scores.add(objective.getScore(player));
}
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();
}
private void updateLobbyScoreboard() {
this.scoreboard.clearSlot(DisplaySlot.SIDEBAR);
Objective obj = this.scoreboard.getObjective("lobby");
if (obj != null) {
obj.unregister();
}
obj = this.scoreboard.registerNewObjective("lobby", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(this.formatLobbyScoreboardString(
BedwarsRel.getInstance().getStringConfig("lobby-scoreboard.title", "&eBEDWARS")));
List<String> rows = BedwarsRel.getInstance().getConfig()
.getStringList("lobby-scoreboard.content");
int rowMax = rows.size();
if (rows == null || rows.isEmpty()) {
return;
}
for (String row : rows) {
if (row.trim().equals("")) {
for (int i = 0; i <= rowMax; i++) {
row = row + " ";
}
}
Score score = obj.getScore(this.formatLobbyScoreboardString(row));
score.setScore(rowMax);
rowMax--;
}
for (Player player : this.getPlayers()) {
player.setScoreboard(this.scoreboard);
}
}
public void updateScoreboard() {
if (this.state == GameState.WAITING
&& BedwarsRel.getInstance().getBooleanConfig("lobby-scoreboard.enabled", true)) {
this.updateLobbyScoreboard();
return;
}
Objective obj = this.scoreboard.getObjective("display");
if (obj == null) {
obj = this.scoreboard.registerNewObjective("display", "dummy");
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(this.formatScoreboardTitle());
for (Team t : this.teams.values()) {
this.scoreboard.resetScores(this.formatScoreboardTeam(t, false));
this.scoreboard.resetScores(this.formatScoreboardTeam(t, true));
boolean teamDead = (t.isDead(this) && this.getState() == GameState.RUNNING) ? true : false;
Score score = obj.getScore(this.formatScoreboardTeam(t, teamDead));
score.setScore(t.getPlayers().size());
}
for (Player player : this.getPlayers()) {
player.setScoreboard(this.scoreboard);
}
}
@Override
protected Boolean execute(String playerID) throws QuestRuntimeException {
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
Objective obj = board.getObjective(objective);
if (obj == null) {
throw new QuestRuntimeException("Scoreboard objective " + objective + " does not exist!");
}
Score score = obj.getScore(PlayerConverter.getName(playerID));
return score.getScore() >= count.getInt(playerID);
}
@Override
protected Void execute(String playerID) throws IllegalStateException, QuestRuntimeException {
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
Objective obj = board.getObjective(objective);
if (obj == null) {
throw new QuestRuntimeException("Scoreboard objective " + objective + " does not exist!");
}
Score score = obj.getScore(PlayerConverter.getName(playerID));
if (multi) {
score.setScore((int) Math.floor(score.getScore() * count.getDouble(playerID)));
} else {
score.setScore((int) Math.floor(score.getScore() + count.getDouble(playerID)));
}
return null;
}
public void decrementScoreForTeamID(int teamID) {
ArenaTeam team = getTeamFromID(teamID);
for (ArenaTeam t : this.teams.values()) {
Objective obj = this.objectives.get(t.getName()+";score");
for (ArenaTeam t2 : this.teams.values()) {
Score score = obj.getScore(t2.getTeamScoreboardName());
if (t2.getName().equals(team.getName())) {
score.setScore(score.getScore() - 1);
}
}
}
}
@Override
protected void execute(Event evt) {
if (player == null || num == null || name == null
|| player.getSingle(evt).getScoreboard() == null) {
Skript.error("This player is either not online or has yet to have a scoreboard set for them");
} else {
Scoreboard sb = player.getSingle(evt).getScoreboard();
Objective objective = sb.getObjective(DisplaySlot.SIDEBAR);
Score score = objective.getScore(name.getSingle(evt).replace("\"", ""));
score.setScore(num.getSingle(evt).intValue());
Core.sbManager.setScoreId(id.getSingle(evt).replace("\"", ""), score, player.getSingle(evt));
}
}
/**
* Add a player to a group score by ID.
*
* @param id The ID text for the group score.
* @param player The player to be added.
*/
void addPlayerToGroupId(String id, Player player) {
if (groupScoreMap.containsKey(id) && player != null) {
groupMap.get(id).add(player);
GroupScore score = groupScoreMap.get(id);
Score newScore =
player.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(score.getName());
newScore.setScore(score.getValue());
}
}
/**
* Update group scores by ID. This will replace the old scores for all players in the group.
*
* @param id The ID text for the group score.
* @param newName New name of the score.
* @param newValue New value of the score.
*/
void groupUpdateScore(String id, String newName, int newValue) {
if (groupScoreMap.containsKey(id) && groupMap.get(id) != null) {
ArrayList<Player> ls = groupMap.get(id);
GroupScore old = groupScoreMap.get(id);
for (Player p : ls) {
Objective obj = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR);
obj.getScoreboard().resetScores(old.getName());
Score newScore = obj.getScore(newName);
newScore.setScore(newValue);
}
groupScoreMap.put(id, new GroupScore(newName, newValue));
}
}
/**
* Update a single score by ID. This will replace the old score for the player.
*
* @param id The ID text for the single score.
* @param newName New name of the score.
* @param newValue New value of the score.
*/
void updateSingleScore(String id, String newName, int newValue) {
if (singleScoreMap.containsKey(id)) {
SingleScore old = singleScoreMap.get(id);
Player player = old.getPlayer();
Objective obj = player.getScoreboard().getObjective(DisplaySlot.SIDEBAR);
Score newScore = obj.getScore(newName);
obj.getScoreboard().resetScores(old.getScore().getEntry());
newScore.setScore(newValue);
singleScoreMap.put(id, new SingleScore(newScore, player));
}
}
/**
* Get a single score by ID.
*
* @param id The ID text for the single score.
*/
Score getScore(String id) {
if (singleScoreMap.containsKey(id)) {
return singleScoreMap.get(id).getScore();
} else {
return null;
}
}
@Override
protected void execute(Event evt) {
String usedId = id.getSingle(evt).replace("\"", "");
if (Core.sbManager.getScore(usedId) != null) {
Score score = Core.sbManager.getScore(usedId);
Objective obj = score.getObjective();
obj.getScoreboard().resetScores(score.getEntry());
Core.sbManager.deleteScoreId(usedId);
}
}
public ImmutableSet<Score> getScores(OfflinePlayer player) throws IllegalArgumentException {
Validate.notNull(player, "OfflinePlayer cannot be null");
return getScores(player.getName());
}
public Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
Validate.notNull(player, "Player cannot be null");
CraftScoreboard scoreboard = checkState();
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);
}
public Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
Validate.notNull(player, "Player cannot be null");
CraftScoreboard scoreboard = checkState();
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);
}