diff --git a/api/src/main/java/com/discordsrv/api/placeholder/PlaceholderService.java b/api/src/main/java/com/discordsrv/api/placeholder/PlaceholderService.java index 894308b3..df78690b 100644 --- a/api/src/main/java/com/discordsrv/api/placeholder/PlaceholderService.java +++ b/api/src/main/java/com/discordsrv/api/placeholder/PlaceholderService.java @@ -52,6 +52,6 @@ public interface PlaceholderService { PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Object... context); Object getResult(@NotNull Matcher matcher, @NotNull Set context); - String getResultAsString(@NotNull Matcher matcher, @NotNull Set context); + CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set context); } diff --git a/common/build.gradle b/common/build.gradle index a4a074cc..a4b61673 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -63,7 +63,7 @@ dependencies { runtimeDownloadApi 'net.kyori:adventure-text-serializer-plain:' + rootProject.adventureVersion runtimeDownloadApi 'net.kyori:adventure-text-serializer-legacy:' + rootProject.adventureVersion runtimeDownloadApi 'net.kyori:adventure-text-serializer-gson:' + rootProject.adventureVersion - runtimeDownloadApi 'dev.vankka:mcdiscordreserializer:4.2.4-SNAPSHOT' + runtimeDownloadApi 'dev.vankka:mcdiscordreserializer:4.3.0' runtimeDownloadApi 'dev.vankka:enhancedlegacytext:1.0.0-SNAPSHOT' // Brigadier diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java index 9161d441..a955ea9d 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java @@ -25,7 +25,6 @@ import com.discordsrv.api.discord.api.entity.channel.DiscordThreadChannel; import com.discordsrv.api.discord.api.entity.message.ReceivedDiscordMessage; import com.discordsrv.api.discord.api.entity.message.ReceivedDiscordMessageCluster; import com.discordsrv.api.discord.api.entity.message.SendableDiscordMessage; -import com.discordsrv.api.discord.api.util.DiscordFormattingUtil; import com.discordsrv.api.event.events.message.receive.game.AbstractGameMessageReceiveEvent; import com.discordsrv.api.placeholder.FormattedText; import com.discordsrv.api.player.DiscordSRVPlayer; @@ -168,9 +167,7 @@ public abstract class AbstractGameMessageModule config, Component component) { - return DiscordFormattingUtil.escapeContent( - discordSRV.componentFactory().discordSerializer().serialize(component) - ); + return discordSRV.componentFactory().discordSerializer().serialize(component); } public Map, DiscordMessageChannel> sendMessageToChannels( diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/MinecraftToDiscordChatModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/MinecraftToDiscordChatModule.java index c23840aa..5976102f 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/MinecraftToDiscordChatModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/MinecraftToDiscordChatModule.java @@ -37,6 +37,7 @@ import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.config.main.channels.MinecraftToDiscordChatConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.function.OrDefault; +import dev.vankka.mcdiscordreserializer.discord.DiscordSerializer; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.GuildChannel; import net.dv8tion.jda.api.entities.Member; @@ -98,7 +99,10 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule config, Component component) { - Placeholders messagePlaceholders = new Placeholders(discordSRV.componentFactory().discordSerializer().serialize(component)); + DiscordSerializer discordSerializer = discordSRV.componentFactory().discordSerializer(); + String content = discordSerializer.serialize(component, discordSerializer.getDefaultOptions().withEscapeMarkdown(false)); + + Placeholders messagePlaceholders = new Placeholders(content); config.opt(cfg -> cfg.contentRegexFilters) .ifPresent(patterns -> patterns.forEach(messagePlaceholders::replaceAll)); diff --git a/common/src/main/java/com/discordsrv/common/placeholder/PlaceholderServiceImpl.java b/common/src/main/java/com/discordsrv/common/placeholder/PlaceholderServiceImpl.java index 3568e984..0af28146 100644 --- a/common/src/main/java/com/discordsrv/common/placeholder/PlaceholderServiceImpl.java +++ b/common/src/main/java/com/discordsrv/common/placeholder/PlaceholderServiceImpl.java @@ -175,12 +175,12 @@ public class PlaceholderServiceImpl implements PlaceholderService { } @Override - public String getResultAsString(@NotNull Matcher matcher, @NotNull Set context) { + public CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set context) { Object result = getResult(matcher, context); return getResultAsString(result); } - private String getResultAsString(Object result) { + private CharSequence getResultAsString(Object result) { if (result == null) { return ""; } else if (result instanceof CharSequence) { @@ -195,7 +195,7 @@ public class PlaceholderServiceImpl implements PlaceholderService { } } - return String.valueOf(output != null ? output : result); + return output instanceof CharSequence ? (CharSequence) output : String.valueOf(output != null ? output : result); } private List resolve(String placeholder, Set context) { @@ -213,7 +213,7 @@ public class PlaceholderServiceImpl implements PlaceholderService { private String updateContent(List results, String placeholder, Matcher matcher, String input) { Object representation = getResultRepresentation(results, placeholder, matcher); - String output = getResultAsString(representation); + CharSequence output = getResultAsString(representation); if (output == null) { output = String.valueOf(representation); } @@ -223,7 +223,7 @@ public class PlaceholderServiceImpl implements PlaceholderService { Pattern.LITERAL ) .matcher(input) - .replaceFirst(output); + .replaceFirst(output instanceof String ? (String) output : output.toString()); } private Object getResultRepresentation(List results, String placeholder, Matcher matcher) { diff --git a/common/src/main/java/com/discordsrv/common/placeholder/result/ComponentResultStringifier.java b/common/src/main/java/com/discordsrv/common/placeholder/result/ComponentResultStringifier.java index 41360001..5400280e 100644 --- a/common/src/main/java/com/discordsrv/common/placeholder/result/ComponentResultStringifier.java +++ b/common/src/main/java/com/discordsrv/common/placeholder/result/ComponentResultStringifier.java @@ -19,6 +19,7 @@ package com.discordsrv.common.placeholder.result; import com.discordsrv.api.component.MinecraftComponent; +import com.discordsrv.api.placeholder.FormattedText; import com.discordsrv.api.placeholder.mapper.PlaceholderResultMapper; import com.discordsrv.api.placeholder.mapper.ResultMappers; import com.discordsrv.common.DiscordSRV; @@ -36,7 +37,7 @@ public class ComponentResultStringifier implements PlaceholderResultMapper { } @Override - public String convertResult(@NotNull Object result) { + public CharSequence convertResult(@NotNull Object result) { if (result instanceof MinecraftComponent) { result = ComponentUtil.fromAPI((MinecraftComponent) result); } @@ -45,7 +46,7 @@ public class ComponentResultStringifier implements PlaceholderResultMapper { if (ResultMappers.isPlainContext()) { return PlainTextComponentSerializer.plainText().serialize(component); } else { - return discordSRV.componentFactory().discordSerializer().serialize(component); + return new FormattedText(discordSRV.componentFactory().discordSerializer().serialize(component)); } } return null;