From d84e4c87dcbe642128601cb7c2c5a43b71b9d585 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 14 Feb 2024 19:55:56 +0100 Subject: [PATCH] Use ComponentLike instead of Component or Chat in some places --- .../src/main/java/fr/pandacube/lib/chat/Chat.java | 2 +- .../main/java/fr/pandacube/lib/chat/ChatStatic.java | 2 +- .../main/java/fr/pandacube/lib/chat/ChatTreeNode.java | 11 +++++++---- .../src/main/java/fr/pandacube/lib/chat/ChatUtil.java | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/Chat.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/Chat.java index 0d7cb4e..db10974 100644 --- a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/Chat.java +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/Chat.java @@ -288,7 +288,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @param comp the component. * @return this. */ - public Chat thenPlayerName(Component comp) { return then(playerNameComponent(comp)); } + public Chat thenPlayerName(ComponentLike comp) { return then(playerNameComponent(comp)); } /** * Appends a component consisting of a new line. diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatStatic.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatStatic.java index 1516bc8..e65c2d4 100644 --- a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatStatic.java +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatStatic.java @@ -248,7 +248,7 @@ public abstract class ChatStatic { * @param c the {@link Component}. * @return a new {@link FormatableChat}. */ - public static FormatableChat playerNameComponent(Component c) { + public static FormatableChat playerNameComponent(ComponentLike c) { FormatableChat fc = chatComponent(c); fc.builder.colorIfAbsent(NamedTextColor.WHITE); return fc; diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatTreeNode.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatTreeNode.java index ca0df66..990135f 100644 --- a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatTreeNode.java +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatTreeNode.java @@ -1,10 +1,13 @@ package fr.pandacube.lib.chat; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; + import java.util.ArrayList; import java.util.List; /** - * A tree structure of {@link Chat} component intended to be rendered in chat using {@link #render(boolean)}. + * A tree structure of chat {@link Component} intended to be rendered in chat using {@link #render(boolean)}. */ public class ChatTreeNode { @@ -19,7 +22,7 @@ public class ChatTreeNode { /** * The component for the current node. */ - public final Chat component; + public final ComponentLike component; /** * Children nodes. @@ -30,7 +33,7 @@ public class ChatTreeNode { * Construct a new {@link ChatTreeNode}. * @param cmp the component for the current node. */ - public ChatTreeNode(Chat cmp) { + public ChatTreeNode(ComponentLike cmp) { component = cmp; } @@ -50,7 +53,7 @@ public class ChatTreeNode { * Each element in the returned list represent 1 line of this tree view. * Thus, the caller may send each line separately or at once, depending on the quantity of data. * @param console true to render for console, false otherwise. - * @return an array of component, each element being a single line. + * @return a list of component, each element being a single line. */ public List render(boolean console) { List ret = new ArrayList<>(); diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatUtil.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatUtil.java index 2b12169..292341e 100644 --- a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatUtil.java +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatUtil.java @@ -432,12 +432,12 @@ public class ChatUtil { * alignment, much harder). * @return a List containing each rendered line of the table. */ - public static List renderTable(List> data, String space, boolean console) { + public static List renderTable(List> data, String space, boolean console) { List> compRows = new ArrayList<>(data.size()); - for (List row : data) { + for (List row : data) { List compRow = new ArrayList<>(row.size()); - for (Chat c : row) { - compRow.add(c.getAdv()); + for (ComponentLike c : row) { + compRow.add(c.asComponent()); } compRows.add(compRow); }