Search in sources :

Example 1 with ScoreboardObjective

use of net.minecraft.server.v1_12_R1.ScoreboardObjective in project PaperDev by Kamillaova.

the class CraftObjective method getDisplaySlot.

public DisplaySlot getDisplaySlot() throws IllegalStateException {
    CraftScoreboard scoreboard = checkState();
    Scoreboard board = scoreboard.board;
    ScoreboardObjective objective = this.objective;
    for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) {
        if (board.getObjectiveForSlot(i) == objective) {
            return CraftScoreboardTranslations.toBukkitSlot(i);
        }
    }
    return null;
}
Also used : Scoreboard(net.minecraft.server.v1_12_R1.Scoreboard) ScoreboardObjective(net.minecraft.server.v1_12_R1.ScoreboardObjective)

Example 2 with ScoreboardObjective

use of net.minecraft.server.v1_12_R1.ScoreboardObjective in project PaperDev by Kamillaova.

the class CraftObjective method setDisplaySlot.

public void setDisplaySlot(DisplaySlot slot) throws IllegalStateException {
    CraftScoreboard scoreboard = checkState();
    Scoreboard board = scoreboard.board;
    ScoreboardObjective objective = this.objective;
    for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) {
        if (board.getObjectiveForSlot(i) == objective) {
            board.setDisplaySlot(i, null);
        }
    }
    if (slot != null) {
        int slotNumber = CraftScoreboardTranslations.fromBukkitSlot(slot);
        board.setDisplaySlot(slotNumber, getHandle());
    }
}
Also used : Scoreboard(net.minecraft.server.v1_12_R1.Scoreboard) ScoreboardObjective(net.minecraft.server.v1_12_R1.ScoreboardObjective)

Example 3 with ScoreboardObjective

use of net.minecraft.server.v1_12_R1.ScoreboardObjective in project PaperDev by Kamillaova.

the class CraftScore method getScore.

public int getScore() throws IllegalStateException {
    Scoreboard board = objective.checkState().board;
    if (board.getPlayers().contains(entry)) {
        // Lazy
        Map<ScoreboardObjective, ScoreboardScore> scores = board.getPlayerObjectives(entry);
        ScoreboardScore score = scores.get(objective.getHandle());
        if (score != null) {
            // Lazy
            return score.getScore();
        }
    }
    // Lazy
    return 0;
}
Also used : Scoreboard(net.minecraft.server.v1_12_R1.Scoreboard) ScoreboardObjective(net.minecraft.server.v1_12_R1.ScoreboardObjective) ScoreboardScore(net.minecraft.server.v1_12_R1.ScoreboardScore)

Example 4 with ScoreboardObjective

use of net.minecraft.server.v1_12_R1.ScoreboardObjective in project PaperDev by Kamillaova.

the class CraftScoreboard method getScores.

public ImmutableSet<Score> getScores(String entry) throws IllegalArgumentException {
    Validate.notNull(entry, "Entry cannot be null");
    ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
    for (ScoreboardObjective objective : (Collection<ScoreboardObjective>) this.board.getObjectives()) {
        scores.add(new CraftScore(new CraftObjective(this, objective), entry));
    }
    return scores.build();
}
Also used : Score(org.bukkit.scoreboard.Score) ImmutableSet(com.google.common.collect.ImmutableSet) ScoreboardObjective(net.minecraft.server.v1_12_R1.ScoreboardObjective) Collection(java.util.Collection)

Example 5 with ScoreboardObjective

use of net.minecraft.server.v1_12_R1.ScoreboardObjective in project PaperDev by Kamillaova.

the class CraftScoreboardManager method setPlayerBoard.

// CraftBukkit method
public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard bukkitScoreboard) throws IllegalArgumentException {
    Validate.isTrue(bukkitScoreboard instanceof CraftScoreboard, "Cannot set player scoreboard to an unregistered Scoreboard");
    CraftScoreboard scoreboard = (CraftScoreboard) bukkitScoreboard;
    net.minecraft.server.v1_12_R1.Scoreboard oldboard = getPlayerBoard(player).getHandle();
    net.minecraft.server.v1_12_R1.Scoreboard newboard = scoreboard.getHandle();
    EntityPlayer entityplayer = player.getHandle();
    if (oldboard == newboard) {
        return;
    }
    if (scoreboard == mainScoreboard) {
        playerBoards.remove(player);
    } else {
        playerBoards.put(player, (CraftScoreboard) scoreboard);
    }
    // Old objective tracking
    HashSet<ScoreboardObjective> removed = new HashSet<ScoreboardObjective>();
    for (int i = 0; i < 3; ++i) {
        ScoreboardObjective scoreboardobjective = oldboard.getObjectiveForSlot(i);
        if (scoreboardobjective != null && !removed.contains(scoreboardobjective)) {
            entityplayer.playerConnection.sendPacket(new PacketPlayOutScoreboardObjective(scoreboardobjective, 1));
            removed.add(scoreboardobjective);
        }
    }
    // Old team tracking
    Iterator<?> iterator = oldboard.getTeams().iterator();
    while (iterator.hasNext()) {
        ScoreboardTeam scoreboardteam = (ScoreboardTeam) iterator.next();
        entityplayer.playerConnection.sendPacket(new PacketPlayOutScoreboardTeam(scoreboardteam, 1));
    }
    // The above is the reverse of the below method.
    server.getPlayerList().sendScoreboard((ScoreboardServer) newboard, player.getHandle());
}
Also used : ScoreboardObjective(net.minecraft.server.v1_12_R1.ScoreboardObjective) PacketPlayOutScoreboardObjective(net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardObjective) Scoreboard(net.minecraft.server.v1_12_R1.Scoreboard) PacketPlayOutScoreboardTeam(net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam) PacketPlayOutScoreboardObjective(net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardObjective) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) HashSet(java.util.HashSet) ScoreboardTeam(net.minecraft.server.v1_12_R1.ScoreboardTeam) PacketPlayOutScoreboardTeam(net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam)

Aggregations

ScoreboardObjective (net.minecraft.server.v1_12_R1.ScoreboardObjective)9 Scoreboard (net.minecraft.server.v1_12_R1.Scoreboard)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)1 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)1 PacketPlayOutScoreboardObjective (net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardObjective)1 PacketPlayOutScoreboardTeam (net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam)1 ScoreboardScore (net.minecraft.server.v1_12_R1.ScoreboardScore)1 ScoreboardTeam (net.minecraft.server.v1_12_R1.ScoreboardTeam)1 Objective (org.bukkit.scoreboard.Objective)1 Score (org.bukkit.scoreboard.Score)1