diff --git a/build.gradle b/build.gradle index 89f25cb..915bda5 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -34,8 +35,13 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modCompileOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") - modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") + //modCompileOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + //modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") + + modCompileOnly fabricApi.module("fabric-api-base", project.fabric_version) + modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version) + + modCompileOnly fabricApi.module("fabric-message-api-v1", project.fabric_version) modImplementation include("eu.pb4:placeholder-api:2.0.0-beta.7+1.19") modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT") @@ -45,6 +51,10 @@ dependencies { // You may need to force-disable transitiveness on them. } +loom { + enableTransitiveAccessWideners = false +} + processResources { inputs.property "version", project.version diff --git a/gradle.properties b/gradle.properties index c40c409..600cb33 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.19.1-pre3 -yarn_mappings=1.19.1-pre3+build.1 +minecraft_version=1.19.1-pre5 +yarn_mappings=1.19.1-pre5+build.1 loader_version=0.14.8 #Fabric api -fabric_version=0.57.1+1.19.1 +fabric_version=0.57.2+1.19.1 # Mod Properties - mod_version = 1.3.3+1.19.1 + mod_version = 1.4.0+1.19.1 maven_group = eu.pb4 archives_base_name = styled-chat # Dependencies -is_stable = true +is_stable = false diff --git a/src/main/java/eu/pb4/styledchat/StyledChatEvents.java b/src/main/java/eu/pb4/styledchat/StyledChatEvents.java index c8cdd78..6a26553 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatEvents.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatEvents.java @@ -5,9 +5,7 @@ import eu.pb4.placeholders.api.parsers.TextParserV1; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.network.message.MessageType; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; public class StyledChatEvents { /** diff --git a/src/main/java/eu/pb4/styledchat/StyledChatMod.java b/src/main/java/eu/pb4/styledchat/StyledChatMod.java index 90e3946..8f9802e 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatMod.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatMod.java @@ -1,52 +1,49 @@ package eu.pb4.styledchat; -import com.mojang.serialization.Lifecycle; import eu.pb4.placeholders.api.Placeholders; -import eu.pb4.styledchat.command.Commands; import eu.pb4.styledchat.config.ConfigManager; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.message.MessageType; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Decoration; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryKey; -import net.minecraft.util.registry.SimpleRegistry; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.Optional; - public class StyledChatMod implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger("Styled Chat"); public static MinecraftServer server = null; public static String VERSION = FabricLoader.getInstance().getModContainer("styledchat").get().getMetadata().getVersion().getFriendlyString(); - public static RegistryKey MESSAGE_TYPE = RegistryKey.of(Registry.MESSAGE_TYPE_KEY, new Identifier("styled_chat", "generic_hack")); + public static boolean USE_FABRIC_API = true; + + public static RegistryKey MESSAGE_TYPE_ID = RegistryKey.of(Registry.MESSAGE_TYPE_KEY, new Identifier("styled_chat", "generic_hack")); + public static MessageType MESSAGE_TYPE = new MessageType(Decoration.ofChat("%s"), Decoration.ofChat("%s")); @Override public void onInitialize() { this.crabboardDetection(); - Commands.register(); + Placeholders.registerChangeEvent((id, removed) -> ConfigManager.clearCached()); + + } - ServerLifecycleEvents.SERVER_STARTING.register((s) -> { - this.crabboardDetection(); - ConfigManager.loadConfig(); - server = s; - }); - ServerLifecycleEvents.SERVER_STOPPED.register((s) -> { - server = null; - }); + public static void serverStarting(MinecraftServer s) { + crabboardDetection(); + ConfigManager.loadConfig(); + server = s; + } - Placeholders.registerChangeEvent((id, removed) -> ConfigManager.clearCached()); + public static void serverStopped(MinecraftServer s) { + server = null; } - private void crabboardDetection() { + + private static void crabboardDetection() { if (FabricLoader.getInstance().isModLoaded("cardboard")) { LOGGER.error(""); LOGGER.error("Cardboard detected! This mod doesn't work with it!"); diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 8c5626e..f0315bd 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -15,12 +15,11 @@ import eu.pb4.styledchat.ducks.ExtSignedMessage; import eu.pb4.styledchat.parser.SpoilerNode; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.class_7597; import net.minecraft.command.EntitySelector; import net.minecraft.network.message.MessageDecorator; -import net.minecraft.network.message.MessageSignature; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SignedMessage; +import net.minecraft.network.packet.s2c.play.ChatSuggestionsS2CPacket; import net.minecraft.scoreboard.Team; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.filter.FilteredMessage; @@ -61,7 +60,7 @@ public final class StyledChatUtils { public static final String FORMAT_PERMISSION_UNSAFE = "styledchat.unsafe_format."; public static final Pattern EMOTE_PATTERN = Pattern.compile("[:](?[^:]+)[:]"); public static final Text EMPTY_TEXT = Text.empty(); - private static final Set> DECORABLE = Set.of(MessageType.CHAT, MessageType.EMOTE_COMMAND, MessageType.MSG_COMMAND_INCOMING, MessageType.MSG_COMMAND_OUTGOING, MessageType.SAY_COMMAND, MessageType.TEAM_MSG_COMMAND); + private static final Set> DECORABLE = Set.of(MessageType.CHAT, MessageType.EMOTE_COMMAND, MessageType.MSG_COMMAND_INCOMING, MessageType.MSG_COMMAND_OUTGOING, MessageType.SAY_COMMAND, MessageType.TEAM_MSG_COMMAND_INCOMING, MessageType.TEAM_MSG_COMMAND_OUTGOING); public static TextNode parseText(String input) { return !input.isEmpty() ? Placeholders.parseNodes(TextParserUtils.formatNodes(input)) : null; @@ -85,7 +84,7 @@ public static TextParserV1 createParser(ServerCommandSource source) { parser.register(SPOILER_TEXT_TAG); } - StyledChatEvents.FORMATTING_CREATION_EVENT.invoker().onFormattingBuild(source, parser); + //StyledChatEvents.FORMATTING_CREATION_EVENT.invoker().onFormattingBuild(source, parser); return parser; } @@ -100,12 +99,21 @@ public static Text formatFor(PlaceholderContext context, String input) { if (config.configData.enableMarkdown || config.configData.legacyChatFormatting) { input = legacyFormatMessage(input, parser.getTags().stream().map((x) -> x.name()).collect(Collectors.toSet())); } - input = StyledChatEvents.PRE_MESSAGE_CONTENT.invoker().onPreMessage(input, context); - + if (StyledChatMod.USE_FABRIC_API) { + input = StyledChatEvents.PRE_MESSAGE_CONTENT.invoker().onPreMessage(input, context); + } var emotes = getEmotes(context); + + var value = additionalParsing(new ParentNode(parser.parseNodes(new LiteralNode(input)))); + + if (StyledChatMod.USE_FABRIC_API) { + value = StyledChatEvents.MESSAGE_CONTENT.invoker().onMessage(value, context); + } + + var text = Placeholders.parseText( - StyledChatEvents.MESSAGE_CONTENT.invoker().onMessage(additionalParsing(new ParentNode(parser.parseNodes(new LiteralNode(input)))), context), + value, context, EMOTE_PATTERN, (id) -> emotes.containsKey(id) ? ((ctx, arg) -> PlaceholderResult.value(Placeholders.parseText(emotes.get(id), ctx))) : null @@ -200,7 +208,7 @@ public static MessageDecorator getCommandDecorator(String context, ServerCom return CompletableFuture.completedFuture(switch (context) { case "msg" -> { try { - yield config.getPrivateMessageSent( + yield config.getPrivateMessageReceived( source.getDisplayName(), ((EntitySelector) argumentGetter.apply("targets", EntitySelector.class)).getPlayers(source).get(0).getDisplayName(), input, source @@ -212,7 +220,7 @@ public static MessageDecorator getCommandDecorator(String context, ServerCom } case "teammsg" -> { try { - yield config.getTeamChatSent(((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), + yield config.getTeamChatReceived(((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), source.getDisplayName(), input, source ); @@ -292,12 +300,16 @@ public static void modifyForSending(FilteredMessage message, Serv ((ExtSignedMessage) (Object) message.raw()).styledChat_setArg("override", StyledChatUtils.formatMessage(message.raw(), source, type)); if (message.raw() != message.filtered()) { - ((ExtSignedMessage) (Object) message.raw()).styledChat_setArg("override", StyledChatUtils.formatMessage(message.filtered(), source, type)); + ((ExtSignedMessage) (Object) message.filtered()).styledChat_setArg("override", StyledChatUtils.formatMessage(message.filtered(), source, type)); } } public static void modifyForSending(SignedMessage message, ServerCommandSource source, RegistryKey type) { - ((ExtSignedMessage) (Object) message).styledChat_setArg("override", StyledChatUtils.formatMessage(message, source, type)); + try { + ((ExtSignedMessage) (Object) message).styledChat_setArg("override", StyledChatUtils.formatMessage(message, source, type)); + } catch (Exception e) { + e.printStackTrace(); + } } public static Text formatMessage(SignedMessage message, ServerCommandSource source, RegistryKey type) { @@ -332,7 +344,7 @@ public static Text formatMessage(SignedMessage message, ServerCommandSource sour yield Text.empty(); } } - case "team_msg_command" -> { + case "team_msg_command_incoming" -> { try { yield config.getTeamChatReceived(((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), source.getDisplayName(), @@ -343,6 +355,16 @@ public static Text formatMessage(SignedMessage message, ServerCommandSource sour } } + case "team_msg_command_outgoing" -> { + try { + yield config.getTeamChatSent(((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), + source.getDisplayName(), + input, source + ); + } catch (Exception e) { + yield Text.literal(""); + } + } case "say_command" -> config.getSayCommand(source, input); case "emote_command" -> config.getMeCommand(source, input); @@ -367,12 +389,12 @@ public static FilteredMessage toEventMessage(FilteredMessage(config.allPossibleAutoCompletionKeys))); + player.networkHandler.sendPacket(new ChatSuggestionsS2CPacket(ChatSuggestionsS2CPacket.Action.REMOVE, new ArrayList<>(config.allPossibleAutoCompletionKeys))); var set = new HashSet(); @@ -398,7 +420,7 @@ public static void sendAutocompliton(ServerPlayerEntity player) { } if (!set.isEmpty()) { - player.networkHandler.sendPacket(new class_7597(class_7597.class_7598.ADD, new ArrayList<>(set))); + player.networkHandler.sendPacket(new ChatSuggestionsS2CPacket(ChatSuggestionsS2CPacket.Action.ADD, new ArrayList<>(set))); } } } diff --git a/src/main/java/eu/pb4/styledchat/command/Commands.java b/src/main/java/eu/pb4/styledchat/command/Commands.java index df63880..1eb94f8 100644 --- a/src/main/java/eu/pb4/styledchat/command/Commands.java +++ b/src/main/java/eu/pb4/styledchat/command/Commands.java @@ -1,6 +1,7 @@ package eu.pb4.styledchat.command; +import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import eu.pb4.placeholders.api.PlaceholderContext; @@ -8,55 +9,54 @@ import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import net.minecraft.util.Util; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class Commands { - public static void register() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register( - literal("styledchat") - .requires(Permissions.require("styledchat.main", true)) - .executes(Commands::about) - - .then(literal("reload") - .requires(Permissions.require("styledchat.reload", 3)) - .executes(Commands::reloadConfig) - ) - ); - - dispatcher.register( - literal("tellform") - .requires(Permissions.require("styledchat.tellform", 2)) - - .then(argument("targets", EntityArgumentType.players()) - .then(argument("message", StringArgumentType.greedyString()) - .executes((context) -> { - int i = 0; - Text parsed; - - var ctx = context.getSource().getPlayer() != null ? PlaceholderContext.of(context.getSource().getPlayer()) : PlaceholderContext.of(context.getSource().getServer()); - - parsed = StyledChatUtils.formatFor(ctx, context.getArgument("message", String.class)); - - for (var player : EntityArgumentType.getPlayers(context, "targets")) { - player.sendMessage(parsed); - } - - return i; + public static void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { + dispatcher.register( + literal("styledchat") + .requires(Permissions.require("styledchat.main", true)) + .executes(Commands::about) + + .then(literal("reload") + .requires(Permissions.require("styledchat.reload", 3)) + .executes(Commands::reloadConfig) + ) + ); + + dispatcher.register( + literal("tellform") + .requires(Permissions.require("styledchat.tellform", 2)) + + .then(argument("targets", EntityArgumentType.players()) + .then(argument("message", StringArgumentType.greedyString()) + .executes((context) -> { + int i = 0; + Text parsed; + + var ctx = context.getSource().getPlayer() != null ? PlaceholderContext.of(context.getSource().getPlayer()) : PlaceholderContext.of(context.getSource().getServer()); + + parsed = StyledChatUtils.formatFor(ctx, context.getArgument("message", String.class)); + + for (var player : EntityArgumentType.getPlayers(context, "targets")) { + player.sendMessage(parsed); } - ) - ) - ) - ); - }); + + return i; + } + ) + ) + ) + ); + } private static int reloadConfig(CommandContext context) { diff --git a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java index f7337be..fbc8f96 100644 --- a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java +++ b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java @@ -22,7 +22,7 @@ public class ConfigData { public boolean parseLinksInChat = true; public boolean enableMarkdown = true; public boolean allowModdedDecorators = true; - public boolean sendFullMessageInChatPreview = true; + public boolean sendFullMessageInChatPreview = false; public boolean sendAutoCompletionForTags = false; public boolean sendAutoCompletionForTagAliases = false; public boolean sendAutoCompletionForEmotes = true; diff --git a/src/main/java/eu/pb4/styledchat/ducks/ExtSignedMessage.java b/src/main/java/eu/pb4/styledchat/ducks/ExtSignedMessage.java index 4bdea80..2ae51f2 100644 --- a/src/main/java/eu/pb4/styledchat/ducks/ExtSignedMessage.java +++ b/src/main/java/eu/pb4/styledchat/ducks/ExtSignedMessage.java @@ -3,7 +3,7 @@ import net.minecraft.text.Text; public interface ExtSignedMessage { - void styledChat_setOriginal(String message); + //void styledChat_setOriginal(String message); void styledChat_setArg(String name, Text arg); String styledChat_getOriginal(); Text styledChat_getArg(String name); diff --git a/src/main/java/eu/pb4/styledchat/mixin/CommandManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/CommandManagerMixin.java new file mode 100644 index 0000000..d761425 --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/mixin/CommandManagerMixin.java @@ -0,0 +1,23 @@ +package eu.pb4.styledchat.mixin; + +import com.mojang.brigadier.CommandDispatcher; +import eu.pb4.styledchat.command.Commands; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(CommandManager.class) +public class CommandManagerMixin { + @Shadow @Final private CommandDispatcher dispatcher; + + @Inject(method = "", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;setConsumer(Lcom/mojang/brigadier/ResultConsumer;)V")) + private void styledChat_registerCommand(CommandManager.RegistrationEnvironment environment, CommandRegistryAccess commandRegistryAccess, CallbackInfo ci) { + Commands.register(this.dispatcher, commandRegistryAccess, environment); + } +} diff --git a/src/main/java/eu/pb4/styledchat/mixin/MessageArgumentTypeSignedMessageMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MessageArgumentTypeSignedMessageMixin.java index 1c5deca..e34f4ee 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MessageArgumentTypeSignedMessageMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MessageArgumentTypeSignedMessageMixin.java @@ -2,18 +2,24 @@ import eu.pb4.styledchat.ducks.ExtPlayNetworkHandler; +import eu.pb4.styledchat.ducks.ExtSignedMessage; import net.minecraft.command.argument.MessageArgumentType; import net.minecraft.network.message.MessageDecorator; +import net.minecraft.network.message.SignedMessage; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.filter.FilteredMessage; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; @Mixin(MessageArgumentType.SignedMessage.class) public class MessageArgumentTypeSignedMessageMixin { - @Redirect(method = "method_44266", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;")) + @Redirect(method = "decorate(Lnet/minecraft/server/command/ServerCommandSource;Lnet/minecraft/server/filter/FilteredMessage;Lnet/minecraft/server/filter/FilteredMessage;)Ljava/util/concurrent/CompletableFuture;", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;")) private MessageDecorator styledChat_returnCached(MinecraftServer instance) { return (player, message) -> { if (player != null) { @@ -23,4 +29,16 @@ private MessageDecorator styledChat_returnCached(MinecraftServer instance) { return CompletableFuture.completedFuture(message); }; } + + /*@Redirect(method = "decorate", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;thenAccept(Ljava/util/function/Consumer;)Ljava/util/concurrent/CompletableFuture;")) + private CompletableFuture styledChat_replaceFormatting(CompletableFuture> instance, Consumer> action) { + return instance.thenAccept((x) -> { + ((ExtSignedMessage) (Object) x.raw()).styledChat_setOriginal(this.plain); + + if (x.raw() != x.filtered()) { + ((ExtSignedMessage) (Object) x.filtered()).styledChat_setOriginal(this.plain); + } + action.accept(x); + }); + }*/ } diff --git a/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java index 2fdf2fe..be85aac 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java @@ -9,18 +9,12 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.Optional; - @Mixin(MessageType.class) public class MessageTypeMixin { @Inject(method = "initialize", at = @At("TAIL")) private static void styledChat_replace(Registry registry, CallbackInfoReturnable> cir) { - - BuiltinRegistries.add(registry, StyledChatMod.MESSAGE_TYPE, - new MessageType(Decoration.ofChat("%s"), Decoration.ofChat("%s")) - ); + BuiltinRegistries.add(registry, StyledChatMod.MESSAGE_TYPE_ID, StyledChatMod.MESSAGE_TYPE); } } diff --git a/src/main/java/eu/pb4/styledchat/mixin/MinecraftServerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MinecraftServerMixin.java index 14586a9..0228316 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MinecraftServerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MinecraftServerMixin.java @@ -1,5 +1,6 @@ package eu.pb4.styledchat.mixin; +import eu.pb4.styledchat.StyledChatMod; import eu.pb4.styledchat.StyledChatUtils; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Text; @@ -12,6 +13,16 @@ @Mixin(MinecraftServer.class) public class MinecraftServerMixin { + @Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;setFavicon(Lnet/minecraft/server/ServerMetadata;)V")) + private void styledChat_registerStarting(CallbackInfo ci) { + StyledChatMod.serverStarting((MinecraftServer) (Object) this); + } + + @Inject(method = "shutdown", at = @At("TAIL")) + private void styledChat_registerStopping(CallbackInfo ci) { + StyledChatMod.serverStarting((MinecraftServer) (Object) this); + } + @Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true) private void styledChat_excludeSendingOfHiddenMessages(Text message, CallbackInfo ci) { if (message == StyledChatUtils.IGNORED_TEXT) { diff --git a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java index c177721..774129c 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java @@ -3,18 +3,16 @@ import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; import eu.pb4.styledchat.ducks.ExtSignedMessage; -import net.minecraft.class_7597; import net.minecraft.network.ClientConnection; -import net.minecraft.network.message.MessageSender; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SignedMessage; import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; +import net.minecraft.server.filter.FilteredMessage; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.Stats; import net.minecraft.text.Text; import net.minecraft.text.TranslatableTextContent; -import net.minecraft.util.registry.RegistryKey; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -27,6 +25,7 @@ import java.util.ArrayList; import java.util.HashSet; +import java.util.function.Predicate; @Mixin(PlayerManager.class) @@ -64,15 +63,15 @@ private void styledChat_sendTree(ServerPlayerEntity player, CallbackInfo ci) { StyledChatUtils.sendAutocompliton(player); } - @Redirect(method = "broadcast(Lnet/minecraft/network/message/SignedMessage;Ljava/util/function/Function;Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/util/registry/RegistryKey;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;logChatMessage(Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/text/Text;Lnet/minecraft/util/registry/RegistryKey;)V"), require = 0) - private void styledChat_fixServerLogs(MinecraftServer instance, MessageSender sender, Text ignore, RegistryKey typeKey, SignedMessage message) { - var out = ((ExtSignedMessage) (Object) message).styledChat_getArg("override"); + @Redirect(method = "broadcast(Lnet/minecraft/server/filter/FilteredMessage;Ljava/util/function/Predicate;Lnet/minecraft/network/message/MessageSourceProfile;Lnet/minecraft/network/message/MessageType$Parameters;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;logChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageType$Parameters;Ljava/lang/String;)V"), require = 0) + private void styledChat_fixServerLogs(MinecraftServer instance, Text text, MessageType.Parameters parameters, String string, FilteredMessage filteredMessage) { + var out = ((ExtSignedMessage) (Object) filteredMessage.raw()).styledChat_getArg("override"); if (out != null) { if (out != StyledChatUtils.IGNORED_TEXT) { this.server.sendMessage(out); } } else { - this.server.logChatMessage(sender, message.getContent(), typeKey); + this.server.logChatMessage(text, parameters, string); } } } diff --git a/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java new file mode 100644 index 0000000..8824a4d --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java @@ -0,0 +1,31 @@ +package eu.pb4.styledchat.mixin; + +import eu.pb4.styledchat.StyledChatMod; +import eu.pb4.styledchat.ducks.ExtSignedMessage; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SentMessage; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.util.registry.Registry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(SentMessage.Chat.class) +public abstract class SentMessageChatMixin { + @Shadow public abstract SignedMessage getWrappedMessage(); + + @Redirect(method = "toPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;")) + private MessageType.Serialized styledChat_replaceSerialized(MessageType.Parameters instance, DynamicRegistryManager registryManager) { + var override = ((ExtSignedMessage) (Object) this.getWrappedMessage()).styledChat_getArg("override"); + if (override != null) { + var reg = registryManager.get(Registry.MESSAGE_TYPE_KEY); + return new MessageType.Serialized(reg.getRawId(reg.get(StyledChatMod.MESSAGE_TYPE_ID)), override, null); + } else { + return instance.toSerialized(registryManager); + } + } +} diff --git a/src/main/java/eu/pb4/styledchat/mixin/SentMessageEntityMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SentMessageEntityMixin.java new file mode 100644 index 0000000..a6cc3b0 --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/mixin/SentMessageEntityMixin.java @@ -0,0 +1,33 @@ +package eu.pb4.styledchat.mixin; + +import eu.pb4.styledchat.StyledChatMod; +import eu.pb4.styledchat.ducks.ExtSignedMessage; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SentMessage; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.util.registry.Registry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SentMessage.Entity.class) +public abstract class SentMessageEntityMixin { + @Shadow public abstract SignedMessage getWrappedMessage(); + + @Redirect(method = "toPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;")) + private MessageType.Serialized styledChat_replaceSerialized(MessageType.Parameters instance, DynamicRegistryManager registryManager) { + var override = ((ExtSignedMessage) (Object) this.getWrappedMessage()).styledChat_getArg("override"); + if (override != null) { + var reg = registryManager.get(Registry.MESSAGE_TYPE_KEY); + return new MessageType.Serialized(reg.getRawId(reg.get(StyledChatMod.MESSAGE_TYPE_ID)), override, null); + } else { + return instance.toSerialized(registryManager); + } + } +} diff --git a/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java new file mode 100644 index 0000000..d19f51a --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java @@ -0,0 +1,33 @@ +package eu.pb4.styledchat.mixin; + +import eu.pb4.styledchat.StyledChatMod; +import eu.pb4.styledchat.ducks.ExtSignedMessage; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SentMessage; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.util.registry.Registry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SentMessage.Profileless.class) +public abstract class SentMessageProfilelessMixin { + @Shadow public abstract SignedMessage getWrappedMessage(); + + @Redirect(method = "toPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;")) + private MessageType.Serialized styledChat_replaceSerialized(MessageType.Parameters instance, DynamicRegistryManager registryManager) { + var override = ((ExtSignedMessage) (Object) this.getWrappedMessage()).styledChat_getArg("override"); + if (override != null) { + var reg = registryManager.get(Registry.MESSAGE_TYPE_KEY); + return new MessageType.Serialized(reg.getRawId(reg.get(StyledChatMod.MESSAGE_TYPE_ID)), override, null); + } else { + return instance.toSerialized(registryManager); + } + } +} diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java index fa260e1..d6d476a 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java @@ -5,14 +5,12 @@ import eu.pb4.styledchat.other.WrappedEvent; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +@Pseudo @Mixin(ServerMessageEvents.class) public class ServerMessageEventsMixin { @Mutable diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java index edcdaa7..01c9e76 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java @@ -3,6 +3,7 @@ import eu.pb4.styledchat.ducks.ExtPlayNetworkHandler; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; +import eu.pb4.styledchat.ducks.ExtSignedMessage; import net.minecraft.network.message.MessageDecorator; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SignedMessage; @@ -13,19 +14,20 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.*; import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.function.Consumer; @Mixin(ServerPlayNetworkHandler.class) -public class ServerPlayNetworkManagerMixin implements ExtPlayNetworkHandler { +public abstract class ServerPlayNetworkManagerMixin implements ExtPlayNetworkHandler { @Unique Text styledChat_lastCached = null; @@ -33,23 +35,15 @@ public class ServerPlayNetworkManagerMixin implements ExtPlayNetworkHandler { @Shadow public ServerPlayerEntity player; + @Shadow @Final private MinecraftServer server; + + @Shadow protected abstract void handleDecoratedMessage(FilteredMessage message); + @ModifyArg(method = "onDisconnected", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")) private Text styledChat_replaceDisconnectMessage(Text text) { return ConfigManager.getConfig().getLeft(this.player); } - @Redirect(method = "handleMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;")) - private MessageDecorator styledChat_replaceDecorator(MinecraftServer instance) { - return (player, message) -> CompletableFuture.completedFuture(this.styledChat_lastCached != null ? this.styledChat_lastCached : message); - } - - @Inject(method = "handleMessage", at = @At("HEAD")) - private void styledChat_removeCachedIfNotPreviewed(ChatMessageC2SPacket packet, FilteredMessage message, CallbackInfo ci) { - if (!packet.isPreviewed()) { - this.styledChat_lastCached = null; - } - } - @Redirect(method = "decorateChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;")) private MessageDecorator styledChat_replaceDecorator2(MinecraftServer instance) { return ConfigManager.getConfig().configData.sendFullMessageInChatPreview ? StyledChatUtils.getChatDecorator() : StyledChatUtils.getRawDecorator(); @@ -65,6 +59,32 @@ private void styledChat_setFormattedMessage(FilteredMessage messa StyledChatUtils.modifyForSending(message, this.player.getCommandSource(), MessageType.CHAT); } + /*@Redirect(method = "handleMessage", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;thenAcceptAsync(Ljava/util/function/Consumer;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;")) + private CompletableFuture> styledChat_replaceFormatting(CompletableFuture> instance, Consumer> action, Executor executor, ChatMessageC2SPacket packet, FilteredMessage message) { + return instance.thenApplyAsync((x) -> { + ((ExtSignedMessage) (Object) x.raw()).styledChat_setOriginal(message.raw()); + + if (x.raw() != x.filtered()) { + ((ExtSignedMessage) (Object) x.filtered()).styledChat_setOriginal(message.filtered()); + } + action.accept(x); + return null; + }, executor); + }*/ + + + @Redirect(method = "handleMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;")) + private MessageDecorator styledChat_replaceDecorator(MinecraftServer instance) { + return (player, message) -> CompletableFuture.completedFuture(this.styledChat_lastCached != null ? this.styledChat_lastCached : message); + } + + @Inject(method = "handleMessage", at = @At("HEAD")) + private void styledChat_removeCachedIfNotPreviewed(ChatMessageC2SPacket packet, FilteredMessage filteredMessage, CallbackInfoReturnable> cir) { + if (!packet.signedPreview()) { + this.styledChat_lastCached = null; + } + } + @Override public @Nullable Text styledChat_getLastCached() { return this.styledChat_lastCached; diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java index f168ddb..affe071 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayerEntityMixin.java @@ -1,19 +1,16 @@ package eu.pb4.styledchat.mixin; import eu.pb4.styledchat.ducks.ExtSignedMessage; -import eu.pb4.styledchat.StyledChatMod; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; -import net.minecraft.network.Packet; -import net.minecraft.network.message.MessageSender; +import net.minecraft.nbt.NbtCompound; import net.minecraft.network.message.MessageType; -import net.minecraft.network.message.SignedMessage; +import net.minecraft.network.message.SentMessage; import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; -import net.minecraft.util.registry.RegistryKey; +import net.minecraft.util.registry.Registry; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -23,15 +20,14 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Optional; - @Mixin(ServerPlayerEntity.class) public abstract class ServerPlayerEntityMixin { + @Shadow @Final public MinecraftServer server; - @Shadow protected abstract int getMessageTypeId(RegistryKey typeKey); + @Shadow public abstract void readCustomDataFromNbt(NbtCompound nbt); - @Shadow @Final public MinecraftServer server; + @Shadow public abstract void playerTick(); @ModifyArg(method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")) private Text styledChat_replaceDeathMessage(Text text) { @@ -45,14 +41,7 @@ private void styledChat_excludeSendingOfHiddenMessages(Text message, CallbackInf } } - @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) - private void styledChat_excludeSendingOfHiddenMessages(SignedMessage message, MessageSender sender, RegistryKey typeKey, CallbackInfo ci) { - if (message.getContent() == StyledChatUtils.IGNORED_TEXT) { - ci.cancel(); - } - } - - @Redirect(method = "sendChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V")) + /*@Redirect(method = "sendChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V")) private void styledChat_hacky(ServerPlayNetworkHandler instance, Packet packet, SignedMessage message, MessageSender sender, RegistryKey typeKey) { var override = ((ExtSignedMessage) (Object) message).styledChat_getArg("override"); if (override != null) { @@ -63,5 +52,21 @@ private void styledChat_hacky(ServerPlayNetworkHandler instance, Packet packe } else { instance.sendPacket(packet); } - } + }*/ + + /*@Redirect(method = "sendChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/SentMessage;toPacket(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)Lnet/minecraft/network/packet/s2c/play/ChatMessageS2CPacket;")) + private ChatMessageS2CPacket styledChat_hacky(SentMessage instance, ServerPlayerEntity player, MessageType.Parameters parameters) { + //var message = arg.method_44852(); + var reg = this.server.getRegistryManager().get(Registry.MESSAGE_TYPE_KEY); + var override = ((ExtSignedMessage) (Object) instance.getWrappedMessage()).styledChat_getArg("override"); + if (override != null) { + /*nstance.sendPacket(new ChatMessageS2CPacket(message, new MessageType.class_7603( + reg.getRawId(reg.get(StyledChatMod.MESSAGE_TYPE)), override, null + )));* / + + return null; + } else { + return instance.toPacket(player, parameters); + } + }*/ } diff --git a/src/main/java/eu/pb4/styledchat/mixin/SignedMessageMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SignedMessageMixin.java index 7dcb8c6..70eedf0 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/SignedMessageMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/SignedMessageMixin.java @@ -2,30 +2,37 @@ import eu.pb4.styledchat.ducks.ExtSignedMessage; import eu.pb4.styledchat.StyledChatUtils; -import net.minecraft.network.message.MessageSignature; +import net.minecraft.network.message.MessageBody; +import net.minecraft.network.message.MessageHeader; +import net.minecraft.network.message.MessageSignatureData; import net.minecraft.network.message.SignedMessage; import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.HashMap; import java.util.Map; +import java.util.Optional; @Mixin(SignedMessage.class) public class SignedMessageMixin implements ExtSignedMessage { - @Unique - private String styledChat_original; + /*@Unique + private String styledChat_original;*/ + @Shadow @Final private MessageBody signedBody; @Unique private Map styledChat_args = new HashMap<>(); - @Override + /*@Override public void styledChat_setOriginal(String message) { this.styledChat_original = message; - } + }*/ @Override public void styledChat_setArg(String name, Text arg) { @@ -34,7 +41,7 @@ public void styledChat_setArg(String name, Text arg) { @Override public String styledChat_getOriginal() { - return this.styledChat_original; + return this.signedBody.content().plain().getString(); } @Override @@ -42,8 +49,8 @@ public Text styledChat_getArg(String name) { return this.styledChat_args.getOrDefault(name, StyledChatUtils.EMPTY_TEXT); } - @Inject(method = "of(Lnet/minecraft/text/Text;Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignature;Z)Lnet/minecraft/network/message/SignedMessage;", at = @At("RETURN")) - private static void styledChat_setOriginal(Text originalContent, Text decoratedContent, MessageSignature signature, boolean previewed, CallbackInfoReturnable cir) { - ((ExtSignedMessage) (Object) cir.getReturnValue()).styledChat_setOriginal(originalContent.getString()); - } + /*@Inject(method = "(Lnet/minecraft/network/message/MessageHeader;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/network/message/MessageBody;Ljava/util/Optional;)V", at = @At("RETURN")) + private static void styledChat_setOriginal(MessageHeader messageHeader, MessageSignatureData messageSignatureData, MessageBody messageBody, Optional optional, CallbackInfo ci) { + ((ExtSignedMessage) this).styledChat_setOriginal(text.getString()); + }*/ } diff --git a/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java deleted file mode 100644 index fe7b50e..0000000 --- a/src/main/java/eu/pb4/styledchat/mixin/TeamMsgCommandMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -package eu.pb4.styledchat.mixin; - -import eu.pb4.styledchat.ducks.ExtSignedMessage; -import eu.pb4.styledchat.StyledChatUtils; -import eu.pb4.styledchat.config.ConfigManager; -import net.minecraft.entity.Entity; -import net.minecraft.network.message.MessageSender; -import net.minecraft.network.message.MessageType; -import net.minecraft.network.message.SignedMessage; -import net.minecraft.scoreboard.Team; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.command.TeamMsgCommand; -import net.minecraft.server.filter.FilteredMessage; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(TeamMsgCommand.class) -public class TeamMsgCommandMixin { - @Inject(method = "method_44148", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendMessage(Lnet/minecraft/text/Text;)V")) - private static void styledChat_formatOgText(List list, Entity entity, Text text, ServerCommandSource serverCommandSource, MessageSender messageSender, FilteredMessage decoratedMessage, CallbackInfo ci) { - var input = StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) decoratedMessage.raw()).styledChat_getOriginal()); - ((ExtSignedMessage) (Object) decoratedMessage.raw()).styledChat_setArg("base_input", input); - - if (decoratedMessage.raw() != decoratedMessage.filtered()) { - ((ExtSignedMessage) (Object) decoratedMessage.filtered()).styledChat_setArg("base_input", StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) decoratedMessage.filtered()).styledChat_getOriginal())); - } - - var config = ConfigManager.getConfig(); - serverCommandSource.sendFeedback(config.getTeamChatSent(((Team) entity.getScoreboardTeam()).getFormattedName(), entity.getDisplayName(), input, serverCommandSource), false); - - StyledChatUtils.modifyForSending(decoratedMessage, serverCommandSource, MessageType.TEAM_MSG_COMMAND); - } - - @Redirect(method = "method_44148", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendMessage(Lnet/minecraft/text/Text;)V")) - private static void styledChat_noop(ServerPlayerEntity instance, Text message) { - - } -} diff --git a/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/MeCommandMixin.java similarity index 95% rename from src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java rename to src/main/java/eu/pb4/styledchat/mixin/commands/MeCommandMixin.java index 2fbaa84..254fb4e 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MeCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/MeCommandMixin.java @@ -1,4 +1,4 @@ -package eu.pb4.styledchat.mixin; +package eu.pb4.styledchat.mixin.commands; import eu.pb4.styledchat.StyledChatUtils; import net.minecraft.network.message.MessageType; diff --git a/src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java similarity index 51% rename from src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java rename to src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java index 3c1e053..6c2ac20 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MessageCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java @@ -1,17 +1,17 @@ -package eu.pb4.styledchat.mixin; +package eu.pb4.styledchat.mixin.commands; import eu.pb4.styledchat.ducks.ExtSignedMessage; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; -import net.minecraft.network.message.MessageSender; +import net.minecraft.network.message.MessageSourceProfile; import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SentMessage; import net.minecraft.network.message.SignedMessage; import net.minecraft.server.command.MessageCommand; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.filter.FilteredMessage; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; -import net.minecraft.util.registry.RegistryKey; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -23,12 +23,12 @@ @Mixin(MessageCommand.class) public class MessageCommandMixin { @Inject(method = "method_44144", at = @At("HEAD")) - private static void styledChat_formatOgText(Collection collection, MessageSender messageSender, ServerCommandSource serverCommandSource, FilteredMessage decoratedMessage, CallbackInfo ci) { - var input = StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) decoratedMessage.raw()).styledChat_getOriginal()); - ((ExtSignedMessage) (Object) decoratedMessage.raw()).styledChat_setArg("base_input", input); + private static void styledChat_formatOgText(MessageSourceProfile messageSourceProfile, Collection collection, ServerCommandSource serverCommandSource, MessageType.Parameters parameters, FilteredMessage filteredMessage, CallbackInfo ci) { + var input = StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) filteredMessage.raw()).styledChat_getOriginal()); + ((ExtSignedMessage) (Object) filteredMessage.raw()).styledChat_setArg("base_input", input); - if (decoratedMessage.raw() != decoratedMessage.filtered()) { - ((ExtSignedMessage) (Object) decoratedMessage.filtered()).styledChat_setArg("base_input", StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) decoratedMessage.filtered()).styledChat_getOriginal())); + if (filteredMessage.raw() != filteredMessage.filtered()) { + ((ExtSignedMessage) (Object) filteredMessage.filtered()).styledChat_setArg("base_input", StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) filteredMessage.filtered()).styledChat_getOriginal())); } var config = ConfigManager.getConfig(); @@ -37,16 +37,21 @@ private static void styledChat_formatOgText(Collection colle } } - @Redirect(method = "method_44144", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/command/ServerCommandSource;method_44749(Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/util/registry/RegistryKey;)V")) - private static void styledChat_noopFeedback(ServerCommandSource instance, MessageSender messageSender, SignedMessage signedMessage, RegistryKey registryKey) { + @Redirect(method = "method_44144", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/command/ServerCommandSource;sendChatMessage(Lnet/minecraft/network/message/SentMessage;Lnet/minecraft/network/message/MessageType$Parameters;)V")) + private static void styledChat_noopFeedback(ServerCommandSource instance, SentMessage message, MessageType.Parameters params) { // noop } @Redirect(method = "method_44144", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/filter/FilteredMessage;getFilterableFor(Lnet/minecraft/server/command/ServerCommandSource;Lnet/minecraft/server/network/ServerPlayerEntity;)Ljava/lang/Object;")) - private static Object styledChat_formatText(FilteredMessage instance, ServerCommandSource source, ServerPlayerEntity receiver) { - var x = instance.getFilterableFor(source, receiver); - ((ExtSignedMessage) (Object) x).styledChat_setArg("targets", receiver.getDisplayName()); - StyledChatUtils.modifyForSending(x, source, MessageType.MSG_COMMAND_INCOMING); - return x; + private static Object styledChat_formatText(FilteredMessage instance, ServerCommandSource source, ServerPlayerEntity receiver) { + try { + var x = instance.getFilterableFor(source, receiver); + ((ExtSignedMessage) (Object) x.getWrappedMessage()).styledChat_setArg("targets", receiver.getDisplayName()); + StyledChatUtils.modifyForSending(x.getWrappedMessage(), source, MessageType.MSG_COMMAND_INCOMING); + return x; + } catch (Exception e) { + e.printStackTrace(); + return null; + } } } diff --git a/src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/SayCommandMixin.java similarity index 95% rename from src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java rename to src/main/java/eu/pb4/styledchat/mixin/commands/SayCommandMixin.java index 411a38b..502c58d 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/SayCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/SayCommandMixin.java @@ -1,4 +1,4 @@ -package eu.pb4.styledchat.mixin; +package eu.pb4.styledchat.mixin.commands; import eu.pb4.styledchat.StyledChatUtils; import net.minecraft.network.message.MessageType; diff --git a/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java new file mode 100644 index 0000000..74d5d44 --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java @@ -0,0 +1,41 @@ +package eu.pb4.styledchat.mixin.commands; + +import eu.pb4.styledchat.ducks.ExtSignedMessage; +import eu.pb4.styledchat.StyledChatUtils; +import eu.pb4.styledchat.config.ConfigManager; +import net.minecraft.entity.Entity; +import net.minecraft.network.message.MessageSourceProfile; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SentMessage; +import net.minecraft.scoreboard.Team; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.command.TeamMsgCommand; +import net.minecraft.server.filter.FilteredMessage; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(TeamMsgCommand.class) +public class TeamMsgCommandMixin { + @Inject(method = "method_44148", at = @At(value = "HEAD")) + private static void styledChat_formatOgText(MessageSourceProfile messageSourceProfile, List list, Entity entity, MessageType.Parameters parameters, ServerCommandSource serverCommandSource, MessageType.Parameters parameters2, FilteredMessage decoratedMessage, CallbackInfo ci) { + var input = StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) decoratedMessage.raw().getWrappedMessage()).styledChat_getOriginal()); + ((ExtSignedMessage) (Object) decoratedMessage.raw().getWrappedMessage()).styledChat_setArg("base_input", input); + StyledChatUtils.modifyForSending(decoratedMessage.raw().getWrappedMessage(), serverCommandSource, MessageType.TEAM_MSG_COMMAND_OUTGOING); + + if (decoratedMessage.raw().getWrappedMessage() != decoratedMessage.filtered().getWrappedMessage()) { + ((ExtSignedMessage) (Object) decoratedMessage.filtered().getWrappedMessage()).styledChat_setArg("base_input", StyledChatUtils.formatFor(serverCommandSource, ((ExtSignedMessage) (Object) decoratedMessage.filtered().getWrappedMessage()).styledChat_getOriginal())); + StyledChatUtils.modifyForSending(decoratedMessage.raw().getWrappedMessage(), serverCommandSource, MessageType.TEAM_MSG_COMMAND_OUTGOING); + } + + var config = ConfigManager.getConfig(); + serverCommandSource.sendFeedback(config.getTeamChatSent(((Team) entity.getScoreboardTeam()).getFormattedName(), entity.getDisplayName(), input, serverCommandSource), false); + } + + @Redirect(method = "method_44148", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendChatMessage(Lnet/minecraft/network/message/SentMessage;Lnet/minecraft/network/message/MessageType$Parameters;)V", ordinal = 0)) + private static void styledChat_noop(ServerPlayerEntity instance, SentMessage message, MessageType.Parameters params) {} +} diff --git a/src/main/resources/styledchat.mixins.json b/src/main/resources/styledchat.mixins.json index 8d042e5..9923f18 100644 --- a/src/main/resources/styledchat.mixins.json +++ b/src/main/resources/styledchat.mixins.json @@ -4,24 +4,28 @@ "package": "eu.pb4.styledchat.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "CommandManagerMixin", "DecoratableArgumentTypeMixin", - "MeCommandMixin", + "commands.MeCommandMixin", "MessageArgumentTypeMixin", "MessageArgumentTypeSignedMessageMixin", - "MessageCommandMixin", + "commands.MessageCommandMixin", "MessageFormatMixin", "MessageTypeMixin", "MinecraftServerMixin", "PlayerAdvancementTrackerMixin", "PlayerEntityMixin", "PlayerManagerMixin", - "SayCommandMixin", + "commands.SayCommandMixin", + "SentMessageChatMixin", + "SentMessageEntityMixin", + "SentMessageProfilelessMixin", "ServerMessageEventsMixin", "ServerPlayerEntityMixin", "ServerPlayNetworkManagerMixin", "SignedMessageMixin", "TameableEntityMixin", - "TeamMsgCommandMixin" + "commands.TeamMsgCommandMixin" ], "client": [ ],