Search in sources :

Example 1 with ScoreboardScoreMessage

use of net.glowstone.net.message.play.scoreboard.ScoreboardScoreMessage in project Glowstone by GlowstoneMC.

the class GlowScore method setScore.

/**
 * Sets this score's value.
 * @param score the new value
 * @throws IllegalStateException if the objective is not registered on a scoreboard
 */
@Override
public void setScore(int score) throws IllegalStateException {
    objective.checkValid();
    this.score = score;
    objective.getScoreboard().broadcast(new ScoreboardScoreMessage(entry, objective.getName(), score));
}
Also used : ScoreboardScoreMessage(net.glowstone.net.message.play.scoreboard.ScoreboardScoreMessage)

Example 2 with ScoreboardScoreMessage

use of net.glowstone.net.message.play.scoreboard.ScoreboardScoreMessage in project Glowstone by GlowstoneMC.

the class GlowScoreboard method subscribe.

// //////////////////////////////////////////////////////////////////////////
// Internals
/**
 * Send a player this scoreboard's contents and subscribe them to future changes.
 *
 * @param player The player to subscribe.
 */
public void subscribe(GlowPlayer player) {
    // objectives
    for (GlowObjective objective : objectives.values()) {
        player.getSession().send(ScoreboardObjectiveMessage.create(objective.getName(), new TextMessage(objective.getDisplayName())));
    }
    // display slots
    for (DisplaySlot slot : DisplaySlot.values()) {
        GlowObjective objective = displaySlots.get(slot);
        String name = objective != null ? objective.getName() : "";
        player.getSession().send(new ScoreboardDisplayMessage(GlowDisplaySlot.getId(slot), name));
    }
    // scores
    for (Entry<String, Set<GlowScore>> entry : scoreMap.entrySet()) {
        for (GlowScore score : entry.getValue()) {
            player.getSession().send(new ScoreboardScoreMessage(entry.getKey(), score.getObjective().getName(), score.getScore()));
        }
    }
    // teams
    for (GlowTeam team : teams.values()) {
        player.getSession().send(team.getCreateMessage());
    }
    // add to player set
    players.add(player);
}
Also used : HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ScoreboardScoreMessage(net.glowstone.net.message.play.scoreboard.ScoreboardScoreMessage) DisplaySlot(org.bukkit.scoreboard.DisplaySlot) GlowDisplaySlot(net.glowstone.constants.GlowDisplaySlot) ScoreboardDisplayMessage(net.glowstone.net.message.play.scoreboard.ScoreboardDisplayMessage) TextMessage(net.glowstone.util.TextMessage)

Aggregations

ScoreboardScoreMessage (net.glowstone.net.message.play.scoreboard.ScoreboardScoreMessage)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GlowDisplaySlot (net.glowstone.constants.GlowDisplaySlot)1 ScoreboardDisplayMessage (net.glowstone.net.message.play.scoreboard.ScoreboardDisplayMessage)1 TextMessage (net.glowstone.util.TextMessage)1 DisplaySlot (org.bukkit.scoreboard.DisplaySlot)1