diff --git a/README.md b/README.md index 9532901..0f5e20d 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,7 @@ Additionally, you can enable markdown and legacy (&X) formatting in the config "dark_aqua": true }, "emoticons": { + "$emojibase:builtin:joypixels": "${emoji}", "potion": "๐Ÿงช", "trident": "๐Ÿ”ฑ", "rod": "๐ŸŽฃ", diff --git a/gradle.properties b/gradle.properties index 1f726f3..5a48493 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_version=0.83.0+1.20.1 # Mod Properties - mod_version = 2.2.1+1.20.1 + mod_version = 2.2.2+1.20.1 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 4dacb64..6acfe22 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -413,6 +413,7 @@ public static Text formatFor(ServerCommandSource source, String original) { } } + @Deprecated public static SignedMessage toEventMessage(SignedMessage message, PlaceholderContext context) { var ext = (ExtSignedMessage) (Object) message; diff --git a/src/main/java/eu/pb4/styledchat/mixin/SentMessageMixin.java b/src/main/java/eu/pb4/styledchat/mixin/SentMessageMixin.java index cc48bdc..f116bd8 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/SentMessageMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/SentMessageMixin.java @@ -3,11 +3,15 @@ import eu.pb4.styledchat.StyledChatMod; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.ducks.ExtSignedMessage; +import eu.pb4.styledchat.other.ExtendedSentMessage; import eu.pb4.styledchat.other.StyledChatSentMessage; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SentMessage; import net.minecraft.network.message.SignedMessage; +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.CallbackInfoReturnable; @@ -27,4 +31,38 @@ public interface SentMessageMixin { } } } + + @Inject(method = "of", at = @At("RETURN"), cancellable = true) + private static void styledChat$forceAttach(SignedMessage message, CallbackInfoReturnable cir) { + if (cir.getReturnValue() instanceof SentMessage.Profileless) { + ((ExtendedSentMessage) cir.getReturnValue()).styledChat$setMessage(message); + } + } + + @Mixin(SentMessage.Chat.class) + class ChatMixin implements ExtendedSentMessage { + + @Shadow @Final private SignedMessage message; + + @Override + public SignedMessage styledChat$message() { + return this.message; + } + } + + @Mixin(SentMessage.Profileless.class) + class ProfilelessMixin implements ExtendedSentMessage { + @Unique + private SignedMessage styledChat$message; + + @Override + public SignedMessage styledChat$message() { + return this.styledChat$message; + } + + @Override + public void styledChat$setMessage(SignedMessage value) { + styledChat$message = value; + } + } } diff --git a/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java index 3d0bdf1..5913b82 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java @@ -5,6 +5,7 @@ import eu.pb4.styledchat.ducks.ExtSignedMessage; import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; +import eu.pb4.styledchat.other.ExtendedSentMessage; import eu.pb4.styledchat.other.StyledChatSentMessage; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SentMessage; @@ -33,26 +34,26 @@ private static void styledChat_noopFeedback(ServerCommandSource instance, SentMe // noop } - @Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendChatMessage(Lnet/minecraft/network/message/SentMessage;ZLnet/minecraft/network/message/MessageType$Parameters;)V")) + @Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendChatMessage(Lnet/minecraft/network/message/SentMessage;ZLnet/minecraft/network/message/MessageType$Parameters;)V")) private static void styledChat_formatText(ServerPlayerEntity instance, SentMessage message, boolean bl, MessageType.Parameters parameters, ServerCommandSource source) { - if (message instanceof StyledChatSentMessage styledChatSentMessage) { + if (message instanceof ExtendedSentMessage extSentMessage) { try { var sent = StyledChatMod.getMessageType().params(StyledChatStyles.getPrivateMessageSent( source.getDisplayName(), instance.getDisplayName(), - ExtSignedMessage.getArg(styledChatSentMessage.message(), "base_input"), instance.getCommandSource() + ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), instance.getCommandSource() )); - source.sendChatMessage(styledChatSentMessage.reformat(sent, MessageType.MSG_COMMAND_OUTGOING), bl, sent); + source.sendChatMessage(message, bl, sent); var rex = StyledChatMod.getMessageType().params(StyledChatStyles.getPrivateMessageReceived( source.getDisplayName(), instance.getDisplayName(), - ExtSignedMessage.getArg(styledChatSentMessage.message(), "base_input"), source + ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), source )); - instance.sendChatMessage(styledChatSentMessage.reformat(rex, MessageType.TEAM_MSG_COMMAND_INCOMING), bl, rex); + instance.sendChatMessage(message, bl, rex); return; } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java index 8200aa7..bcda3c8 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java @@ -3,9 +3,8 @@ import eu.pb4.styledchat.StyledChatMod; import eu.pb4.styledchat.StyledChatStyles; import eu.pb4.styledchat.StyledChatUtils; -import eu.pb4.styledchat.config.ConfigManager; import eu.pb4.styledchat.ducks.ExtSignedMessage; -import eu.pb4.styledchat.other.StyledChatSentMessage; +import eu.pb4.styledchat.other.ExtendedSentMessage; import net.minecraft.entity.Entity; import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SentMessage; @@ -36,24 +35,24 @@ private static void styledChat_formatOgText(ServerCommandSource serverCommandSou @Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendChatMessage(Lnet/minecraft/network/message/SentMessage;ZLnet/minecraft/network/message/MessageType$Parameters;)V")) private static void styledChat_replaceForSelf(ServerPlayerEntity instance, SentMessage message, boolean bl, MessageType.Parameters parameters, ServerCommandSource source) { - if (message instanceof StyledChatSentMessage styledChatSentMessage) { + if (message instanceof ExtendedSentMessage extSentMessage) { try { if (source.getPlayer() == instance) { var sent = StyledChatMod.getMessageType().params(StyledChatStyles.getTeamChatSent( ((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), source.getDisplayName(), - ExtSignedMessage.getArg(styledChatSentMessage.message(), "base_input"), instance.getCommandSource() + ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), instance.getCommandSource() )); - source.sendChatMessage(styledChatSentMessage.reformat(sent, MessageType.TEAM_MSG_COMMAND_OUTGOING), bl, sent); + source.sendChatMessage(message, bl, sent); } else { var rex = StyledChatMod.getMessageType().params(StyledChatStyles.getTeamChatReceived( ((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), source.getDisplayName(), - ExtSignedMessage.getArg(styledChatSentMessage.message(), "base_input"), source + ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), source )); - instance.sendChatMessage(styledChatSentMessage.reformat(rex, MessageType.TEAM_MSG_COMMAND_INCOMING), bl, rex); + instance.sendChatMessage(message, bl, rex); } return; } catch (Exception e) { diff --git a/src/main/java/eu/pb4/styledchat/other/ExtendedSentMessage.java b/src/main/java/eu/pb4/styledchat/other/ExtendedSentMessage.java new file mode 100644 index 0000000..05af7d8 --- /dev/null +++ b/src/main/java/eu/pb4/styledchat/other/ExtendedSentMessage.java @@ -0,0 +1,8 @@ +package eu.pb4.styledchat.other; + +import net.minecraft.network.message.SignedMessage; + +public interface ExtendedSentMessage { + SignedMessage styledChat$message(); + default void styledChat$setMessage(SignedMessage value) {}; +} diff --git a/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java b/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java index fd28706..2b67d26 100644 --- a/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java +++ b/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java @@ -15,7 +15,7 @@ import java.util.Objects; -public interface StyledChatSentMessage extends SentMessage { +public interface StyledChatSentMessage extends SentMessage, ExtendedSentMessage { Text override(); SignedMessage message(); @@ -24,8 +24,12 @@ public interface StyledChatSentMessage extends SentMessage { RegistryKey sourceType(); - record Chat(SignedMessage message, Text override, MessageType.Parameters parameters, RegistryKey sourceType) implements StyledChatSentMessage { + @Override + default SignedMessage styledChat$message() { + return this.message(); + } + record Chat(SignedMessage message, Text override, MessageType.Parameters parameters, RegistryKey sourceType) implements StyledChatSentMessage { public Text getContent() { return message.unsignedContent(); } diff --git a/src/main/resources/styledchat.mixins.json b/src/main/resources/styledchat.mixins.json index 46079e9..e9ea96a 100644 --- a/src/main/resources/styledchat.mixins.json +++ b/src/main/resources/styledchat.mixins.json @@ -4,7 +4,6 @@ "package": "eu.pb4.styledchat.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "RegistryLoaderMixin", "CommandManagerMixin", "MessageArgumentTypeMixin", "MessageFormatMixin", @@ -12,7 +11,10 @@ "PlayerAdvancementTrackerMixin", "PlayerEntityMixin", "PlayerManagerMixin", + "RegistryLoaderMixin", "SentMessageMixin", + "SentMessageMixin$ChatMixin", + "SentMessageMixin$ProfilelessMixin", "ServerPlayerEntityMixin", "ServerPlayNetworkManagerMixin", "SignedMessageMixin",