mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-11 00:52:50 +01:00
Fix null input on FormattedText
This commit is contained in:
parent
99912dc937
commit
99ac8ac130
@ -23,16 +23,26 @@
|
|||||||
|
|
||||||
package com.discordsrv.api.placeholder.format;
|
package com.discordsrv.api.placeholder.format;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.
|
* Represents content that doesn't need to be processed for the purposes of DiscordSRV's processing.
|
||||||
*/
|
*/
|
||||||
public class FormattedText implements CharSequence {
|
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;
|
private final CharSequence text;
|
||||||
|
|
||||||
public FormattedText(CharSequence text) {
|
private FormattedText(@NotNull CharSequence text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class ComponentResultStringifier implements PlaceholderResultMapper {
|
|||||||
case PLAIN:
|
case PLAIN:
|
||||||
return discordSRV.componentFactory().plainSerializer().serialize(component);
|
return discordSRV.componentFactory().plainSerializer().serialize(component);
|
||||||
case DISCORD:
|
case DISCORD:
|
||||||
return new FormattedText(discordSRV.componentFactory().discordSerialize(component));
|
return FormattedText.of(discordSRV.componentFactory().discordSerialize(component));
|
||||||
case ANSI:
|
case ANSI:
|
||||||
return discordSRV.componentFactory().ansiSerializer().serialize(component);
|
return discordSRV.componentFactory().ansiSerializer().serialize(component);
|
||||||
case LEGACY:
|
case LEGACY:
|
||||||
|
@ -197,6 +197,6 @@ public class DiscordInviteModule extends AbstractModule<DiscordSRV> {
|
|||||||
|
|
||||||
@Placeholder("discord_invite")
|
@Placeholder("discord_invite")
|
||||||
public CharSequence getInvite() {
|
public CharSequence getInvite() {
|
||||||
return new FormattedText(invite != null ? invite : UNKNOWN_INVITE);
|
return FormattedText.of(invite != null ? invite : UNKNOWN_INVITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
|
|||||||
}
|
}
|
||||||
|
|
||||||
String finalMessage = messagePlaceholders.toString();
|
String finalMessage = messagePlaceholders.toString();
|
||||||
return new FormattedText(preventEveryoneMentions(everyoneMentionAllowed, finalMessage));
|
return FormattedText.of(preventEveryoneMentions(everyoneMentionAllowed, finalMessage));
|
||||||
})
|
})
|
||||||
.applyPlaceholderService()
|
.applyPlaceholderService()
|
||||||
.build();
|
.build();
|
||||||
|
@ -50,7 +50,7 @@ public final class GamePermissionUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String data = meta.getMeta(uuid, metaKey).join();
|
String data = meta.getMeta(uuid, metaKey).join();
|
||||||
return new FormattedText(data);
|
return FormattedText.of(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component getPrefix(DiscordSRV discordSRV, UUID uuid) {
|
public static Component getPrefix(DiscordSRV discordSRV, UUID uuid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user