mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Add getting text from component to PlexUtils
This commit is contained in:
parent
d716f77ac0
commit
3604add18a
@ -60,7 +60,8 @@ public class ChatListener extends PlexListener
|
||||
@Override
|
||||
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
|
||||
{
|
||||
String text = ((TextComponent)message).content();
|
||||
String text = PlexUtils.getTextFromComponent(message);
|
||||
|
||||
Component component = Component.empty();
|
||||
|
||||
if (hasPrefix)
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user