Tweak some stuff relating to FormattedText, make invite not get escaped, ever

This commit is contained in:
Vankka 2022-04-12 13:18:56 +03:00
parent ad7bca010f
commit eba37d9b6f
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
4 changed files with 12 additions and 11 deletions

View File

@ -226,7 +226,7 @@ public class SendableDiscordMessageImpl implements SendableDiscordMessage {
throw new IllegalStateException("DiscordSRVApi not available"); throw new IllegalStateException("DiscordSRVApi not available");
} }
this.replacements.put(PlaceholderService.PATTERN, this.replacements.put(PlaceholderService.PATTERN,
wrapFunction(matcher -> api.placeholderService().getResultAsString(matcher, context))); wrapFunction(matcher -> api.placeholderService().getResultAsPlain(matcher, context)));
return this; return this;
} }

View File

@ -52,6 +52,6 @@ public interface PlaceholderService {
PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Object... context); PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Object... context);
Object getResult(@NotNull Matcher matcher, @NotNull Set<Object> context); Object getResult(@NotNull Matcher matcher, @NotNull Set<Object> context);
CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context); CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set<Object> context);
} }

View File

@ -18,6 +18,7 @@
package com.discordsrv.common.invite; package com.discordsrv.common.invite;
import com.discordsrv.api.placeholder.FormattedText;
import com.discordsrv.api.placeholder.annotation.Placeholder; import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.main.DiscordInviteConfig; import com.discordsrv.common.config.main.DiscordInviteConfig;
@ -92,7 +93,7 @@ public class DiscordInviteModule extends AbstractModule<DiscordSRV> {
} }
@Placeholder("discord_invite") @Placeholder("discord_invite")
public String getInvite() { public CharSequence getInvite() {
return invite != null ? invite : UNKNOWN_INVITE; return new FormattedText(invite != null ? invite : UNKNOWN_INVITE);
} }
} }

View File

@ -175,16 +175,16 @@ public class PlaceholderServiceImpl implements PlaceholderService {
} }
@Override @Override
public CharSequence getResultAsString(@NotNull Matcher matcher, @NotNull Set<Object> context) { public CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set<Object> context) {
Object result = getResult(matcher, 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) { if (result == null) {
return ""; return "";
} else if (result instanceof CharSequence) { } else if (result instanceof CharSequence) {
return result.toString(); return (CharSequence) result;
} }
Object output = null; Object output = null;
@ -213,7 +213,7 @@ public class PlaceholderServiceImpl implements PlaceholderService {
private String updateContent(List<PlaceholderLookupResult> results, String placeholder, Matcher matcher, String input) { private String updateContent(List<PlaceholderLookupResult> results, String placeholder, Matcher matcher, String input) {
Object representation = getResultRepresentation(results, placeholder, matcher); Object representation = getResultRepresentation(results, placeholder, matcher);
CharSequence output = getResultAsString(representation); CharSequence output = getResultAsPlain(representation);
if (output == null) { if (output == null) {
output = String.valueOf(representation); output = String.valueOf(representation);
} }
@ -241,9 +241,9 @@ public class PlaceholderServiceImpl implements PlaceholderService {
case SUCCESS: case SUCCESS:
replacement = result.getValue(); replacement = result.getValue();
if (replacement == null) { if (replacement == null) {
replacement = getResultAsString(null); replacement = getResultAsPlain(null);
} }
if (StringUtils.isNotBlank(getResultAsString(replacement))) { if (StringUtils.isNotBlank(getResultAsPlain(replacement))) {
return replacement; return replacement;
} }
break; break;