From b13a9a98ef52f70bea9df2a05acf0239e93c6eea Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:55:35 +0200 Subject: [PATCH] Update to 1.20.2 --- build.gradle | 4 +- gradle.properties | 10 ++-- .../eu/pb4/styledchat/StyledChatUtils.java | 59 +------------------ .../mixin/PlayerAdvancementTrackerMixin.java | 2 +- .../styledchat/mixin/PlayerManagerMixin.java | 5 +- .../mixin/ServerPlayNetworkManagerMixin.java | 24 ++++---- .../other/StyledChatSentMessage.java | 4 +- 7 files changed, 26 insertions(+), 82 deletions(-) diff --git a/build.gradle b/build.gradle index c48eaea..440e19b 100644 --- a/build.gradle +++ b/build.gradle @@ -41,10 +41,10 @@ dependencies { //modCompileOnly fabricApi.module("fabric-api-base", project.fabric_version) //modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version) - modImplementation include("eu.pb4:predicate-api:0.1.2+1.20") + modImplementation include("eu.pb4:predicate-api:0.3.0+1.20.2") modImplementation include("eu.pb4:placeholder-api:2.1.3+1.20.1") modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT") - modImplementation include("eu.pb4:player-data-api:0.2.2+1.19.3") + modImplementation include("eu.pb4:player-data-api:0.3.0+1.20.2") modCompileOnly("maven.modrinth:vanish:1.1.0") //modLocalRuntime("fr.catcore:server-translations-api:1.4.17+1.19.2") diff --git a/gradle.properties b/gradle.properties index 870d082..84b17d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.1 -loader_version=0.14.21 +minecraft_version=1.20.2-rc2 +yarn_mappings=1.20.2-rc2+build.1 +loader_version=0.14.22 #Fabric api -fabric_version=0.83.0+1.20.1 +fabric_version=0.89.0+1.20.2 # Mod Properties - mod_version = 2.2.3+1.20.1 + mod_version = 2.3.0+1.20.2 maven_group = eu.pb4 archives_base_name = styled-chat diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 4cd7540..6abfb72 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -194,7 +194,7 @@ public static Text formatFor(PlaceholderContext context, String input) { if (config.configData.formatting.respectColors) { try { - text = context.server().getMessageDecorator().decorate(context.player(), text).get(); + text = context.server().getMessageDecorator().decorate(context.player(), text); } catch (Exception e) { // noop } @@ -203,63 +203,10 @@ public static Text formatFor(PlaceholderContext context, String input) { return text; } - // Todo: Remove this - public static String legacyFormatMessage(String input, Set handlers) { - var config = ConfigManager.getConfig(); - - try { - if (config.configData.formatting.markdown) { - if (handlers.contains(SPOILER_TAG)) { - input = input.replaceAll(getMarkdownRegex("||", "\\|\\|"), "$2"); - } - - if (handlers.contains("bold")) { - input = input.replaceAll(getMarkdownRegex("**", "\\*\\*"), "$2"); - } - - if (handlers.contains("underline")) { - input = input.replaceAll(getMarkdownRegex("__", "__"), "$2"); - } - - if (handlers.contains("strikethrough")) { - input = input.replaceAll(getMarkdownRegex("~~", "~~"), "$2"); - } - - if (handlers.contains("italic")) { - input = input.replaceAll(getMarkdownRegex("*", "\\*"), "$2"); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - return input; - } - private static String getMarkdownRegex(String base, String sides) { return "(" + sides + ")(?[^" + base + "]+)(" + sides + ")"; } - public static MessageDecorator getChatDecorator() { - return (player, message) -> { - if (player != null) { - return CompletableFuture.completedFuture(StyledChatStyles.getChat(player, formatFor(PlaceholderContext.of(player), message.getString()))); - } else { - return CompletableFuture.completedFuture(formatFor(PlaceholderContext.of(StyledChatMod.server), message.getString())); - } - }; - } - - public static MessageDecorator getRawDecorator() { - return (player, message) -> { - if (player != null) { - return CompletableFuture.completedFuture(formatFor(PlaceholderContext.of(player), message.getString())); - } else { - return CompletableFuture.completedFuture(formatFor(PlaceholderContext.of(StyledChatMod.server), message.getString())); - } - }; - } - public static MessageDecorator getCommandDecorator(String context, ServerCommandSource source, BiFunction, Object> argumentGetter) { Config config = ConfigManager.getConfig(); @@ -268,7 +215,7 @@ public static MessageDecorator getCommandDecorator(String context, ServerCom var input = formatFor(player != null ? PlaceholderContext.of(player) : PlaceholderContext.of(StyledChatMod.server), message.getString()); - return CompletableFuture.completedFuture(switch (context) { + return switch (context) { case "msg" -> { try { yield config.getPrivateMessageReceived( @@ -297,7 +244,7 @@ public static MessageDecorator getCommandDecorator(String context, ServerCom case "me" -> config.getMeCommand(source, input); default -> input; - }); + }; }; } diff --git a/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java index b5dc3d6..5b110b6 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/PlayerAdvancementTrackerMixin.java @@ -15,7 +15,7 @@ public class PlayerAdvancementTrackerMixin { @Shadow private ServerPlayerEntity owner; - @ModifyArg(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")) + @ModifyArg(method = "method_53637", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")) private Text styledChat_changeAdvancementMessage(Text text) { var translatableText = (TranslatableTextContent) text.getContent(); Text advancement = (Text) translatableText.getArgs()[1]; diff --git a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java index a4f44f5..a5dd041 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java @@ -9,6 +9,7 @@ import net.minecraft.network.message.SignedMessage; import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ConnectedClientData; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.Stats; import net.minecraft.text.Text; @@ -34,12 +35,12 @@ public class PlayerManagerMixin { private ServerPlayerEntity styledChat_temporaryPlayer = null; @Inject(method = "onPlayerConnect", at = @At(value = "HEAD")) - private void styledChat_storePlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { + private void styledChat_storePlayer(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) { this.styledChat_temporaryPlayer = player; } @Inject(method = "onPlayerConnect", at = @At("RETURN")) - private void styledChat_removeStoredPlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { + private void styledChat_removeStoredPlayer(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) { this.styledChat_temporaryPlayer = null; } diff --git a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java index 06f6f3b..bd3e1ac 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/ServerPlayNetworkManagerMixin.java @@ -7,10 +7,13 @@ import eu.pb4.styledchat.config.ConfigManager; import eu.pb4.styledchat.ducks.ExtPlayNetworkHandler; import eu.pb4.styledchat.StyledChatUtils; +import net.minecraft.network.ClientConnection; 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.ClientSettingsC2SPacket; +import net.minecraft.network.packet.c2s.common.ClientOptionsC2SPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ConnectedClientData; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.*; @@ -31,20 +34,18 @@ public abstract class ServerPlayNetworkManagerMixin implements ExtPlayNetworkHan @Unique private ChatStyle styledChat$style; - @Unique - private boolean styledChat$chatColors = true; - @ModifyArg(method = "onDisconnected", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")) + @ModifyArg(method = "cleanUp", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")) private Text styledChat_replaceDisconnectMessage(Text text) { return StyledChatStyles.getLeft(this.player); } - @Redirect(method = "method_44900", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageDecorator;decorate(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/text/Text;)Ljava/util/concurrent/CompletableFuture;")) - private CompletableFuture styledChat_replaceDecorator2(MessageDecorator instance, ServerPlayerEntity player, Text text) { + @Redirect(method = "method_44900", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageDecorator;decorate(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/text/Text;)Lnet/minecraft/text/Text;")) + private Text styledChat_replaceDecorator2(MessageDecorator instance, ServerPlayerEntity player, Text text) { if (player != null) { - return CompletableFuture.completedFuture(StyledChatUtils.formatFor(PlaceholderContext.of(player), text.getString())); + return StyledChatUtils.formatFor(PlaceholderContext.of(player), text.getString()); } else { - return CompletableFuture.completedFuture(StyledChatUtils.formatFor(PlaceholderContext.of(StyledChatMod.server), text.getString())); + return StyledChatUtils.formatFor(PlaceholderContext.of(StyledChatMod.server), text.getString()); } } @@ -53,11 +54,6 @@ private void styledChat_setFormattedMessage(SignedMessage signedMessage, Callbac StyledChatUtils.modifyForSending(signedMessage, this.player.getCommandSource(), MessageType.CHAT); } - @Inject(method = "onClientSettings", at = @At("TAIL")) - private void styledChat_setFormattedMessage(ClientSettingsC2SPacket packet, CallbackInfo ci) { - this.styledChat$chatColors = packet.chatColors(); - } - @Override public ChatStyle styledChat$getStyle() { if (this.styledChat$style == null) { @@ -73,6 +69,6 @@ private void styledChat_setFormattedMessage(ClientSettingsC2SPacket packet, Call @Override public boolean styledChat$chatColors() { - return this.styledChat$chatColors || !ConfigManager.getConfig().configData.formatting.respectColors; + return this.player.areClientChatColorsEnabled() || !ConfigManager.getConfig().configData.formatting.respectColors; } } diff --git a/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java b/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java index 5eb4976..3c97442 100644 --- a/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java +++ b/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java @@ -32,7 +32,7 @@ public interface StyledChatSentMessage extends SentMessage, ExtendedSentMessage } record Chat(SignedMessage message, Text override, MessageType.Parameters parameters, RegistryKey sourceType, MutableObject colorless) implements StyledChatSentMessage { - public Text getContent() { + public Text content() { return message.unsignedContent(); } @@ -74,7 +74,7 @@ public StyledChatSentMessage reformat(MessageType.Parameters pars, RegistryKey sourceType, MutableObject colorless) implements StyledChatSentMessage { - public Text getContent() { + public Text content() { return this.message.unsignedContent(); }