Skip to content

Commit

Permalink
Fix opRevealImpersonations gamerule creating wrong nametags
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jul 20, 2024
1 parent 3255653 commit 0e4c115
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
------------------------------------------------------
Version 3.0.1
------------------------------------------------------
- Fixed impersonator's names appearing as "Faked(Faked)" for operators when the `opRevealImpersonations` gamerule is off

------------------------------------------------------
Version 3.0.0
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jb_annotations_version = 23.0.0
apiguardian_version = 1.1.2

# Mod Properties
mod_version = 3.0.0
mod_version = 3.0.1
maven_group = org.ladysnake
archives_base_name = impersonate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jetbrains.annotations.Nullable;
import org.ladysnake.impersonate.Impersonator;

import java.util.Objects;
import java.util.Optional;

public class ImpersonateTextContent implements RecipientAwareTextContent {
Expand All @@ -52,8 +53,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.ladysnake.impersonate.impl.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
Expand All @@ -34,7 +35,6 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
Expand Down Expand Up @@ -78,12 +78,13 @@ public void impersonate_disableCape() {
dataTracker.set(PLAYER_MODEL_PARTS, newModelMask);
}

@Inject(method = "getName", at = @At("RETURN"), cancellable = true)
private void fakeName(CallbackInfoReturnable<Text> cir) {
@ModifyReturnValue(method = "getName", at = @At("RETURN"))
private Text fakeName(Text original) {
PlayerEntity self = ((PlayerEntity) (Object) this);
if (Impersonator.get(self).isImpersonating()) {
// if the client is aware that there is an impersonation, they should display it
cir.setReturnValue(MutableText.of(ImpersonateTextContent.get(self, getWorld().isClient)));
return MutableText.of(ImpersonateTextContent.get(self, getWorld().isClient));
}
return original;
}
}

0 comments on commit 0e4c115

Please sign in to comment.