mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-28 17:37:52 +01:00
Tweak some stuff relating to FormattedText, make invite not get escaped, ever
This commit is contained in:
parent
ad7bca010f
commit
eba37d9b6f
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user