Fix null input on FormattedText

This commit is contained in:
Vankka 2024-08-30 23:11:40 +03:00
parent 99912dc937
commit 99ac8ac130
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
5 changed files with 15 additions and 5 deletions

View File

@ -23,16 +23,26 @@
package com.discordsrv.api.placeholder.format;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents content that doesn't need to be processed for the purposes of DiscordSRV's processing.
*/
public class FormattedText implements CharSequence {
@Contract(value = "null -> null; !null -> new", pure = true)
public static FormattedText of(@Nullable CharSequence text) {
if (text == null) {
return null;
}
return new FormattedText(text);
}
private final CharSequence text;
public FormattedText(CharSequence text) {
private FormattedText(@NotNull CharSequence text) {
this.text = text;
}

View File

@ -49,7 +49,7 @@ public class ComponentResultStringifier implements PlaceholderResultMapper {
case PLAIN:
return discordSRV.componentFactory().plainSerializer().serialize(component);
case DISCORD:
return new FormattedText(discordSRV.componentFactory().discordSerialize(component));
return FormattedText.of(discordSRV.componentFactory().discordSerialize(component));
case ANSI:
return discordSRV.componentFactory().ansiSerializer().serialize(component);
case LEGACY:

View File

@ -197,6 +197,6 @@ public class DiscordInviteModule extends AbstractModule<DiscordSRV> {
@Placeholder("discord_invite")
public CharSequence getInvite() {
return new FormattedText(invite != null ? invite : UNKNOWN_INVITE);
return FormattedText.of(invite != null ? invite : UNKNOWN_INVITE);
}
}

View File

@ -177,7 +177,7 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
}
String finalMessage = messagePlaceholders.toString();
return new FormattedText(preventEveryoneMentions(everyoneMentionAllowed, finalMessage));
return FormattedText.of(preventEveryoneMentions(everyoneMentionAllowed, finalMessage));
})
.applyPlaceholderService()
.build();

View File

@ -50,7 +50,7 @@ public final class GamePermissionUtil {
}
String data = meta.getMeta(uuid, metaKey).join();
return new FormattedText(data);
return FormattedText.of(data);
}
public static Component getPrefix(DiscordSRV discordSRV, UUID uuid) {