From 217567c037ea51c68d7c8551043e648c7aac3600 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 4 May 2022 21:34:22 +0200 Subject: [PATCH] 22w18a --- gradle.properties | 2 +- ...PacketListenerImpl_scarpetEventsMixin.java | 8 ++++-- ...java => ServerPlayer_actionPackMixin.java} | 9 ++---- .../ServerPlayer_scarpetEventMixin.java | 6 ++-- ...Player_updateSuppressionCrashFixMixin.java | 5 ++-- .../carpet/patches/EntityPlayerMPFake.java | 9 +++--- .../script/utils/SnoopyCommandSource.java | 28 +++++++++++++------ src/main/resources/carpet.mixins.json | 2 +- 8 files changed, 40 insertions(+), 29 deletions(-) rename src/main/java/carpet/mixins/{ServerPlayerMixin.java => ServerPlayer_actionPackMixin.java} (82%) diff --git a/gradle.properties b/gradle.properties index 88f04a49..227bb77a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use # or better: https://modmuss50.me/fabric.html - minecraft_version=22w17a + minecraft_version=22w18a loader_version=0.13.3 fabric_version=0.49.4+1.19 diff --git a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java index 6ef09fbc..cc533e5b 100644 --- a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java +++ b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java @@ -1,5 +1,7 @@ package carpet.mixins; +import net.minecraft.network.chat.MessageSignature; +import net.minecraft.network.chat.SignedMessage; import net.minecraft.network.protocol.game.ServerboundChatPacket; import net.minecraft.server.network.TextFilter; import org.spongepowered.asm.mixin.Mixin; @@ -284,13 +286,13 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin } @Inject(method = "handleChat(Lnet/minecraft/network/protocol/game/ServerboundChatPacket;Lnet/minecraft/server/network/TextFilter$FilteredText;)V", - at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z"), + at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/SignedMessage;Lnet/minecraft/server/network/TextFilter$FilteredText;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/resources/ResourceKey;)V"), locals = LocalCapture.CAPTURE_FAILHARD ) - private void onChatMessage(ServerboundChatPacket serverboundChatPacket, TextFilter.FilteredText filteredText, CallbackInfo ci, String string) { + private void onChatMessage(ServerboundChatPacket serverboundChatPacket, TextFilter.FilteredText filteredText, CallbackInfo ci, MessageSignature messageSignature, SignedMessage signedMessage) { if (PLAYER_MESSAGE.isNeeded()) { - PLAYER_MESSAGE.onPlayerMessage(player,string); + PLAYER_MESSAGE.onPlayerMessage(player, filteredText.getRaw()); } } } diff --git a/src/main/java/carpet/mixins/ServerPlayerMixin.java b/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java similarity index 82% rename from src/main/java/carpet/mixins/ServerPlayerMixin.java rename to src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java index d5448ec0..90b4ca2a 100644 --- a/src/main/java/carpet/mixins/ServerPlayerMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java @@ -7,6 +7,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.ProfilePublicKey; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -14,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayer.class) -public abstract class ServerPlayerMixin implements ServerPlayerEntityInterface +public abstract class ServerPlayer_actionPackMixin implements ServerPlayerEntityInterface { @Unique public EntityPlayerActionPack actionPack; @@ -25,11 +26,7 @@ public abstract class ServerPlayerMixin implements ServerPlayerEntityInterface } @Inject(method = "", at = @At(value = "RETURN")) - private void onServerPlayerEntityContructor( - MinecraftServer minecraftServer_1, - ServerLevel serverWorld_1, - GameProfile gameProfile_1, - CallbackInfo ci) + private void onServerPlayerEntityContructor(MinecraftServer foo, ServerLevel bar, GameProfile baz, ProfilePublicKey qux, CallbackInfo ci) { this.actionPack = new EntityPlayerActionPack((ServerPlayer) (Object) this); } diff --git a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java index 1ee3d69b..2be1737d 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java @@ -14,6 +14,7 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.ProfilePublicKey; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; @@ -38,9 +39,8 @@ public abstract class ServerPlayer_scarpetEventMixin extends Player implements S @Unique private boolean isInvalidReference = false; - public ServerPlayer_scarpetEventMixin(Level world, BlockPos blockPos, float f, GameProfile gameProfile) - { - super(world, blockPos, f, gameProfile); + public ServerPlayer_scarpetEventMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile, ProfilePublicKey profilePublicKey) { + super(level, blockPos, f, gameProfile, profilePublicKey); } @Shadow protected abstract void completeUsingItem(); diff --git a/src/main/java/carpet/mixins/ServerPlayer_updateSuppressionCrashFixMixin.java b/src/main/java/carpet/mixins/ServerPlayer_updateSuppressionCrashFixMixin.java index 7acf11ef..ea7a584f 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_updateSuppressionCrashFixMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_updateSuppressionCrashFixMixin.java @@ -10,6 +10,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.ProfilePublicKey; import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -18,8 +19,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ServerPlayer.class) public abstract class ServerPlayer_updateSuppressionCrashFixMixin extends Player { - public ServerPlayer_updateSuppressionCrashFixMixin(Level world, BlockPos pos, float yaw, GameProfile profile) { - super(world, pos, yaw, profile); + public ServerPlayer_updateSuppressionCrashFixMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile, ProfilePublicKey profilePublicKey) { + super(level, blockPos, f, gameProfile, profilePublicKey); } @Redirect( diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index 9c4cdf85..7f7b28c8 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -17,6 +17,7 @@ import net.minecraft.server.players.GameProfileCache; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.ProfilePublicKey; import net.minecraft.world.food.FoodData; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.GameType; @@ -60,7 +61,7 @@ public class EntityPlayerMPFake extends ServerPlayer SkullBlockEntity.updateGameprofile(gameprofile, result::set); gameprofile = result.get(); } - EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false); + EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false, null); instance.fixStartingPosition = () -> instance.moveTo(d0, d1, d2, (float) yaw, (float) pitch); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance); instance.teleportTo(worldIn, d0, d1, d2, (float)yaw, (float)pitch); @@ -82,7 +83,7 @@ public class EntityPlayerMPFake extends ServerPlayer player.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login")); ServerLevel worldIn = player.getLevel();//.getWorld(player.dimension); GameProfile gameprofile = player.getGameProfile(); - EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true); + EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true, player.getProfilePublicKey()); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow); playerShadow.setHealth(player.getHealth()); @@ -100,9 +101,9 @@ public class EntityPlayerMPFake extends ServerPlayer return playerShadow; } - private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow) + private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow, ProfilePublicKey profilePublicKey) { - super(server, worldIn, profile); + super(server, worldIn, profile, profilePublicKey); isAShadow = shadow; } diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index 75d35c43..92e52519 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -2,6 +2,7 @@ package carpet.script.utils; import carpet.CarpetSettings; import com.mojang.brigadier.ResultConsumer; +import net.minecraft.commands.CommandSigningContext; import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.EntityAnchorArgument; @@ -36,12 +37,13 @@ public class SnoopyCommandSource extends CommandSourceStack // good stuff private final Component[] error; private final List chatOutput; + private final CommandSigningContext signingContext; public SnoopyCommandSource(CommandSourceStack original, Component[] error, List chatOutput) { super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), CarpetSettings.runPermissionLevel, original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false, - (ctx, succ, res) -> { }, EntityAnchorArgument.Anchor.FEET); + (ctx, succ, res) -> { }, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.NONE); this.output = CommandSource.NULL; this.position = original.getPosition(); this.world = original.getLevel(); @@ -55,6 +57,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.rotation = original.getRotation(); this.error = error; this.chatOutput = chatOutput; + this.signingContext = original.getSigningContext(); } public SnoopyCommandSource(ServerPlayer player, Component[] error, List output) { @@ -75,14 +78,15 @@ public class SnoopyCommandSource extends CommandSourceStack this.rotation = player.getRotationVector(); // not a client call really this.error = error; this.chatOutput = output; + this.signingContext = CommandSigningContext.NONE; } - private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, ResultConsumer consumer, EntityAnchorArgument.Anchor entityAnchor, + private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, ResultConsumer consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, Component[] error, List chatOutput ) { super(output, pos, rot, world, level, simpleName, name, server, entity, false, - consumer, entityAnchor); + consumer, entityAnchor, context); this.output = output; this.position = pos; this.rotation = rot; @@ -96,30 +100,31 @@ public class SnoopyCommandSource extends CommandSourceStack this.entityAnchor = entityAnchor; this.error = error; this.chatOutput = chatOutput; + this.signingContext = context; } @Override public CommandSourceStack withEntity(Entity entity) { - return new SnoopyCommandSource(output, position, rotation, world, level, entity.getName().getString(), entity.getDisplayName(), server, entity, resultConsumer, entityAnchor, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, entity.getName().getString(), entity.getDisplayName(), server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); } @Override public CommandSourceStack withPosition(Vec3 position) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); } @Override public CommandSourceStack withRotation(Vec2 rotation) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); } @Override public CommandSourceStack withCallback(ResultConsumer consumer) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, error, chatOutput); } @Override @@ -148,7 +153,12 @@ public class SnoopyCommandSource extends CommandSourceStack @Override public CommandSourceStack withAnchor(EntityAnchorArgument.Anchor anchor) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, anchor, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, anchor, signingContext, error, chatOutput); + } + + @Override + public CommandSourceStack withSigningContext(CommandSigningContext commandSigningContext) { + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, commandSigningContext, error, chatOutput); } @Override @@ -156,7 +166,7 @@ public class SnoopyCommandSource extends CommandSourceStack { double d = DimensionType.getTeleportationScale(this.world.dimensionType(), world.dimensionType()); Vec3 position = new Vec3(this.position.x * d, this.position.y, this.position.z * d); - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); } @Override diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index e570c4b0..5ceda88d 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -64,7 +64,7 @@ "ExperienceOrb_xpNoCooldownMixin", "Player_xpNoCooldownMixin", "ServerboundPlayerActionPacketMixin", - "ServerPlayerMixin", + "ServerPlayer_actionPackMixin", "PlayerList_coreMixin", "PlayerList_fakePlayersMixin", "RedstoneWireBlock_fastMixin",