diff --git a/changelog.md b/changelog.md index 7247e75..6e10d21 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +------------------------------------------------------ +Version 2.10.3 +------------------------------------------------------ +- Fixed impersonator's names appearing as "Faked(Faked)" for operators when the `opRevealImpersonations` gamerule is off +- Toggling the `impersonate:opRevealImpersonations` gamerule now properly updates usernames without needing a re-log + ------------------------------------------------------ Version 2.10.2 ------------------------------------------------------ diff --git a/gradle.properties b/gradle.properties index 0ec2f4d..fcf9b17 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ jb_annotations_version = 23.0.0 apiguardian_version = 1.1.2 # Mod Properties -mod_version = 2.10.2 +mod_version = 2.10.3 maven_group = org.ladysnake archives_base_name = impersonate diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateGamerules.java b/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateGamerules.java index b19f723..fb5a498 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateGamerules.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateGamerules.java @@ -17,6 +17,7 @@ */ package io.github.ladysnake.impersonate.impl; +import io.github.ladysnake.impersonate.Impersonator; import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; import net.minecraft.server.network.ServerPlayerEntity; @@ -27,7 +28,7 @@ public final class ImpersonateGamerules { register("fakeCapes", GameRuleFactory.createBooleanRule(false, (server, rule) -> { for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { if (rule.get()) { - ((PlayerEntityExtensions)player).impersonate_resetCape(); + ((PlayerEntityExtensions) player).impersonate_resetCape(); } else { ((PlayerEntityExtensions) player).impersonate_disableCape(); } @@ -35,7 +36,13 @@ public final class ImpersonateGamerules { })); public static final GameRules.Key OP_REVEAL_IMPERSONATIONS = - register("opRevealImpersonations", GameRuleFactory.createBooleanRule(true)); + register("opRevealImpersonations", GameRuleFactory.createBooleanRule(true, (server, rule) -> { + for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { + if (Impersonator.get(player) instanceof PlayerImpersonator playerImpersonator) { + playerImpersonator.syncChanges(playerImpersonator.getImpersonatedProfile()); + } + } + })); public static final GameRules.Key LOG_REVEAL_IMPERSONATIONS = register("logRevealImpersonations", GameRuleFactory.createBooleanRule(true)); diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java b/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java index 908e4bb..89e5ab7 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java @@ -25,6 +25,7 @@ import net.minecraft.text.Style; import net.minecraft.text.TextContent; +import java.util.Objects; import java.util.Optional; public class ImpersonateTextContent implements RecipientAwareTextContent { @@ -39,8 +40,9 @@ public static TextContent get(PlayerEntity player) { public static TextContent get(PlayerEntity player, boolean reveal) { Impersonator impersonator = Impersonator.get(player); String fakeName = impersonator.getEditedProfile().getName(); - String trueText = String.format("%s(%s)", fakeName, player.getGameProfile().getName()); - return new ImpersonateTextContent(trueText, fakeName, reveal); + String trueName = player.getGameProfile().getName(); + String trueText = String.format("%s(%s)", fakeName, trueName); + return new ImpersonateTextContent(trueText, fakeName, reveal && !Objects.equals(fakeName, trueName)); } private ImpersonateTextContent(String trueText, String fakedText, boolean revealed) { diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/PacketMeddling.java b/src/main/java/io/github/ladysnake/impersonate/impl/PacketMeddling.java index 23dccf4..08e126a 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/PacketMeddling.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/PacketMeddling.java @@ -42,7 +42,7 @@ public static void resolvePlayerListEntries(PlayerListS2CPacket packet, ServerPl for (PlayerListS2CPacket.Entry entry : packet.getEntries()) { PlayerEntity playerEntry = player.server.getPlayerManager().getPlayer(entry.profileId()); if (playerEntry != null) { - Impersonator impersonator = Impersonate.IMPERSONATION.get(playerEntry); + Impersonator impersonator = Impersonator.get(playerEntry); if (impersonator.isImpersonating()) { // OPs get the true profile with semi-fake display name, others get a complete lie PlayerListS2CPacketEntryAccessor accessibleEntry = (PlayerListS2CPacketEntryAccessor) (Object) entry; diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/PlayerImpersonator.java b/src/main/java/io/github/ladysnake/impersonate/impl/PlayerImpersonator.java index 226f2e1..22ef9fa 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/PlayerImpersonator.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/PlayerImpersonator.java @@ -104,17 +104,17 @@ private void setImpersonatedProfile(@Nullable GameProfile profile) { this.impersonatedProfile = profile; this.editedProfile = profile == null ? null : new GameProfile(this.getActualProfile().getId(), this.impersonatedProfile.getName()); this.syncChanges(profile); - Impersonate.IMPERSONATION.sync(this.player); } } - private void syncChanges(@Nullable GameProfile profile) { + public void syncChanges(@Nullable GameProfile profile) { if (this.player instanceof ServerPlayerEntity serverPlayer && serverPlayer.networkHandler != null) { updatePlayerLists(new PlayerRemoveS2CPacket(List.of(this.player.getUuid()))); this.applyCapeGamerule(serverPlayer, profile); ServerPlayerSkins.setSkin(serverPlayer, profile == null ? this.getActualProfile() : profile); updatePlayerLists(PlayerListS2CPacket.entryFromPlayer(List.of(serverPlayer))); } + Impersonate.IMPERSONATION.sync(this.player); } private void applyCapeGamerule(ServerPlayerEntity player, GameProfile impersonatedProfile) { diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ListCommandMixin.java b/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ListCommandMixin.java index a25fb1a..4659415 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ListCommandMixin.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ListCommandMixin.java @@ -19,6 +19,7 @@ import com.mojang.authlib.GameProfile; import io.github.ladysnake.impersonate.Impersonate; +import io.github.ladysnake.impersonate.Impersonator; import net.minecraft.server.command.ListCommand; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; @@ -42,7 +43,7 @@ private static void fakeNameAndUuid(ServerPlayerEntity player, CallbackInfoRetur Object[] args = cnt.getArgs(); // Defend against other mods changing the text if (args.length == 2 && args[0] instanceof Text && args[1] instanceof UUID) { - GameProfile impersonatedProfile = Impersonate.IMPERSONATION.get(player).getImpersonatedProfile(); + GameProfile impersonatedProfile = Impersonator.get(player).getImpersonatedProfile(); if (impersonatedProfile != null) { // Name is already covered by PlayerEntity#getName mixin