Skip to content

Commit

Permalink
Properly implement fakeCapes gamerule, fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Sep 14, 2021
1 parent 8fb702f commit 474b0b2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
------------------------------------------------------
Version 2.3.4
------------------------------------------------------
- Fixed no one getting a cape unless impersonators got capes too

------------------------------------------------------
Version 2.3.3
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jb_annotations_version = 19.0.0
apiguardian_version = 1.0.0

# Mod Properties
mod_version = 2.3.3
mod_version = 2.3.4
maven_group = io.github.ladysnake
archives_base_name = impersonate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,25 @@ private void setImpersonatedProfile(@Nullable GameProfile profile) {
updatePlayerLists(PlayerListS2CPacket.Action.REMOVE_PLAYER);
this.impersonatedProfile = profile;
this.editedProfile = profile == null ? null : new GameProfile(this.getActualProfile().getId(), this.impersonatedProfile.getName());
if (this.player instanceof ServerPlayerEntity) {
ServerPlayerSkins.setSkin(((ServerPlayerEntity) player), profile == null ? this.getActualProfile() : profile);
if (this.player instanceof ServerPlayerEntity serverPlayer) {
this.applyCapeGamerule(serverPlayer, profile);
ServerPlayerSkins.setSkin(serverPlayer, profile == null ? this.getActualProfile() : profile);
}
updatePlayerLists(PlayerListS2CPacket.Action.ADD_PLAYER);
Impersonate.IMPERSONATION.sync(this.player);
}
}

private void applyCapeGamerule(ServerPlayerEntity player, GameProfile impersonatedProfile) {
if (!player.getServerWorld().getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
if (impersonatedProfile == null) {
((PlayerEntityExtensions) player).impersonate_resetCape();
} else {
((PlayerEntityExtensions) player).impersonate_disableCape();
}
}
}

private void updatePlayerLists(PlayerListS2CPacket.Action action) {
if (!player.world.isClient) {
PlayerManager playerManager = ((ServerPlayerEntity) player).server.getPlayerManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.github.ladysnake.impersonate.impl.mixin;

import com.mojang.authlib.GameProfile;
import io.github.ladysnake.impersonate.Impersonator;
import io.github.ladysnake.impersonate.impl.ImpersonateGamerules;
import io.github.ladysnake.impersonate.impl.PlayerEntityExtensions;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -39,7 +40,7 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile

@Inject(method = "setClientSettings", at = @At("RETURN"))
private void removeCapeIfDisallowed(ClientSettingsC2SPacket clientSettingsC2SPacket, CallbackInfo ci) {
if (!this.world.getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
if (Impersonator.get(this).isImpersonating() && !this.world.getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
this.impersonate_disableCape();
}
}
Expand Down

0 comments on commit 474b0b2

Please sign in to comment.