Java Code Examples for org.bukkit.scoreboard.Score#setScore()

The following examples show how to use org.bukkit.scoreboard.Score#setScore() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 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: 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 18
Source File: TagUtils.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Refreshes tag of a player
 *
 * @param p target player
 */
@SuppressWarnings("deprecation")
public static void refresh(Player p) {
	if(!Config.TAGAPI_ENABLED.getBoolean()) {
		return;
	}

	Scoreboard board = p.getScoreboard();
	for(Player player : CompatibilityUtils.getOnlinePlayers()) {
		NovaPlayer nPlayerLoop = PlayerManager.getPlayer(player);

		String tName = "ng_" + player.getName();
		if(tName.length() > 16) {
			tName = tName.substring(0, 16);
		}

		Team team = board.getTeam(tName);

		if(team == null) {
			team = board.registerNewTeam(tName);
			team.addPlayer(player);
		}

		//Points
		Objective pointsObjective = board.getObjective("points");
		if(Config.POINTSBELOWNAME.getBoolean()) {
			if(pointsObjective == null) {
				pointsObjective = board.registerNewObjective("points", "dummy");
				pointsObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
				pointsObjective.setDisplayName(Message.MISC_POINTSBELOWNAME.get());
			}

			Score score = pointsObjective.getScore(player);
			score.setScore(nPlayerLoop.getPoints());
		}
		else if(pointsObjective != null) {
			pointsObjective.unregister();
		}

		//set tag
		PreparedTag tag = new PreparedTagScoreboardImpl(PlayerManager.getPlayer(player));
		tag.setTagColorFor(PlayerManager.getPlayer(p));
		team.setPrefix(tag.get());
	}
}