mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-26 12:35:20 +01:00
Update MCDiscordReserializer, change some stuff regarding escaping
This commit is contained in:
parent
9e6e2cb22c
commit
02a0d098d0
@ -52,6 +52,6 @@ public interface PlaceholderService {
|
||||
PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Object... context);
|
||||
|
||||
Object getResult(@NotNull Matcher matcher, @NotNull Set<Object> context);
|
||||
String getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context);
|
||||
CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context);
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<T extends IMessageConfig, E exte
|
||||
}
|
||||
|
||||
public String convertMessage(OrDefault<T> config, Component component) {
|
||||
return DiscordFormattingUtil.escapeContent(
|
||||
discordSRV.componentFactory().discordSerializer().serialize(component)
|
||||
);
|
||||
return discordSRV.componentFactory().discordSerializer().serialize(component);
|
||||
}
|
||||
|
||||
public Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> sendMessageToChannels(
|
||||
|
@ -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<Mine
|
||||
|
||||
@Override
|
||||
public String convertMessage(OrDefault<MinecraftToDiscordChatConfig> 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));
|
||||
|
||||
|
@ -175,12 +175,12 @@ public class PlaceholderServiceImpl implements PlaceholderService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context) {
|
||||
public CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> 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<PlaceholderLookupResult> resolve(String placeholder, Set<Object> context) {
|
||||
@ -213,7 +213,7 @@ public class PlaceholderServiceImpl implements PlaceholderService {
|
||||
private String updateContent(List<PlaceholderLookupResult> 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<PlaceholderLookupResult> results, String placeholder, Matcher matcher) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user