Search in sources :

Example 1 with ClientboundSetObjectivePacket

use of net.minecraft.network.protocol.game.ClientboundSetObjectivePacket 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 ClientboundSetObjectivePacket

use of net.minecraft.network.protocol.game.ClientboundSetObjectivePacket 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 3 with ClientboundSetObjectivePacket

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

the class ServerScoreboardMixin method bridge$removeObjective.

@Override
public void bridge$removeObjective(final Objective objective) {
    final net.minecraft.world.scores.Objective scoreObjective = ((SpongeObjective) objective).getObjectiveFor(this);
    ((ScoreboardAccessor) this).accessor$objectivesByName().remove(scoreObjective.getName());
    for (int i = 0; i < 19; ++i) {
        if (this.getDisplayObjective(i) == scoreObjective) {
            this.setDisplayObjective(i, null);
        }
    }
    ((ServerScoreboardBridge) this).bridge$sendToPlayers(new ClientboundSetObjectivePacket(scoreObjective, Constants.Scoreboards.OBJECTIVE_PACKET_REMOVE));
    final List list = ((ScoreboardAccessor) this).accessor$objectivesByCriteria().get(scoreObjective.getCriteria());
    if (list != null) {
        list.remove(scoreObjective);
    }
    for (final Map<net.minecraft.world.scores.Objective, Score> scoreMap : ((ScoreboardAccessor) this).accessor$playerScores().values()) {
        final Score score = scoreMap.remove(scoreObjective);
        if (score != null) {
            ((ScoreBridge) score).bridge$getSpongeScore().removeScoreFor(scoreObjective);
        }
    }
    this.shadow$setDirty();
    ((SpongeObjective) objective).removeObjectiveFor(this);
}
Also used : ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Objective(org.spongepowered.api.scoreboard.objective.Objective) SpongeObjective(org.spongepowered.common.scoreboard.SpongeObjective) Score(net.minecraft.world.scores.Score) SpongeScore(org.spongepowered.common.scoreboard.SpongeScore) PlayerList(net.minecraft.server.players.PlayerList) ArrayList(java.util.ArrayList) List(java.util.List) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge)

Example 4 with ClientboundSetObjectivePacket

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

the class SidebarImpl method remove.

@Override
public void remove() {
    for (PlayerTeam team : generatedTeams) {
        PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team));
    }
    generatedTeams.clear();
    PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1));
}
Also used : PlayerTeam(net.minecraft.world.scores.PlayerTeam) ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)

Example 5 with ClientboundSetObjectivePacket

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

the class SidebarImpl method remove.

@Override
public void remove() {
    for (PlayerTeam team : generatedTeams) {
        PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team));
    }
    generatedTeams.clear();
    PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1));
}
Also used : PlayerTeam(net.minecraft.world.scores.PlayerTeam) ClientboundSetObjectivePacket(net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)

Aggregations

ClientboundSetObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)6 PlayerTeam (net.minecraft.world.scores.PlayerTeam)5 ClientboundSetDisplayObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket)3 ClientboundSetScorePacket (net.minecraft.network.protocol.game.ClientboundSetScorePacket)3 Objective (net.minecraft.world.scores.Objective)2 Score (net.minecraft.world.scores.Score)2 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientboundSetPlayerTeamPacket (net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket)1 PlayerList (net.minecraft.server.players.PlayerList)1 Objective (org.spongepowered.api.scoreboard.objective.Objective)1 ServerScoreboardBridge (org.spongepowered.common.bridge.server.ServerScoreboardBridge)1 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)1