Skip to content

Commit

Permalink
Fix server translation api breaking chat previews
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Aug 14, 2022
1 parent 489a9c8 commit e41352e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 17 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/main/java/eu/pb4/styledchat/StyledChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/eu/pb4/styledchat/other/ServerTranslationUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/styledchat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"commands.SayCommandMixin",
"SentMessageChatMixin",
"SentMessageProfilelessMixin",
"ServerMessageEventsMixin",
"compat.ServerMessageEventsMixin",
"ServerPlayerEntityMixin",
"ServerPlayNetworkManagerMixin",
"SignedMessageMixin",
Expand Down

0 comments on commit e41352e

Please sign in to comment.