diff --git a/common b/common index 2cfd93c..9e3bf14 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 2cfd93c19753e1420043fa17336f2d09afaeee46 +Subproject commit 9e3bf14ffaead5e388993d9c925acf6a6a00a6e2 diff --git a/versions/1.21.10/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.10/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 2614241..4dd9311 100644 --- a/versions/1.21.10/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.10/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.name(); UUID uuid = profile.id(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.11/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.11/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 2614241..4dd9311 100644 --- a/versions/1.21.11/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.11/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.name(); UUID uuid = profile.id(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.4/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.4/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 41b6bdb..2a68cd6 100644 --- a/versions/1.21.4/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.4/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.getName(); UUID uuid = profile.getId(); - if (SaturnPlayer.get(name, uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.5/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.5/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 5dd00f6..2a68cd6 100644 --- a/versions/1.21.5/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.5/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.getName(); UUID uuid = profile.getId(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.6/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.6/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 5dd00f6..2a68cd6 100644 --- a/versions/1.21.6/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.6/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.getName(); UUID uuid = profile.getId(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.7/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.7/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 5dd00f6..2a68cd6 100644 --- a/versions/1.21.7/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.7/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.getName(); UUID uuid = profile.getId(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.8/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.8/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 5dd00f6..2a68cd6 100644 --- a/versions/1.21.8/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.8/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.getName(); UUID uuid = profile.getId(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } } diff --git a/versions/1.21.9/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java b/versions/1.21.9/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java index 2614241..4dd9311 100644 --- a/versions/1.21.9/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java +++ b/versions/1.21.9/src/main/java/org/saturnclient/saturnclient/mixin/TabListMixin.java @@ -1,43 +1,49 @@ package org.saturnclient.saturnclient.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import java.util.UUID; -import org.jetbrains.annotations.Nullable; import org.saturnclient.client.player.Roles; import org.saturnclient.client.player.SaturnPlayer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -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.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; @Mixin(PlayerListEntry.class) public abstract class TabListMixin { - @Shadow - private GameProfile profile; - /** - * @author HexLeo - * @reason Adds the Saturn Client icon to the player's name if they are online - * with Saturn Client + * Adds the Saturn Client icon to the player's name if they are online with + * Saturn Client, keeping any name, rank prefix or team formatting the server + * set. */ - @Overwrite - @Nullable - public Text getDisplayName() { - GameProfile profile = ((PlayerListEntry) (Object) this).getProfile(); + @Inject(method = "getDisplayName", at = @At("RETURN"), cancellable = true) + private void saturn$addSaturnIcon(CallbackInfoReturnable cir) { + PlayerListEntry entry = (PlayerListEntry) (Object) this; + GameProfile profile = entry.getProfile(); String name = profile.name(); UUID uuid = profile.id(); - if (SaturnPlayer.get(uuid) != null) { - return Text.literal(Roles.getSaturnIndicator()) - .styled(style -> style.withColor(Roles.getIconColor(uuid))) - .append(Text.literal(name).styled(style -> style.withColor(Formatting.WHITE))); + if (SaturnPlayer.get(name, uuid) == null) { + return; } - return Text.literal(name); + + Text displayName = cir.getReturnValue(); + + // With no server-set name, vanilla shows the team-decorated profile name. + if (displayName == null) { + displayName = Team.decorateName(entry.getScoreboardTeam(), Text.literal(name)); + } + + cir.setReturnValue(Text.empty() + .append(Text.literal(Roles.getSaturnIndicator()) + .styled(style -> style.withColor(Roles.getIconColor(uuid)))) + .append(displayName)); } }