Skip to content

Commit

Permalink
Update to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jul 4, 2022
1 parent a3b3255 commit 076bb8b
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 79 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import net.fabricmc.loom.task.RemapJarTask

plugins {
id 'io.github.ladysnake.chenille' version '0.7.0'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'io.github.ladysnake.chenille' version '0.9.0'
id 'io.github.juuxel.loom-quiltflower' version "1.6.0"
}

Expand Down Expand Up @@ -38,8 +39,8 @@ dependencies {
modIncludeApi libs.cca.base
modIncludeImplementation libs.cca.entity
modCompileOnly compatLibs.illuminations
// modRuntimeOnly compatLibs.illuminations
modTestImplementation libs.elmendorf
modRuntimeOnly compatLibs.illuminations
modLocalImplementation libs.elmendorf

api "org.jetbrains:annotations:${jb_annotations_version}"
api "org.apiguardian:apiguardian-api:${apiguardian_version}"
Expand Down Expand Up @@ -98,7 +99,7 @@ assemble.dependsOn(remapStandaloneJar)

chenille {
configurePublishing {
mainArtifact = remapStandaloneJar
mainArtifact = remapStandaloneJar.archiveFile
withArtifactory()
withCurseforgeRelease()
withGithubRelease()
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
------------------------------------------------------
Version 2.6.0
------------------------------------------------------
Updated to MC 1.19

------------------------------------------------------
Version 2.5.0
------------------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.2
loader_version=0.13.3
fabric_version=0.50.0+1.18.2
minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.8
fabric_version=0.57.0+1.19

# Other Dependencies
jb_annotations_version = 23.0.0
apiguardian_version = 1.1.2

# Mod Properties
mod_version = 2.5.0
mod_version = 2.6.0
maven_group = io.github.ladysnake
archives_base_name = impersonate

Expand All @@ -24,8 +24,7 @@ license_header = LGPL
gpl_version = 3
modrinth_id = xBZuWXoj
curseforge_id = 360333
curseforge_versions = 1.18.2
curseforge_versions = 1.19
cf_requirements = fabric-api
cf_embeddeds = cardinal-components
release_type = release
changelog_url = https://github.com/Ladysnake/Impersonate/blob/1.17/changelog.md
2 changes: 1 addition & 1 deletion gradle/compat-libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
illuminations = "3401926"
illuminations = "3846131"

[libraries]
illuminations = { module = "curse.maven:illuminations-292908", version.ref = "illuminations" }
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
cca = "4.1.4"
cca = "5.0.1"
fpa = "0.1-SNAPSHOT"
elmendorf = "0.5.2"
elmendorf = "0.6.0"

[libraries]
cca-base = { module = "dev.onyxstudios.cardinal-components-api:cardinal-components-base", version.ref = "cca" }
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pluginManagement {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
name "Quilt"
url "https://maven.quiltmc.org/repository/release"
}
maven {
name = 'Cotton'
url = 'https://server.bbkr.space/artifactory/libs-release/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.github.ladysnake.impersonate.impl.ImpersonateGamerules;
import io.github.ladysnake.impersonate.impl.PlayerImpersonator;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -45,7 +45,7 @@ public final class Impersonate implements ModInitializer, EntityComponentInitial

@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> ImpersonateCommand.register(dispatcher));
CommandRegistrationCallback.EVENT.register((dispatcher, acc, dedicated) -> ImpersonateCommand.register(dispatcher));
ImpersonateGamerules.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -99,9 +99,9 @@ private static int stopImpersonation(ServerCommandSource source, Collection<Serv
private static void sendImpersonationFeedback(ServerCommandSource source, ServerPlayerEntity player, GameProfile impersonated, String message) {
String name = impersonated.getName();
if (source.getEntity() == player) {
source.sendFeedback(new TranslatableText("impersonate:commands.disguise." + message + ".success.self", name), true);
source.sendFeedback(Text.translatable("impersonate:commands.disguise." + message + ".success.self", name), true);
} else {
source.sendFeedback(new TranslatableText("impersonate:commands.disguise." + message + ".success.other", player.getDisplayName(), name), true);
source.sendFeedback(Text.translatable("impersonate:commands.disguise." + message + ".success.other", player.getDisplayName(), name), true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,34 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Style;
import net.minecraft.text.TextContent;

public class ImpersonateText extends LiteralText implements RecipientAwareText {
import java.util.Optional;

public class ImpersonateTextContent implements TextContent {
private final String trueText;
private final String fakedText;
private boolean revealed;

public static Text get(PlayerEntity player) {
public static TextContent get(PlayerEntity player) {
return get(player, false);
}

public static Text get(PlayerEntity player, boolean reveal) {
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 ImpersonateText(trueText, fakeName, reveal);
return new ImpersonateTextContent(trueText, fakeName, reveal);
}

private ImpersonateText(String trueText, String fakedText, boolean revealed) {
super(fakedText);
private ImpersonateTextContent(String trueText, String fakedText, boolean revealed) {
this.trueText = trueText;
this.fakedText = fakedText;
this.revealed = revealed;
}

@Override
public void impersonateResolve(CommandOutput recipient) {
revealed = !(recipient instanceof PlayerEntity) || shouldBeRevealedBy((PlayerEntity) recipient);
}
Expand All @@ -59,18 +60,17 @@ public static boolean shouldBeRevealedBy(PlayerEntity player) {
}

@Override
public String asString() {
return this.getRawString();
public <T> Optional<T> visit(StringVisitable.StyledVisitor<T> visitor, Style style) {
return visitor.accept(style, this.getString());
}

@Override
public String getRawString() {
return this.revealed ? this.trueText : this.fakedText;
public <T> Optional<T> visit(StringVisitable.Visitor<T> visitor) {
return visitor.accept(this.getString());
}

@Override
public ImpersonateText copy() {
return new ImpersonateText(this.trueText, this.fakedText, this.revealed);
public String getString() {
return this.revealed ? this.trueText : this.fakedText;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;

import java.util.function.Function;

public final class PacketMeddling {

public static void resolvePlayerListEntries(PlayerListS2CPacket packet, ServerPlayerEntity player) {
boolean reveal = ImpersonateText.shouldBeRevealedBy(player);
boolean reveal = ImpersonateTextContent.shouldBeRevealedBy(player);
for (PlayerListS2CPacket.Entry entry : packet.getEntries()) {
PlayerEntity playerEntry = player.server.getPlayerManager().getPlayer(entry.getProfile().getId());
if (playerEntry != null) {
Impersonator impersonator = Impersonate.IMPERSONATION.get(playerEntry);
if (impersonator.isImpersonating()) {
// OPs get the true profile with semi-fake display name, others get a complete lie
if (reveal) {
((PlayerListS2CPacketEntryAccessor) entry).setDisplayName(ImpersonateText.get(playerEntry, true));
((PlayerListS2CPacketEntryAccessor) entry).setDisplayName(MutableText.of(ImpersonateTextContent.get(playerEntry, true)));
} else {
((PlayerListS2CPacketEntryAccessor) entry).setProfile(impersonator.getEditedProfile());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -106,8 +107,9 @@ public static synchronized void setSkin(@NotNull ServerPlayerEntity player, Game

/**
* Sets the skin to the specified player and reloads it with {@link #reloadSkin(ServerPlayerEntity)}
* @param player player whose skin needs to be changed
* @param value skin texture value
*
* @param player player whose skin needs to be changed
* @param value skin texture value
* @param signature skin texture signature
*/
private static void setPlayerSkin(ServerPlayerEntity player, @Nullable String value, @Nullable String signature) {
Expand All @@ -127,18 +129,19 @@ private static void setPlayerSkin(ServerPlayerEntity player, @Nullable String va

/**
* Reloads player's skin for all the players (including the one that has changed the skin)
*
* @param player player that wants to have the skin reloaded
*/
private static void reloadSkin(ServerPlayerEntity player) {
for(ServerPlayerEntity other : Objects.requireNonNull(player.getServer()).getPlayerManager().getPlayerList()) {
for (ServerPlayerEntity other : Objects.requireNonNull(player.getServer()).getPlayerManager().getPlayerList()) {
// Refreshing tablist for each player
other.networkHandler.sendPacket(new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER, player));
other.networkHandler.sendPacket(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, player));
}

ChunkManager manager = player.world.getChunkManager();
assert manager instanceof ServerChunkManager;
ThreadedAnvilChunkStorage storage = ((ServerChunkManager)manager).threadedAnvilChunkStorage;
ThreadedAnvilChunkStorage storage = ((ServerChunkManager) manager).threadedAnvilChunkStorage;
EntityTrackerAccessor trackerEntry = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(player.getId());

for (ServerPlayerEntity tracking : PlayerLookup.tracking(player)) {
Expand All @@ -155,7 +158,17 @@ private static void reloadSkin(ServerPlayerEntity player) {
private static void reloadSkinVanilla(ServerPlayerEntity player) {
// need to change the player entity on the client
ServerWorld targetWorld = (ServerWorld) player.world;
player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(targetWorld.method_40134(), targetWorld.getRegistryKey(), BiomeAccess.hashSeed(targetWorld.getSeed()), player.interactionManager.getGameMode(), player.interactionManager.getPreviousGameMode(), targetWorld.isDebugWorld(), targetWorld.isFlat(), true));
player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(
targetWorld.getDimensionKey(),
targetWorld.getRegistryKey(),
BiomeAccess.hashSeed(targetWorld.getSeed()),
player.interactionManager.getGameMode(),
player.interactionManager.getPreviousGameMode(),
targetWorld.isDebugWorld(),
targetWorld.isFlat(),
true,
player.getLastDeathPos()
));
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
player.server.getPlayerManager().sendCommandTree(player);
player.networkHandler.sendPacket(new ExperienceBarUpdateS2CPacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import net.minecraft.server.command.ListCommand;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.TranslatableTextContent;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -38,8 +38,8 @@ public abstract class ListCommandMixin {
private static void fakeNameAndUuid(ServerPlayerEntity player, CallbackInfoReturnable<Text> cir) {
Text text = cir.getReturnValue();

if (text instanceof TranslatableText) {
Object[] args = ((TranslatableText) text).getArgs();
if (text instanceof TranslatableTextContent cnt) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class MinecraftServerMixin implements CommandOutput {
@Shadow
public abstract ServerWorld getOverworld();

@ModifyVariable(method = "sendSystemMessage", at = @At("HEAD"), argsOnly = true)
@ModifyVariable(method = "sendMessage", at = @At("HEAD"), argsOnly = true)
private Text revealImpersonatorsInMessages(Text message) {
if (this.getOverworld() == null || this.getGameRules().getBoolean(ImpersonateGamerules.LOG_REVEAL_IMPERSONATIONS)) {
return ((RecipientAwareText) message).impersonateResolveAll(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;

import java.util.List;

@Mixin(MutableText.class)
public interface MutableTextMixin extends Text, RecipientAwareText {
public abstract class MutableTextMixin implements Text, RecipientAwareText {
@Override
default Text impersonateResolveAll(CommandOutput recipient) {
public Text impersonateResolveAll(CommandOutput recipient) {
this.impersonateResolve(recipient);
List<Text> siblings = this.getSiblings();
for (int i = 0; i < siblings.size(); i++) {
Text sibling = siblings.get(i);
siblings.set(i, ((RecipientAwareText) sibling).impersonateResolveAll(recipient));
}
this.getSiblings().replaceAll(text -> ((RecipientAwareText) text).impersonateResolveAll(recipient));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

import com.mojang.authlib.GameProfile;
import io.github.ladysnake.impersonate.Impersonator;
import io.github.ladysnake.impersonate.impl.ImpersonateText;
import io.github.ladysnake.impersonate.impl.ImpersonateTextContent;
import io.github.ladysnake.impersonate.impl.PlayerEntityExtensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
Expand Down Expand Up @@ -82,7 +83,7 @@ private void fakeName(CallbackInfoReturnable<Text> cir) {
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(ImpersonateText.get(self, world.isClient));
cir.setReturnValue(MutableText.of(ImpersonateTextContent.get(self, world.isClient)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
*/
package io.github.ladysnake.impersonate.impl.mixin;

import com.mojang.authlib.GameProfile;
import io.github.ladysnake.impersonate.Impersonator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(PlayerManager.class)
public class PlayerManagerMixin {
@Redirect(method = "loadPlayerData", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;getName()Lnet/minecraft/text/Text;"))
private Text resolvePlayerName(ServerPlayerEntity player) {
return new LiteralText(Impersonator.get(player).getActualProfile().getName());
@Redirect(method = "loadPlayerData", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;getGameProfile()Lcom/mojang/authlib/GameProfile;"))
private GameProfile resolvePlayerName(ServerPlayerEntity player) {
return Impersonator.get(player).getActualProfile();
}
@Redirect(method = "createStatHandler", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getName()Lnet/minecraft/text/Text;"))
private Text resolvePlayerStatsName(PlayerEntity player) {
return new LiteralText(Impersonator.get(player).getActualProfile().getName());
return Text.literal(Impersonator.get(player).getActualProfile().getName());
}
}
Loading

0 comments on commit 076bb8b

Please sign in to comment.