Search in sources :

Example 1 with ScoreboardDisplayMessage

use of net.glowstone.net.message.play.scoreboard.ScoreboardDisplayMessage 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)

Example 2 with ScoreboardDisplayMessage

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

the class GlowScoreboard method setDisplaySlot.

/**
 * Set the objective displayed in the given slot.
 *
 * @param slot The display slot.
 * @param objective The objective to display there, possibly null.
 */
void setDisplaySlot(DisplaySlot slot, GlowObjective objective) {
    GlowObjective previous = displaySlots.put(slot, objective);
    // previous objective is no longer in this display slot
    if (previous != null) {
        previous.displaySlot = null;
    }
    // new objective is now in this display slot
    if (objective != null) {
        // update objective's display slot
        broadcast(new ScoreboardDisplayMessage(GlowDisplaySlot.getId(slot), objective.getName()));
        objective.displaySlot = slot;
    } else {
        // no objective
        broadcast(new ScoreboardDisplayMessage(GlowDisplaySlot.getId(slot), ""));
    }
}
Also used : ScoreboardDisplayMessage(net.glowstone.net.message.play.scoreboard.ScoreboardDisplayMessage)

Aggregations

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