mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-25 12:25:15 +01:00
Add legacy section parsing for prefix/suffix
This commit is contained in:
parent
cb5392fb81
commit
3c3977200f
@ -40,5 +40,12 @@ public interface MinecraftComponentFactory {
|
||||
@NotNull
|
||||
MinecraftComponent empty();
|
||||
|
||||
GameTextBuilder textBuilder(String content);
|
||||
/**
|
||||
* Creates a EnhancedLegacyText {@link GameTextBuilder} based on the given input.
|
||||
* @param enhancedLegacyText the format
|
||||
* @return the new builder
|
||||
*/
|
||||
@NotNull
|
||||
GameTextBuilder textBuilder(@NotNull String enhancedLegacyText);
|
||||
|
||||
}
|
||||
|
@ -25,13 +25,16 @@ import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.component.renderer.DiscordSRVMinecraftRenderer;
|
||||
import com.discordsrv.common.component.translation.Translation;
|
||||
import com.discordsrv.common.component.translation.TranslationRegistry;
|
||||
import dev.vankka.enhancedlegacytext.EnhancedLegacyText;
|
||||
import dev.vankka.mcdiscordreserializer.discord.DiscordSerializer;
|
||||
import dev.vankka.mcdiscordreserializer.discord.DiscordSerializerOptions;
|
||||
import dev.vankka.mcdiscordreserializer.minecraft.MinecraftSerializer;
|
||||
import dev.vankka.mcdiscordreserializer.minecraft.MinecraftSerializerOptions;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||
import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.ansi.ColorLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -103,8 +106,16 @@ public class ComponentFactory implements MinecraftComponentFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameTextBuilder textBuilder(String content) {
|
||||
return new EnhancedTextBuilderImpl(discordSRV, content);
|
||||
public @NotNull GameTextBuilder textBuilder(@NotNull String enhancedLegacyText) {
|
||||
return new EnhancedTextBuilderImpl(discordSRV, enhancedLegacyText);
|
||||
}
|
||||
|
||||
public @NotNull Component parse(@NotNull String textInput) {
|
||||
if (textInput.contains(String.valueOf(LegacyComponentSerializer.SECTION_CHAR))) {
|
||||
return LegacyComponentSerializer.legacySection().deserialize(textInput);
|
||||
}
|
||||
|
||||
return EnhancedLegacyText.get().parse(textInput);
|
||||
}
|
||||
|
||||
public MinecraftSerializer minecraftSerializer() {
|
||||
|
@ -20,7 +20,6 @@ package com.discordsrv.common.permission.util;
|
||||
|
||||
import com.discordsrv.api.module.type.PermissionDataProvider;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.component.util.ComponentUtil;
|
||||
import com.discordsrv.common.exception.MessageException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@ -88,6 +87,6 @@ public final class PermissionUtil {
|
||||
}
|
||||
|
||||
private static Component translate(DiscordSRV discordSRV, String data) {
|
||||
return data != null ? ComponentUtil.fromAPI(discordSRV.componentFactory().textBuilder(data).build()) : null;
|
||||
return data != null ? discordSRV.componentFactory().parse(data) : null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user