org.bukkit.scoreboard.Score Java Examples

The following examples show how to use org.bukkit.scoreboard.Score. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EffSetScore.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: Arena.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
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);
		}
	}
}
 
Example #4
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #5
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
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);
  }
}
 
Example #6
Source File: EffDeleteIdScore.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example #7
Source File: IdScoreBoardManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #8
Source File: IdScoreBoardManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
    }

}
 
Example #9
Source File: IdScoreBoardManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example #10
Source File: IdScoreBoardManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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());
    }

}
 
Example #11
Source File: EffSetIdBasedScore.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@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));
    }
}
 
Example #12
Source File: Arena.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
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);
			}
		}
	}
}
 
Example #13
Source File: ScoreboardEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #14
Source File: ScoreboardCondition.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
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);
  }
}
 
Example #16
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #17
Source File: CraftScoreboard.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #18
Source File: CraftScoreboard.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #19
Source File: CraftScore.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
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
}
 
Example #20
Source File: ScoreboardAPI.java    From AnnihilationPro with MIT License 5 votes vote down vote up
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());
	}
}
 
Example #21
Source File: Game.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #22
Source File: AssembleBoardEntry.java    From Assemble with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #23
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #24
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #25
Source File: CraftScore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
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
}
 
Example #26
Source File: CraftObjective.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
    Validate.notNull(player, "Player cannot be null");
    CraftScoreboard scoreboard = checkState();

    return new CraftScore(this, player.getName());
}
 
Example #27
Source File: SingleScore.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
public Score getScore() {
    return this.score;
}
 
Example #28
Source File: SingleScore.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
public SingleScore(Score score, Player player) {
    this.score = score;
    this.player = player;
}
 
Example #29
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public ImmutableSet<Score> getScores(OfflinePlayer player) throws IllegalArgumentException {
    Validate.notNull(player, "OfflinePlayer cannot be null");

    return getScores(player.getName());
}
 
Example #30
Source File: IdScoreBoardManager.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
void setScoreId(String id, Score score, Player player) {
    singleScoreMap.put(id, new SingleScore(score, player));
}