From eba37d9b6fa663546fe0b81bd9b3ab42f29e9b48 Mon Sep 17 00:00:00 2001 From: Vankka Date: Tue, 12 Apr 2022 13:18:56 +0300 Subject: [PATCH] Tweak some stuff relating to FormattedText, make invite not get escaped, ever --- .../message/impl/SendableDiscordMessageImpl.java | 2 +- .../api/placeholder/PlaceholderService.java | 2 +- .../common/invite/DiscordInviteModule.java | 5 +++-- .../common/placeholder/PlaceholderServiceImpl.java | 14 +++++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/com/discordsrv/api/discord/api/entity/message/impl/SendableDiscordMessageImpl.java b/api/src/main/java/com/discordsrv/api/discord/api/entity/message/impl/SendableDiscordMessageImpl.java index b7e2b6b6..f97410f0 100644 --- a/api/src/main/java/com/discordsrv/api/discord/api/entity/message/impl/SendableDiscordMessageImpl.java +++ b/api/src/main/java/com/discordsrv/api/discord/api/entity/message/impl/SendableDiscordMessageImpl.java @@ -226,7 +226,7 @@ public class SendableDiscordMessageImpl implements SendableDiscordMessage { throw new IllegalStateException("DiscordSRVApi not available"); } this.replacements.put(PlaceholderService.PATTERN, - wrapFunction(matcher -> api.placeholderService().getResultAsString(matcher, context))); + wrapFunction(matcher -> api.placeholderService().getResultAsPlain(matcher, context))); return this; } 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 df78690b..bd3511b6 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); - CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set context); + CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set context); } diff --git a/common/src/main/java/com/discordsrv/common/invite/DiscordInviteModule.java b/common/src/main/java/com/discordsrv/common/invite/DiscordInviteModule.java index a62496c5..c2d0ab3b 100644 --- a/common/src/main/java/com/discordsrv/common/invite/DiscordInviteModule.java +++ b/common/src/main/java/com/discordsrv/common/invite/DiscordInviteModule.java @@ -18,6 +18,7 @@ package com.discordsrv.common.invite; +import com.discordsrv.api.placeholder.FormattedText; import com.discordsrv.api.placeholder.annotation.Placeholder; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.config.main.DiscordInviteConfig; @@ -92,7 +93,7 @@ public class DiscordInviteModule extends AbstractModule { } @Placeholder("discord_invite") - public String getInvite() { - return invite != null ? invite : UNKNOWN_INVITE; + public CharSequence getInvite() { + return new FormattedText(invite != null ? invite : UNKNOWN_INVITE); } } 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 0af28146..2370eb07 100644 --- a/common/src/main/java/com/discordsrv/common/placeholder/PlaceholderServiceImpl.java +++ b/common/src/main/java/com/discordsrv/common/placeholder/PlaceholderServiceImpl.java @@ -175,16 +175,16 @@ public class PlaceholderServiceImpl implements PlaceholderService { } @Override - public CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set context) { + public CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set context) { Object result = getResult(matcher, context); - return getResultAsString(result); + return getResultAsPlain(result); } - private CharSequence getResultAsString(Object result) { + private CharSequence getResultAsPlain(Object result) { if (result == null) { return ""; } else if (result instanceof CharSequence) { - return result.toString(); + return (CharSequence) result; } Object output = null; @@ -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); - CharSequence output = getResultAsString(representation); + CharSequence output = getResultAsPlain(representation); if (output == null) { output = String.valueOf(representation); } @@ -241,9 +241,9 @@ public class PlaceholderServiceImpl implements PlaceholderService { case SUCCESS: replacement = result.getValue(); if (replacement == null) { - replacement = getResultAsString(null); + replacement = getResultAsPlain(null); } - if (StringUtils.isNotBlank(getResultAsString(replacement))) { + if (StringUtils.isNotBlank(getResultAsPlain(replacement))) { return replacement; } break;