Search in sources :

Example 1 with ServerScoreboardBridge

use of org.spongepowered.common.bridge.server.ServerScoreboardBridge 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 2 with ServerScoreboardBridge

use of org.spongepowered.common.bridge.server.ServerScoreboardBridge 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)

Aggregations

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