mirror of
https://github.com/plexusorg/Plex.git
synced 2025-06-28 22:46:40 +00:00
Add getting text from component to PlexUtils
This commit is contained in:
@ -13,6 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
@ -166,6 +167,40 @@ public class PlexUtils implements PlexBase
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
public static String getTextFromComponent(Component component)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((TextComponent)component).content();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PlexLog.warn("Unable to get text of component", e.getLocalizedMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTextFromComponents(Component... components)
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (Component component : components)
|
||||
{
|
||||
builder.append(getTextFromComponent(component));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PlexLog.warn("Unable to get text of components", e.getLocalizedMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNameList()
|
||||
{
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
|
Reference in New Issue
Block a user