From 3fd5fb35c957e2b011fab590fcf4a8ec2101ed2f Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Sun, 11 Feb 2024 03:03:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=84=E7=89=88=E6=9C=ACMi?= =?UTF-8?q?xin=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mixins/MixinPlayerAdvancements.java | 2 +- .../minecraft/mixins/MixinPlayerList.java | 6 +-- .../MixinServerGamePacketListenerImpl.java | 37 +++++++++++++------ .../minecraft/mixins/MixinServerPlayer.java | 2 +- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerAdvancements.java b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerAdvancements.java index b7094033..6ed179ca 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerAdvancements.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerAdvancements.java @@ -23,7 +23,7 @@ public abstract class MixinPlayerAdvancements { @Shadow public abstract AdvancementProgress getOrStartProgress(AdvancementHolder advancementHolder); - @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER)) + @Inject(method = "award(Lnet/minecraft/advancements/AdvancementHolder;Ljava/lang/String;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER)) private void award(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable cir) { MinecraftEvents.PLAYER_ADVANCEMENT.invoker().advancement(player, advancementHolder, getOrStartProgress(advancementHolder).isDone()); } diff --git a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerList.java b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerList.java index 365a3336..5433944d 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerList.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerList.java @@ -47,21 +47,21 @@ private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CommandSo //$$ @Inject(method = "broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD")) //$$ private void broadcastChatMessage(FilteredText filteredText, CommandSourceStack commandSourceStack, ResourceKey resourceKey, CallbackInfo ci) { //$$ MinecraftEvents.SERVER_MESSAGE.invoker().message(filteredText.filtered().serverContent().getString(), commandSourceStack); - //$$ // TODO filtered() or raw() ? //$$ } //#endif // TODO This feature has been removed in versions 1.18.2 and below due to compatibility issues (#197) - @Inject(method = "placeNewPlayer", at = @At("RETURN")) //#if MC >= 12002 + @Inject(method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/server/network/CommonListenerCookie;)V", at = @At("RETURN")) private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { //#else + //$$ @Inject(method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;)V", at = @At("RETURN")) //$$ private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CallbackInfo ci) { //#endif MinecraftEvents.PLAYER_JOIN.invoker().join(serverPlayer); } - @Inject(method = "remove", at = @At("HEAD")) + @Inject(method = "remove(Lnet/minecraft/server/level/ServerPlayer;)V", at = @At("HEAD")) private void remove(ServerPlayer serverPlayer, CallbackInfo ci) { MinecraftEvents.PLAYER_QUIT.invoker().quit(serverPlayer); } diff --git a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerGamePacketListenerImpl.java b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerGamePacketListenerImpl.java index e69c4553..1bace8a1 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerGamePacketListenerImpl.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerGamePacketListenerImpl.java @@ -30,6 +30,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC == 11900 +//$$ import java.util.Objects; +//#endif import java.util.Optional; import static com.xujiayao.mcdiscordchat.Main.SERVER; @@ -43,21 +46,26 @@ public class MixinServerGamePacketListenerImpl { @Shadow private ServerPlayer player; - //#if MC > 11802 - @Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true) + //#if MC > 11900 + @Inject(method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;)V", at = @At("HEAD"), cancellable = true) private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CallbackInfo ci) { Optional result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, playerChatMessage.decoratedContent().getString()); if (result.isPresent()) { - //#if MC > 11900 SERVER.getPlayerList().broadcastChatMessage(playerChatMessage.withUnsignedContent(result.get()), this.player, ChatType.bind(ChatType.CHAT, player)); - //#else - //$$ SERVER.getPlayerList().broadcastChatMessage(FilteredText.passThrough(playerChatMessage.withUnsignedContent(result.get())), this.player, ChatType.CHAT); - //#endif ci.cancel(); } } + //#elseif MC == 11900 + //$$ @Inject(method = "broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;)V", at = @At("HEAD"), cancellable = true) + //$$ private void broadcastChatMessage(FilteredText filteredText, CallbackInfo ci) { + //$$ Optional result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, Objects.requireNonNull(filteredText.filtered()).serverContent().getString()); + //$$ if (result.isPresent()) { + //$$ SERVER.getPlayerList().broadcastChatMessage(FilteredText.passThrough(filteredText.filtered().withUnsignedContent(result.get())), this.player, ChatType.CHAT); + //$$ ci.cancel(); + //$$ } + //$$ } //#elseif MC > 11605 - //$$ @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"), cancellable = true) + //$$ @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"), cancellable = true) //$$ private void handleChat(TextFilter.FilteredText filteredText, CallbackInfo ci) { //$$ Optional result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, filteredText.getFiltered()); //$$ if (result.isPresent()) { @@ -88,18 +96,23 @@ private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CallbackI //$$ } //#endif - //#if MC > 11900 - @Inject(method = "performChatCommand", at = @At("HEAD")) + //#if MC >= 11903 + @Inject(method = "performChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;Lnet/minecraft/network/chat/LastSeenMessages;)V", at = @At("HEAD")) private void performChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, LastSeenMessages lastSeenMessages, CallbackInfo ci) { MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command()); } - //#elseif MC > 11802 - //$$ @Inject(method = "handleChatCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)V")) + //#elseif MC > 11900 + //$$ @Inject(method = "performChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;)V", at = @At("HEAD")) + //$$ private void performChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) { + //$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command()); + //$$ } + //#elseif MC == 11900 + //$$ @Inject(method = "handleChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)I")) //$$ private void handleChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) { //$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, "/" + serverboundChatCommandPacket.command()); //$$ } //#else - //$$ @Inject(method = "handleCommand", at = @At("HEAD")) + //$$ @Inject(method = "handleCommand(Ljava/lang/String;)V", at = @At("HEAD")) //$$ private void handleCommand(String string, CallbackInfo ci) { //$$ MinecraftEvents.PLAYER_COMMAND.invoker().command(player, string); //$$ } diff --git a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerPlayer.java b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerPlayer.java index 844f6b55..fc285512 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerPlayer.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerPlayer.java @@ -14,7 +14,7 @@ @Mixin(ServerPlayer.class) public class MixinServerPlayer { - @Inject(method = "die", at = @At("HEAD")) + @Inject(method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At("HEAD")) private void die(DamageSource damageSource, CallbackInfo ci) { MinecraftEvents.PLAYER_DIE.invoker().die((ServerPlayer) (Object) this, damageSource); }