Search in sources :

Example 1 with ClientboundSetDisplayObjectivePacket

use of net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket in project Denizen-For-Bukkit by DenizenScript.

the class SidebarImpl method sendUpdate.

@Override
public void sendUpdate() {
    List<PlayerTeam> oldTeams = generatedTeams;
    generatedTeams = new ArrayList<>();
    PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj1, 0));
    for (int i = 0; i < this.lines.length; i++) {
        String line = this.lines[i];
        if (line == null) {
            break;
        }
        String lineId = Utilities.generateRandomColors(8);
        PlayerTeam team = new PlayerTeam(dummyScoreboard, lineId);
        team.getPlayers().add(lineId);
        team.setPlayerPrefix(Handler.componentToNMS(FormattedTextHelper.parse(line, ChatColor.WHITE)));
        generatedTeams.add(team);
        PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true));
        PacketHelperImpl.send(player, new ClientboundSetScorePacket(ServerScoreboard.Method.CHANGE, obj1.getName(), lineId, this.scores[i]));
    }
    PacketHelperImpl.send(player, new ClientboundSetDisplayObjectivePacket(1, this.obj1));
    PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1));
    Objective temp = this.obj2;
    this.obj2 = this.obj1;
    this.obj1 = temp;
    for (PlayerTeam team : oldTeams) {
        PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team));
    }
}
Also used : ClientboundSetScorePacket(net.minecraft.network.protocol.game.ClientboundSetScorePacket) Objective(net.minecraft.world.scores.Objective) PlayerTeam(net.minecraft.world.scores.PlayerTeam) ClientboundSetDisplayObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket) ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)

Example 2 with ClientboundSetDisplayObjectivePacket

use of net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method bridge$updateDisplaySlot.

@Override
public void bridge$updateDisplaySlot(@Nullable final Objective objective, final int slot) throws IllegalStateException {
    if (objective != null && !objective.scoreboards().contains(this)) {
        throw new IllegalStateException("Attempting to set an objective's display slot that does not exist on this scoreboard!");
    }
    ((ScoreboardAccessor) this).accessor$displayObjectives()[slot] = objective == null ? null : ((SpongeObjective) objective).getObjectiveFor(this);
    ((ServerScoreboardBridge) this).bridge$sendToPlayers(new ClientboundSetDisplayObjectivePacket(slot, ((ScoreboardAccessor) this).accessor$displayObjectives()[slot]));
}
Also used : ClientboundSetDisplayObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket) ScoreboardAccessor(org.spongepowered.common.accessor.world.scores.ScoreboardAccessor) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge)

Example 3 with ClientboundSetDisplayObjectivePacket

use of net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method bridge$addPlayer.

@Override
public void bridge$addPlayer(final ServerPlayer player, final boolean sendPackets) {
    this.impl$players.add(player);
    if (sendPackets) {
        for (final PlayerTeam team : this.getPlayerTeams()) {
            player.connection.send(new ClientboundSetPlayerTeamPacket(team, 0));
        }
        for (final net.minecraft.world.scores.Objective objective : this.getObjectives()) {
            player.connection.send(new ClientboundSetObjectivePacket(objective, 0));
            for (int i = 0; i < 19; ++i) {
                if (this.getDisplayObjective(i) == objective) {
                    player.connection.send(new ClientboundSetDisplayObjectivePacket(i, objective));
                }
            }
            for (final Score score : this.getPlayerScores(objective)) {
                final ClientboundSetScorePacket packetIn = new ClientboundSetScorePacket(Method.CHANGE, score.getObjective().getName(), score.getOwner(), score.getScore());
                player.connection.send(packetIn);
            }
        }
    }
}
Also used : ClientboundSetScorePacket(net.minecraft.network.protocol.game.ClientboundSetScorePacket) Score(net.minecraft.world.scores.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) PlayerTeam(net.minecraft.world.scores.PlayerTeam) ClientboundSetPlayerTeamPacket(net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket) ClientboundSetDisplayObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket) ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)

Example 4 with ClientboundSetDisplayObjectivePacket

use of net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket in project Denizen-For-Bukkit by DenizenScript.

the class SidebarImpl method sendUpdate.

@Override
public void sendUpdate() {
    List<PlayerTeam> oldTeams = generatedTeams;
    generatedTeams = new ArrayList<>();
    PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj1, 0));
    for (int i = 0; i < this.lines.length; i++) {
        String line = this.lines[i];
        if (line == null) {
            break;
        }
        String lineId = Utilities.generateRandomColors(8);
        PlayerTeam team = new PlayerTeam(dummyScoreboard, lineId);
        team.getPlayers().add(lineId);
        team.setPlayerPrefix(Handler.componentToNMS(FormattedTextHelper.parse(line, ChatColor.WHITE)));
        generatedTeams.add(team);
        PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true));
        PacketHelperImpl.send(player, new ClientboundSetScorePacket(ServerScoreboard.Method.CHANGE, obj1.getName(), lineId, this.scores[i]));
    }
    PacketHelperImpl.send(player, new ClientboundSetDisplayObjectivePacket(1, this.obj1));
    PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1));
    Objective temp = this.obj2;
    this.obj2 = this.obj1;
    this.obj1 = temp;
    for (PlayerTeam team : oldTeams) {
        PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team));
    }
}
Also used : ClientboundSetScorePacket(net.minecraft.network.protocol.game.ClientboundSetScorePacket) Objective(net.minecraft.world.scores.Objective) PlayerTeam(net.minecraft.world.scores.PlayerTeam) ClientboundSetDisplayObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket) ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)

Aggregations

ClientboundSetDisplayObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket)4 ClientboundSetObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)3 ClientboundSetScorePacket (net.minecraft.network.protocol.game.ClientboundSetScorePacket)3 PlayerTeam (net.minecraft.world.scores.PlayerTeam)3 Objective (net.minecraft.world.scores.Objective)2 ClientboundSetPlayerTeamPacket (net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket)1 Score (net.minecraft.world.scores.Score)1 ScoreboardAccessor (org.spongepowered.common.accessor.world.scores.ScoreboardAccessor)1 ServerScoreboardBridge (org.spongepowered.common.bridge.server.ServerScoreboardBridge)1 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)1 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)1