diff --git a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEventListener.java index ca78c548..32f9697e 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEventListener.java @@ -46,16 +46,16 @@ public class MinecraftEventListener { public static void init() { - MinecraftEvents.SERVER_MESSAGE.register((playerChatMessage, commandSourceStack) -> { - sendDiscordMessage(playerChatMessage.decoratedContent().getString(), commandSourceStack.getDisplayName().getString(), JDA.getSelfUser().getAvatarUrl()); + MinecraftEvents.SERVER_MESSAGE.register((message, commandSourceStack) -> { + sendDiscordMessage(message, commandSourceStack.getDisplayName().getString(), JDA.getSelfUser().getAvatarUrl()); if (CONFIG.multiServer.enable) { - MULTI_SERVER.sendMessage(false, true, false, commandSourceStack.getDisplayName().getString(), playerChatMessage.decoratedContent().getString()); + MULTI_SERVER.sendMessage(false, true, false, commandSourceStack.getDisplayName().getString(), message); } }); - MinecraftEvents.PLAYER_MESSAGE.register((player, playerChatMessage) -> { - String contentToDiscord = playerChatMessage.decoratedContent().getString(); - String contentToMinecraft = playerChatMessage.decoratedContent().getString(); + MinecraftEvents.PLAYER_MESSAGE.register((player, message) -> { + String contentToDiscord = message; + String contentToMinecraft = message; if (StringUtils.countMatches(contentToDiscord, ":") >= 2) { String[] emojiNames = StringUtils.substringsBetween(contentToDiscord, ":", ":"); @@ -134,7 +134,7 @@ public static void init() { if (CONFIG.generic.broadcastChatMessages) { sendDiscordMessage(contentToDiscord, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString()))); if (CONFIG.multiServer.enable) { - MULTI_SERVER.sendMessage(false, true, false, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.formatChatMessages ? contentToMinecraft : playerChatMessage.decoratedContent().getString()); + MULTI_SERVER.sendMessage(false, true, false, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.formatChatMessages ? contentToMinecraft : message); } } diff --git a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEvents.java b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEvents.java index 479b25ae..a0ed89a9 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEvents.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/MinecraftEvents.java @@ -5,8 +5,6 @@ import net.minecraft.advancements.AdvancementHolder; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.PlayerChatMessage; -import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.damagesource.DamageSource; @@ -17,16 +15,16 @@ */ public interface MinecraftEvents { - Event SERVER_MESSAGE = EventFactory.createArrayBacked(ServerMessage.class, callbacks -> (playerChatMessage, commandSourceStack) -> { + Event SERVER_MESSAGE = EventFactory.createArrayBacked(ServerMessage.class, callbacks -> (message, commandSourceStack) -> { for (ServerMessage callback : callbacks) { - callback.message(playerChatMessage, commandSourceStack); + callback.message(message, commandSourceStack); } }); - Event PLAYER_MESSAGE = EventFactory.createArrayBacked(PlayerMessage.class, callbacks -> (player, playerChatMessage) -> { + Event PLAYER_MESSAGE = EventFactory.createArrayBacked(PlayerMessage.class, callbacks -> (player, message) -> { Optional result = Optional.empty(); for (PlayerMessage callback : callbacks) { - result = callback.message(player, playerChatMessage); + result = callback.message(player, message); } return result; }); @@ -62,11 +60,11 @@ public interface MinecraftEvents { }); interface ServerMessage { - void message(PlayerChatMessage playerChatMessage, CommandSourceStack commandSourceStack); + void message(String message, CommandSourceStack commandSourceStack); } interface PlayerMessage { - Optional message(ServerPlayer player, PlayerChatMessage playerChatMessage); + Optional message(ServerPlayer player, String message); } interface PlayerCommand { 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 116ead07..9e4974e6 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerList.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinPlayerList.java @@ -30,12 +30,12 @@ public class MixinPlayerList { //#if MC > 11900 @Inject(method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/network/chat/ChatType$Bound;)V", at = @At("HEAD")) private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CommandSourceStack commandSourceStack, ChatType.Bound bound, CallbackInfo ci) { - MinecraftEvents.SERVER_MESSAGE.invoker().message(playerChatMessage, commandSourceStack); + MinecraftEvents.SERVER_MESSAGE.invoker().message(playerChatMessage.decoratedContent().getString(), commandSourceStack); } //#else //$$ @Inject(method = "broadcastChatMessage", at = @At("HEAD")) //$$ private void broadcastChatMessage(FilteredText filteredText, CommandSourceStack commandSourceStack, ResourceKey resourceKey, CallbackInfo ci) { - //$$ MinecraftEvents.SERVER_MESSAGE.invoker().message(filteredText.filtered(), commandSourceStack); + //$$ MinecraftEvents.SERVER_MESSAGE.invoker().message(filteredText.filtered().serverContent().getString(), commandSourceStack); //$$ // TODO filtered() or raw() ? //$$ } //#endif 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 7cc8b911..86a76923 100644 --- a/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerGamePacketListenerImpl.java +++ b/src/main/java/com/xujiayao/mcdiscordchat/minecraft/mixins/MixinServerGamePacketListenerImpl.java @@ -34,7 +34,7 @@ public class MixinServerGamePacketListenerImpl { @Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true) private void broadcastChatMessage(PlayerChatMessage playerChatMessage, CallbackInfo ci) { - Optional result = MinecraftEvents.PLAYER_MESSAGE.invoker().message(player, playerChatMessage); + 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));