Skip to content

Commit

Permalink
Fix scoreboard packet sending
Browse files Browse the repository at this point in the history
Fixes #3971
  • Loading branch information
aromaa committed May 20, 2024
1 parent 63200e2 commit e5aeac0
Showing 1 changed file with 10 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@
import org.spongepowered.api.scoreboard.criteria.Criterion;
import org.spongepowered.api.scoreboard.displayslot.DisplaySlot;
import org.spongepowered.api.scoreboard.objective.Objective;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.accessor.world.scores.PlayerTeamAccessor;
import org.spongepowered.common.accessor.world.scores.ScoreboardAccessor;
import org.spongepowered.common.adventure.SpongeAdventure;
import org.spongepowered.common.bridge.server.ServerScoreboardBridge;
import org.spongepowered.common.bridge.world.scores.ObjectiveBridge;
import org.spongepowered.common.scoreboard.SpongeObjective;
import org.spongepowered.common.scoreboard.SpongeScore;
import org.spongepowered.common.util.Constants;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -67,6 +66,9 @@
@Mixin(ServerScoreboard.class)
public abstract class ServerScoreboardMixin extends Scoreboard implements ServerScoreboardBridge {

// @formatter:off
@Shadow @Final private Set<net.minecraft.world.scores.Objective> trackedObjectives;
// @formatter:on

private final List<ServerPlayer> impl$players = new ArrayList<>();

Expand Down Expand Up @@ -191,7 +193,7 @@ public abstract class ServerScoreboardMixin extends Scoreboard implements Server
player.connection.send(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true));
}

for (final net.minecraft.world.scores.Objective objective : this.getObjectives()) {
for (final net.minecraft.world.scores.Objective objective : this.trackedObjectives) {
player.connection.send(new ClientboundSetObjectivePacket(objective, 0));
((ScoreboardAccessor) this).accessor$displayObjectives().forEach((displaySlot, objective1) -> {
if (objective1 == objective) {
Expand Down Expand Up @@ -231,11 +233,6 @@ private void onUpdateScoreValue(final PlayerList manager, final Packet<?> packet
this.bridge$sendToPlayers(packet);
}

@Redirect(method = "onScoreChanged", at = @At(value = "INVOKE", target = "Ljava/util/Set;contains(Ljava/lang/Object;)Z", remap = false))
private boolean onUpdateScoreValue(final Set<?> set, final Object object) {
return true;
}

@Redirect(method = "onPlayerRemoved",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastAll(Lnet/minecraft/network/protocol/Packet;)V"))
private void impl$updatePlayersOnRemoval(final PlayerList manager, final Packet<?> packet) {
Expand All @@ -248,14 +245,10 @@ private boolean onUpdateScoreValue(final Set<?> set, final Object object) {
this.bridge$sendToPlayers(packet);
}

//@Redirect(method = "setObjectiveInDisplaySlot", at = @At(value = "INVOKE", target = SEND_PACKET_METHOD))
/*public void onSetObjectiveInDisplaySlot(PlayerList manager, Packet<?> packet) {
this.sendToPlayers(packet);
}*/

@Inject(method = "onObjectiveAdded", at = @At("RETURN"))
private void impl$UpdatePlayersScoreObjective(final net.minecraft.world.scores.Objective objective, final CallbackInfo ci) {
this.bridge$sendToPlayers(new ClientboundSetObjectivePacket(objective, Constants.Scoreboards.OBJECTIVE_PACKET_ADD));
@Redirect(method = "setDisplayObjective",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastAll(Lnet/minecraft/network/protocol/Packet;)V"))
private void impl$updatePlayersOnSetDisplayObjective(final PlayerList manager, final Packet<?> packet) {
this.bridge$sendToPlayers(packet);
}

@Redirect(method = "addPlayerToTeam",
Expand All @@ -276,18 +269,6 @@ private boolean onUpdateScoreValue(final Set<?> set, final Object object) {
this.bridge$sendToPlayers(packet);
}

@Redirect(method = "onObjectiveChanged",
at = @At(value = "INVOKE", target = "Ljava/util/Set;contains(Ljava/lang/Object;)Z", remap = false))
private boolean impl$alwaysReturnTrueForObjectivesDisplayName(final Set<net.minecraft.world.scores.Objective> set, final Object object) {
return true;
}

@Redirect(method = "onObjectiveRemoved",
at = @At(value = "INVOKE", target = "Ljava/util/Set;contains(Ljava/lang/Object;)Z", remap = false))
private boolean impl$alwaysReturnTrueForObjectiveRemoval(final Set<net.minecraft.world.scores.Objective> set, final Object object) {
return true;
}

@Redirect(method = "onTeamAdded",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastAll(Lnet/minecraft/network/protocol/Packet;)V"))
private void impl$updateAllPlayersOnTeamCreation(final PlayerList manager, final Packet<?> packet) {
Expand Down

0 comments on commit e5aeac0

Please sign in to comment.