Search in sources :

Example 1 with PlayerTeam

use of net.minecraft.world.scores.PlayerTeam in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method removeNoCollideTeam.

@Override
public void removeNoCollideTeam(Player player, UUID noCollide) {
    if (noCollide == null || !player.isOnline()) {
        noCollideTeamMap.remove(player.getUniqueId());
        return;
    }
    HashMap<UUID, PlayerTeam> map = noCollideTeamMap.get(player.getUniqueId());
    if (map == null) {
        return;
    }
    PlayerTeam team = map.remove(noCollide);
    if (team != null) {
        send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team));
    }
    if (map.isEmpty()) {
        noCollideTeamMap.remove(player.getUniqueId());
    }
}
Also used : PlayerTeam(net.minecraft.world.scores.PlayerTeam)

Example 2 with PlayerTeam

use of net.minecraft.world.scores.PlayerTeam 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 3 with PlayerTeam

use of net.minecraft.world.scores.PlayerTeam in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method generateNoCollideTeam.

@Override
public void generateNoCollideTeam(Player player, UUID noCollide) {
    removeNoCollideTeam(player, noCollide);
    PlayerTeam team = new PlayerTeam(SidebarImpl.dummyScoreboard, Utilities.generateRandomColors(8));
    team.getPlayers().add(noCollide.toString());
    team.setCollisionRule(Team.CollisionRule.NEVER);
    HashMap<UUID, PlayerTeam> map = noCollideTeamMap.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>());
    map.put(noCollide, team);
    send(player, ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true));
}
Also used : PlayerTeam(net.minecraft.world.scores.PlayerTeam)

Example 4 with PlayerTeam

use of net.minecraft.world.scores.PlayerTeam in project SpongeCommon by SpongePowered.

the class ServerScoreboardMixin method bridge$registerTeam.

// Add team
@Override
public void bridge$registerTeam(final Team spongeTeam) {
    final PlayerTeam team = (PlayerTeam) spongeTeam;
    if (this.getPlayerTeam(spongeTeam.name()) != null) {
        throw new IllegalArgumentException(String.format("A team with the name '%s' already exists!", spongeTeam.name()));
    }
    if (((PlayerTeamAccessor) team).accessor$scoreboard() != null) {
        throw new IllegalArgumentException("The passed in team is already registered to a scoreboard!");
    }
    ((PlayerTeamAccessor) team).accessor$scoreboard(this);
    ((ScoreboardAccessor) this).accessor$teamsByName().put(team.getName(), team);
    for (final String entry : team.getPlayers()) {
        this.addPlayerToTeam(entry, team);
    }
    this.onTeamAdded(team);
}
Also used : PlayerTeam(net.minecraft.world.scores.PlayerTeam) PlayerTeamAccessor(org.spongepowered.common.accessor.world.scores.PlayerTeamAccessor)

Example 5 with PlayerTeam

use of net.minecraft.world.scores.PlayerTeam 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)

Aggregations

PlayerTeam (net.minecraft.world.scores.PlayerTeam)11 ClientboundSetObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetObjectivePacket)5 ClientboundSetDisplayObjectivePacket (net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket)3 ClientboundSetScorePacket (net.minecraft.network.protocol.game.ClientboundSetScorePacket)3 Objective (net.minecraft.world.scores.Objective)2 Component (net.kyori.adventure.text.Component)1 ClientboundSetPlayerTeamPacket (net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket)1 Score (net.minecraft.world.scores.Score)1 Team (org.spongepowered.api.scoreboard.Team)1 PlayerTeamAccessor (org.spongepowered.common.accessor.world.scores.PlayerTeamAccessor)1 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)1