Skip to content

Commit

Permalink
Add re-sync on opRevealImpersonations update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jul 20, 2024
1 parent 0e4c115 commit eb8d626
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
------------------------------------------------------
Version 3.0.1
------------------------------------------------------
- Fixed impersonator's names appearing as "Faked(Faked)" for operators when the `opRevealImpersonations` gamerule is off
- Fixed impersonator's names appearing as "Faked(Faked)" for operators when the `impersonate:opRevealImpersonations` gamerule is off
- Toggling the `impersonate:opRevealImpersonations` gamerule now properly updates usernames without needing a re-log

------------------------------------------------------
Version 3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,28 @@
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.GameRules;
import org.ladysnake.impersonate.Impersonator;

public final class ImpersonateGamerules {
public static final GameRules.Key<GameRules.BooleanRule> FAKE_CAPES =
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();
}
}
}));

public static final GameRules.Key<GameRules.BooleanRule> 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<GameRules.BooleanRule> LOG_REVEAL_IMPERSONATIONS =
register("logRevealImpersonations", GameRuleFactory.createBooleanRule(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import org.ladysnake.impersonate.Impersonate;
import org.ladysnake.impersonate.Impersonator;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -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
Expand Down

0 comments on commit eb8d626

Please sign in to comment.