diff --git a/build.gradle b/build.gradle index e629df1..1b41653 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,9 @@ dependencies { modImplementation include("eu.pb4:placeholder-api:2.0.0-beta.7+1.19") modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT") + modCompileOnly("fr.catcore:server-translations-api:1.4.16+1.19") + //modLocalRuntime("fr.catcore:server-translations-api:1.4.16+1.19") + //modRuntime "supercoder79:databreaker:0.2.7" // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. diff --git a/gradle.properties b/gradle.properties index f9b91a2..4a4ca39 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 -yarn_mappings=1.19.1+build.1 +minecraft_version=1.19.2 +yarn_mappings=1.19.2+build.1 loader_version=0.14.8 #Fabric api -fabric_version=0.58.4+1.19.1 +fabric_version=0.59.0+1.19.2 # Mod Properties - mod_version = 1.4.0+1.19.1 + mod_version = 1.4.1+1.19.2 maven_group = eu.pb4 archives_base_name = styled-chat # Dependencies -is_stable = false +is_stable = true diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index ef5cab1..5fe296a 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -15,13 +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_7649; import net.minecraft.command.EntitySelector; import net.minecraft.network.message.*; 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; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.ClickEvent; import net.minecraft.text.Text; diff --git a/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java index be85aac..8dbfd59 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.java @@ -9,6 +9,7 @@ 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; @Mixin(MessageType.class) diff --git a/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java index eba411a..922cd41 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java @@ -6,8 +6,6 @@ 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.Final; @@ -21,7 +19,7 @@ public abstract class SentMessageChatMixin implements ExtSentMessage { @Shadow @Final private SignedMessage message; - @Redirect(method = "method_45095", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;")) + @Redirect(method = "send", 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.message).styledChat_getArg("override"); if (override != null) { diff --git a/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java index e8efc21..615817b 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/SentMessageProfilelessMixin.java @@ -22,7 +22,7 @@ public abstract class SentMessageProfilelessMixin implements ExtSentMessage { @Shadow @Final private SignedMessage message; - @Redirect(method = "method_45095", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;")) + @Redirect(method = "send", 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.message).styledChat_getArg("override"); if (override != null) { diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java index f1b7ffc..360cc6d 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java @@ -3,13 +3,11 @@ import eu.pb4.styledchat.ducks.ExtPlayNetworkHandler; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; -import eu.pb4.styledchat.ducks.ExtSignedMessage; +import eu.pb4.styledchat.other.ServerTranslationUtils; import net.minecraft.network.message.MessageDecorator; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SignedMessage; -import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.filter.FilteredMessage; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.*; @@ -47,7 +45,7 @@ private MessageDecorator styledChat_replaceDecorator2(MinecraftServer instance) @Inject(method = "sendChatPreviewPacket", at = @At("HEAD")) private void styledChat_store(int queryId, Text preview, CallbackInfo ci) { - this.styledChat_lastCached = preview; + this.styledChat_lastCached = ServerTranslationUtils.translate(this.player, preview); } @Inject(method = "handleDecoratedMessage", at = @At("HEAD")) diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java b/src/main/java/eu/pb4/styledchat/mixin/compat/ServerMessageEventsMixin.java similarity index 98% rename from src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java rename to src/main/java/eu/pb4/styledchat/mixin/compat/ServerMessageEventsMixin.java index d6d476a..2a477cc 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/compat/ServerMessageEventsMixin.java @@ -1,4 +1,4 @@ -package eu.pb4.styledchat.mixin; +package eu.pb4.styledchat.mixin.compat; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.styledchat.StyledChatUtils; diff --git a/src/main/java/eu/pb4/styledchat/other/ServerTranslationUtils.java b/src/main/java/eu/pb4/styledchat/other/ServerTranslationUtils.java new file mode 100644 index 0000000..538fa4f --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/other/ServerTranslationUtils.java @@ -0,0 +1,19 @@ +package eu.pb4.styledchat.other; + +import fr.catcore.server.translations.api.LocalizationTarget; +import fr.catcore.server.translations.api.text.LocalizableText; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + +public class ServerTranslationUtils { + public static final boolean IS_PRESENT = FabricLoader.getInstance().isModLoaded("server_translations_api"); + + public static Text translate(ServerPlayerEntity player, Text text) { + if (IS_PRESENT) { + return LocalizableText.asLocalizedFor(text, (LocalizationTarget) player); + } else { + return text; + } + } +} diff --git a/src/main/resources/styledchat.mixins.json b/src/main/resources/styledchat.mixins.json index 85fa2ab..e35d034 100644 --- a/src/main/resources/styledchat.mixins.json +++ b/src/main/resources/styledchat.mixins.json @@ -18,7 +18,7 @@ "commands.SayCommandMixin", "SentMessageChatMixin", "SentMessageProfilelessMixin", - "ServerMessageEventsMixin", + "compat.ServerMessageEventsMixin", "ServerPlayerEntityMixin", "ServerPlayNetworkManagerMixin", "SignedMessageMixin",