From 36eb1227cf747ec06efda1d9855f98b171e17609 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 27 Jul 2024 23:49:40 +0200 Subject: [PATCH] Do not use bungeecord-chat as a dependency for pandalib-chat anymore --- pandalib-bungee-chat/.gitignore | 1 + pandalib-bungee-chat/pom.xml | 49 ++++++ .../pandacube/lib/bungee/chat/ChatBungee.java | 71 ++++++++ pandalib-bungee/pom.xml | 2 +- .../commands/BungeeBrigadierDispatcher.java | 4 +- .../bungee/players/BungeeOnlinePlayer.java | 6 +- pandalib-chat/pom.xml | 16 +- .../main/java/fr/pandacube/lib/chat/Chat.java | 154 +++--------------- .../fr/pandacube/lib/chat/ChatColorUtil.java | 78 +++------ .../fr/pandacube/lib/chat/ChatConfig.java | 2 +- .../fr/pandacube/lib/chat/ChatStatic.java | 24 +-- .../java/fr/pandacube/lib/chat/ChatUtil.java | 47 +++--- .../pandacube/lib/chat/LegacyChatFormat.java | 122 ++++++++++++++ .../lib/cli/commands/CommandAdmin.java | 4 +- pandalib-core/pom.xml | 6 + .../lib/core/backup/BackupCleaner.java | 10 +- .../lib/core/backup/BackupProcess.java | 12 +- .../core/backup/RotatedLogsBackupProcess.java | 8 +- pandalib-paper/pom.xml | 6 + .../pandacube/lib/paper/gui/GUIInventory.java | 2 +- .../modules/PerformanceAnalysisManager.java | 15 +- .../lib/paper/util/ItemStackBuilder.java | 4 +- .../lib/paper/util/ScoreboardUtil.java | 8 +- .../fr/pandacube/lib/paper/util/Skull.java | 8 +- pandalib-permissions/pom.xml | 6 + .../lib/permissions/PermissionsResolver.java | 36 ++-- pandalib-players/pom.xml | 11 +- pom.xml | 3 + 28 files changed, 402 insertions(+), 313 deletions(-) create mode 100644 pandalib-bungee-chat/.gitignore create mode 100644 pandalib-bungee-chat/pom.xml create mode 100644 pandalib-bungee-chat/src/main/java/fr/pandacube/lib/bungee/chat/ChatBungee.java create mode 100644 pandalib-chat/src/main/java/fr/pandacube/lib/chat/LegacyChatFormat.java diff --git a/pandalib-bungee-chat/.gitignore b/pandalib-bungee-chat/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/pandalib-bungee-chat/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/pandalib-bungee-chat/pom.xml b/pandalib-bungee-chat/pom.xml new file mode 100644 index 0000000..988e257 --- /dev/null +++ b/pandalib-bungee-chat/pom.xml @@ -0,0 +1,49 @@ + + + + pandalib-parent + fr.pandacube.lib + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + pandalib-bungee-chat + jar + + + + bungeecord-repo + https://oss.sonatype.org/content/repositories/snapshots + + + + + + fr.pandacube.lib + pandalib-util + ${project.version} + + + fr.pandacube.lib + pandalib-chat + ${project.version} + + + + net.md-5 + bungeecord-chat + ${bungeecord.version} + provided + + + + net.kyori + adventure-platform-bungeecord + 4.3.0 + + + + \ No newline at end of file diff --git a/pandalib-bungee-chat/src/main/java/fr/pandacube/lib/bungee/chat/ChatBungee.java b/pandalib-bungee-chat/src/main/java/fr/pandacube/lib/bungee/chat/ChatBungee.java new file mode 100644 index 0000000..b0aa1f8 --- /dev/null +++ b/pandalib-bungee-chat/src/main/java/fr/pandacube/lib/bungee/chat/ChatBungee.java @@ -0,0 +1,71 @@ +package fr.pandacube.lib.bungee.chat; + +import fr.pandacube.lib.chat.Chat; +import fr.pandacube.lib.chat.Chat.FormatableChat; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; +import net.md_5.bungee.api.chat.BaseComponent; + +public class ChatBungee { + + + + /** + * Creates a {@link FormatableChat} from the provided Bungee {@link BaseComponent}. + * @param c the {@link BaseComponent}. + * @return a new {@link FormatableChat}. + */ + public static FormatableChat chatComponent(BaseComponent c) { + return Chat.chatComponent(toAdventure(c)); + } + + + + /** + * Creates a {@link FormatableChat} from the provided Bungee {@link BaseComponent BaseComponent[]}. + * @param c the array of {@link BaseComponent}. + * @return a new {@link FormatableChat}. + */ + public static FormatableChat chatComponent(BaseComponent[] c) { + return Chat.chatComponent(toAdventure(c)); + } + + + + /** + * Converts the Bungee {@link BaseComponent} array into Adventure {@link Component}. + * @param components the Bungee {@link BaseComponent} array. + * @return a {@link Component}. + */ + public static Component toAdventure(BaseComponent[] components) { + return BungeeComponentSerializer.get().deserialize(components); + } + /** + * Converts the Bungee {@link BaseComponent} into Adventure {@link Component}. + * @param component the Bungee {@link BaseComponent}. + * @return a {@link Component}. + */ + public static Component toAdventure(BaseComponent component) { + return toAdventure(new BaseComponent[] { component }); + } + + /** + * Converts the Adventure {@link Component} into Bungee {@link BaseComponent} array. + * @param component the Adventure {@link Component}. + * @return a {@link BaseComponent} array. + */ + public static BaseComponent[] toBungeeArray(ComponentLike component) { + return BungeeComponentSerializer.get().serialize(component.asComponent()); + } + + /** + * Converts the Adventure {@link Component} into Bungee {@link BaseComponent}. + * @param component the Adventure {@link Component}. + * @return a {@link BaseComponent}. + */ + public static BaseComponent toBungee(ComponentLike component) { + BaseComponent[] arr = toBungeeArray(component); + return arr.length == 1 ? arr[0] : new net.md_5.bungee.api.chat.TextComponent(arr); + } +} diff --git a/pandalib-bungee/pom.xml b/pandalib-bungee/pom.xml index b18bdef..c6b6aa8 100644 --- a/pandalib-bungee/pom.xml +++ b/pandalib-bungee/pom.xml @@ -33,7 +33,7 @@ fr.pandacube.lib - pandalib-chat + pandalib-bungee-chat ${project.version} diff --git a/pandalib-bungee/src/main/java/fr/pandacube/lib/bungee/commands/BungeeBrigadierDispatcher.java b/pandalib-bungee/src/main/java/fr/pandacube/lib/bungee/commands/BungeeBrigadierDispatcher.java index f0cee97..47d0f1b 100644 --- a/pandalib-bungee/src/main/java/fr/pandacube/lib/bungee/commands/BungeeBrigadierDispatcher.java +++ b/pandalib-bungee/src/main/java/fr/pandacube/lib/bungee/commands/BungeeBrigadierDispatcher.java @@ -1,6 +1,6 @@ package fr.pandacube.lib.bungee.commands; -import fr.pandacube.lib.chat.Chat; +import fr.pandacube.lib.bungee.chat.ChatBungee; import fr.pandacube.lib.commands.BrigadierDispatcher; import net.kyori.adventure.text.ComponentLike; import net.md_5.bungee.api.CommandSender; @@ -71,6 +71,6 @@ public class BungeeBrigadierDispatcher extends BrigadierDispatcher net.kyori - adventure-platform-bungeecord - 4.3.0 + adventure-text-serializer-gson + 4.13.0 + + + net.kyori + adventure-text-serializer-legacy + 4.13.0 net.kyori @@ -46,13 +51,6 @@ - - net.md-5 - bungeecord-chat - ${bungeecord.version} - compile - - com.google.code.gson gson 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 4852985..7fc937c 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 @@ -16,15 +16,13 @@ import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration.State; import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.BaseComponent; import org.jetbrains.annotations.NotNull; import java.awt.*; +import java.util.Locale; import java.util.Objects; import java.util.function.Consumer; import java.util.function.UnaryOperator; @@ -67,26 +65,10 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * Builds the component into Adventure Component instance. * @return the {@link Component} built from this {@link Chat} component. */ - public Component getAdv() { + public Component get() { return builder.build(); } - /** - * Builds the component into BungeeCord {@link BaseComponent} instance. - * @return the {@link BaseComponent} built from this {@link Chat} component. - */ - public BaseComponent get() { - return toBungee(getAdv()); - } - - /** - * Builds the component into BungeeCord {@link BaseComponent} array. - * @return the {@link BaseComponent} array built from this {@link Chat} component. - */ - public BaseComponent[] getAsArray() { - return toBungeeArray(getAdv()); - } - private static final LegacyComponentSerializer LEGACY_SERIALIZER_BUNGEE_FRIENDLY = LegacyComponentSerializer.builder() .hexColors() .useUnusualXRepeatedCharacterHexFormat() @@ -97,7 +79,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @return the legacy text. RGB colors are in BungeeCord format. */ public String getLegacyText() { - return LEGACY_SERIALIZER_BUNGEE_FRIENDLY.serialize(getAdv()); + return LEGACY_SERIALIZER_BUNGEE_FRIENDLY.serialize(get()); } /** @@ -105,12 +87,12 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @return the plain text of this component. */ public String getPlainText() { - return PlainTextComponentSerializer.plainText().serializeOr(getAdv(), ""); + return PlainTextComponentSerializer.plainText().serializeOr(get(), ""); } @Override public @NotNull HoverEvent asHoverEvent(@NotNull UnaryOperator op) { - return HoverEvent.showText(op.apply(getAdv())); + return HoverEvent.showText(op.apply(get())); } /** @@ -119,7 +101,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource */ @Override public @NotNull Component asComponent() { - return getAdv(); + return get(); } /** @@ -127,7 +109,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @return the {@link Component} built from this {@link Chat} component, with down-sampled colors. */ public Component getAsDownSampledColorsComponent() { - String json = GsonComponentSerializer.colorDownsamplingGson().serialize(getAdv()); + String json = GsonComponentSerializer.colorDownsamplingGson().serialize(get()); return GsonComponentSerializer.gson().deserialize(json); } @@ -144,7 +126,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @return the MiniMessage representation if this {@link Chat} component. */ public String getMiniMessage() { - return MiniMessage.miniMessage().serialize(getAdv()); + return MiniMessage.miniMessage().serialize(get()); } @@ -184,15 +166,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource return this; } - /** - * Appends a BungeeCord {@link BaseComponent} to this component. - * @param comp the component to append. - * @return this. - */ - public Chat then(BaseComponent comp) { - return then(toAdventure(comp)); - } - /** * Appends a component to this component. * @param comp the component to append. @@ -207,15 +180,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource return then(comp.asComponent()); } - /** - * Appends a BungeeCord {@link BaseComponent} array to this component. - * @param comp the components to append. - * @return this. - */ - public Chat then(BaseComponent[] comp) { - return then(toAdventure(comp)); - } - @@ -495,17 +459,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource */ public Chat thenLeftText(ComponentLike leftText) { return then(leftText(leftText, console)); } - /** - * Appends a component filling a chat line with the configured decoration character and - * color and a left-aligned text. - * @param leftText the text aligned to the left. - * @return a new {@link FormatableChat} filling a chat line with the configured decoration character - * and color and a left-aligned text. - * @deprecated uses Bungeecord chat API. - */ - @Deprecated - public Chat thenLeftText(BaseComponent leftText) { return thenLeftText(chatComponent(leftText)); } - /** * Appends a component filling a chat line with the configured decoration character and * color and a right-aligned text. @@ -515,17 +468,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource */ public Chat thenRightText(ComponentLike rightText) { return then(rightText(rightText, console)); } - /** - * Appends a component filling a chat line with the configured decoration character and - * color and a right-aligned text. - * @param rightText the text aligned to the right. - * @return a new {@link FormatableChat} filling a chat line with the configured decoration character - * and color and a right-aligned text. - * @deprecated uses Bungeecord chat API. - */ - @Deprecated - public Chat thenRightText(BaseComponent rightText) { return thenRightText(chatComponent(rightText)); } - /** * Appends a component filling a chat line with the configured decoration character and * color and a centered text. @@ -537,19 +479,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource return then(centerText(centerText, console)); } - /** - * Appends a component filling a chat line with the configured decoration character and - * color and a centered text. - * @param centerText the text aligned to the center. - * @return a new {@link FormatableChat} filling a chat line with the configured decoration character - * and color and a centered text. - * @deprecated uses Bungeecord chat API. - */ - @Deprecated - public Chat thenCenterText(BaseComponent centerText) { - return thenCenterText(chatComponent(centerText)); - } - /** * Appends a component filling a chat line with the configured decoration character and color. * @return a new {@link FormatableChat} filling a chat line with a decoration character and color. @@ -629,12 +558,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @return this. */ public FormatableChat color(TextColor c) { builder.color(c); return this; } - /** - * Sets the color of this component. - * @param c the color. - * @return this. - */ - public FormatableChat color(ChatColor c) { return color(c == null ? null : TextColor.color(c.getColor().getRGB())); } /** * Sets the color of this component. * @param c the color. @@ -646,7 +569,16 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @param c the color. * @return this. */ - public FormatableChat color(String c) { return color(c == null ? null : ChatColor.of(c)); } + public FormatableChat color(String c) { + if (c == null) + return color((TextColor) null); + TextColor tc = c.startsWith("#") + ? TextColor.fromCSSHexString(c) + : NamedTextColor.NAMES.value(c.toLowerCase(Locale.ROOT)); + if (tc == null) + throw new IllegalArgumentException("Invalid color string '" + c + "'."); + return color(tc); + } /** @@ -924,18 +856,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource * @return this. */ public FormatableChat hover(ComponentLike v) { return hover(v.asComponent()); } - /** - * Configure this component to show the provided component when hovered. - * @param v the component to show. - * @return this. - */ - public FormatableChat hover(BaseComponent v) { return hover(toAdventure(v)); } - /** - * Configure this component to show the provided component when hovered. - * @param v the component to show. - * @return this. - */ - public FormatableChat hover(BaseComponent[] v) { return hover(toAdventure(v)); } /** * Configure this component to show the provided legacy text when hovered. * @param legacyText the legacy text to show. @@ -963,7 +883,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource @Override public int hashCode() { - return getAdv().hashCode(); + return get().hashCode(); } @Override @@ -976,8 +896,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource /* package */ static ComponentLike filterObjToComponentLike(Object v) { return switch (v) { - case BaseComponent[] baseComponents -> toAdventure(baseComponents); - case BaseComponent baseComponent -> toAdventure(baseComponent); case ComponentLike componentLike -> componentLike; case null, default -> Component.text(Objects.toString(v)); }; @@ -1011,40 +929,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource } - /** - * Converts the Bungee {@link BaseComponent} array into Adventure {@link Component}. - * @param components the Bungee {@link BaseComponent} array. - * @return a {@link Component}. - */ - public static Component toAdventure(BaseComponent[] components) { - return BungeeComponentSerializer.get().deserialize(components); - } - /** - * Converts the Bungee {@link BaseComponent} into Adventure {@link Component}. - * @param component the Bungee {@link BaseComponent}. - * @return a {@link Component}. - */ - public static Component toAdventure(BaseComponent component) { - return toAdventure(new BaseComponent[] { component }); - } - - /** - * Converts the Adventure {@link Component} into Bungee {@link BaseComponent} array. - * @param component the Adventure {@link Component}. - * @return a {@link BaseComponent} array. - */ - public static BaseComponent[] toBungeeArray(Component component) { - return BungeeComponentSerializer.get().serialize(component); - } - /** - * Converts the Adventure {@link Component} into Bungee {@link BaseComponent}. - * @param component the Adventure {@link Component}. - * @return a {@link BaseComponent}. - */ - public static BaseComponent toBungee(Component component) { - BaseComponent[] arr = toBungeeArray(component); - return arr.length == 1 ? arr[0] : new net.md_5.bungee.api.chat.TextComponent(arr); - } /** * Force the italic formatting to be set to false if it is not explicitly set in the component. diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatColorUtil.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatColorUtil.java index a8ddfe7..8e06479 100644 --- a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatColorUtil.java +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatColorUtil.java @@ -1,14 +1,14 @@ package fr.pandacube.lib.chat; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.format.TextDecoration; +import net.kyori.adventure.text.format.TextFormat; +import net.kyori.adventure.util.RGBLike; + import java.util.regex.Pattern; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import net.kyori.adventure.util.RGBLike; -import net.md_5.bungee.api.ChatColor; - /** - * Provides methods to manipulate legacy colors and {@link ChatColor} class. + * Provides methods to manipulate legacy colors. */ public class ChatColorUtil { @@ -38,12 +38,12 @@ public class ChatColorUtil { int length = legacyText.length(); for (int index = length - 2; index >= 0; index--) { - if (legacyText.charAt(index) == ChatColor.COLOR_CHAR) { + if (legacyText.charAt(index) == LegacyChatFormat.COLOR_CHAR) { // detection of rgb color §x§0§1§2§3§4§5 String rgb; if (index > 11 - && legacyText.charAt(index - 12) == ChatColor.COLOR_CHAR + && legacyText.charAt(index - 12) == LegacyChatFormat.COLOR_CHAR && (legacyText.charAt(index - 11) == 'x' || legacyText.charAt(index - 11) == 'X') && HEX_COLOR_PATTERN.matcher(rgb = legacyText.substring(index - 12, index + 2)).matches()) { @@ -64,7 +64,7 @@ public class ChatColorUtil { // try detect non-rgb format char colorChar = legacyText.charAt(index + 1); - ChatColor legacyColor = getChatColorByChar(colorChar); + LegacyChatFormat legacyColor = LegacyChatFormat.of(colorChar); if (legacyColor != null) { result.insert(0, legacyColor); @@ -83,15 +83,6 @@ public class ChatColorUtil { return result.toString(); } - /** - * Returns the {@link ChatColor} associated with the provided char, case-insensitive. - * @param code the case-insensitive char code. - * @return the corresponding {@link ChatColor}. - */ - public static ChatColor getChatColorByChar(char code) { - return ChatColor.getByChar(Character.toLowerCase(code)); - } - @@ -99,7 +90,7 @@ public class ChatColorUtil { * Translate the color code of the provided string, that uses the alt color char, to the {@code §} color code * format. *

- * This method is the improved version of {@link ChatColor#translateAlternateColorCodes(char, String)}, + * This method is the improved version of Bukkit’s {@code ChatColor.translateAlternateColorCodes(char, String)}, * because it takes into account essentials RGB color code, and {@code altColorChar} escaping (by doubling it). * Essentials RGB color code are converted to Bungee chat RGB format, so the returned string can be converted * to component (see {@link Chat#legacyText(Object)}). @@ -112,7 +103,7 @@ public class ChatColorUtil { */ public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) { - char colorChar = ChatColor.COLOR_CHAR; + char colorChar = LegacyChatFormat.COLOR_CHAR; StringBuilder acc = new StringBuilder(); char[] b = textToTranslate.toCharArray(); for ( int i = 0; i < b.length; i++ ) @@ -180,7 +171,7 @@ public class ChatColorUtil { * @return the text fully italic. */ public static String forceItalic(String legacyText) { - return forceFormat(legacyText, ChatColor.ITALIC); + return forceFormat(legacyText, TextDecoration.ITALIC); } /** @@ -190,7 +181,7 @@ public class ChatColorUtil { * @return the text fully bold. */ public static String forceBold(String legacyText) { - return forceFormat(legacyText, ChatColor.BOLD); + return forceFormat(legacyText, TextDecoration.BOLD); } /** @@ -200,7 +191,7 @@ public class ChatColorUtil { * @return the text fully underlined. */ public static String forceUnderline(String legacyText) { - return forceFormat(legacyText, ChatColor.UNDERLINE); + return forceFormat(legacyText, TextDecoration.UNDERLINED); } /** @@ -210,7 +201,7 @@ public class ChatColorUtil { * @return the text fully stroked through. */ public static String forceStrikethrough(String legacyText) { - return forceFormat(legacyText, ChatColor.STRIKETHROUGH); + return forceFormat(legacyText, TextDecoration.STRIKETHROUGH); } /** @@ -220,15 +211,16 @@ public class ChatColorUtil { * @return the text fully obfuscated. */ public static String forceObfuscated(String legacyText) { - return forceFormat(legacyText, ChatColor.MAGIC); + return forceFormat(legacyText, TextDecoration.OBFUSCATED); } - private static String forceFormat(String legacyText, ChatColor format) { + private static String forceFormat(String legacyText, TextFormat format) { + String formatStr = LegacyChatFormat.of(format).toString(); return format + legacyText - .replace(format.toString(), "") // remove previous tag to make the result cleaner - .replaceAll("§([a-frA-FR\\d])", "§$1" + format); + .replace(formatStr, "") // remove previous tag to make the result cleaner + .replaceAll("§([a-frA-FR\\d])", "§$1" + formatStr); } @@ -243,40 +235,12 @@ public class ChatColorUtil { * @return the resulting text. */ public static String resetToColor(String legacyText, String color) { - return legacyText.replace(ChatColor.RESET.toString(), color); + return legacyText.replace(LegacyChatFormat.RESET.toString(), color); } - /** - * Converts the provided {@link ChatColor} to its Adventure counterpart. - * @param bungee a BungeeCord {@link ChatColor} instance. - * @return the {@link TextColor} equivalent to the provided {@link ChatColor}. - */ - public static TextColor toAdventure(ChatColor bungee) { - if (bungee == null) - return null; - if (bungee.getColor() == null) - throw new IllegalArgumentException("The provided Bungee ChatColor must be an actual color (not format nor reset)."); - return TextColor.color(bungee.getColor().getRGB()); - } - - /** - * Converts the provided {@link TextColor} to its BungeeCord counterpart. - * @param col a Adventure {@link TextColor} instance. - * @return the {@link ChatColor} equivalent to the provided {@link TextColor}. - */ - public static ChatColor toBungee(TextColor col) { - if (col == null) - return null; - if (col instanceof NamedTextColor) { - return ChatColor.of(((NamedTextColor) col).toString()); - } - return ChatColor.of(col.asHexString()); - } - - /** * Create a color, interpolating between 2 colors. * @param v0 the value corresponding to color {@code cc0}. diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatConfig.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatConfig.java index b98922a..af83108 100644 --- a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatConfig.java +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/ChatConfig.java @@ -87,7 +87,7 @@ public class ChatConfig { */ public static int getPrefixWidth(boolean console) { Chat c; - return prefix == null ? 0 : (c = prefix.get()) == null ? 0 : ChatUtil.componentWidth(c.getAdv(), console); + return prefix == null ? 0 : (c = prefix.get()) == null ? 0 : ChatUtil.componentWidth(c.get(), console); } 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 ce4606d..53c2168 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 @@ -1,7 +1,6 @@ package fr.pandacube.lib.chat; -import java.util.Objects; - +import fr.pandacube.lib.chat.Chat.FormatableChat; import net.kyori.adventure.text.BlockNBTComponent; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentBuilder; @@ -18,9 +17,8 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import fr.pandacube.lib.chat.Chat.FormatableChat; +import java.util.Objects; /** * Abstract class holding the publicly accessible methods to create an instance of {@link Chat} component. @@ -33,15 +31,6 @@ public abstract class ChatStatic { return new FormatableChat(componentToBuilder(c)); } - /** - * Creates a {@link FormatableChat} from the provided Bungee {@link BaseComponent}. - * @param c the {@link BaseComponent}. - * @return a new {@link FormatableChat}. - */ - public static FormatableChat chatComponent(BaseComponent c) { - return new FormatableChat(componentToBuilder(Chat.toAdventure(c))); - } - /** * Creates a {@link FormatableChat} from the provided {@link ComponentLike}. * If the provided component is an instance of {@link Chat}, its content will be duplicated, and the provided one @@ -61,15 +50,6 @@ public abstract class ChatStatic { return new FormatableChat(Component.text()); } - /** - * Creates a {@link FormatableChat} from the provided Bungee {@link BaseComponent BaseComponent[]}. - * @param c the array of {@link BaseComponent}. - * @return a new {@link FormatableChat}. - */ - public static FormatableChat chatComponent(BaseComponent[] c) { - return chatComponent(Chat.toAdventure(c)); - } - 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 cf90146..00bf683 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 @@ -1,5 +1,17 @@ package fr.pandacube.lib.chat; +import fr.pandacube.lib.chat.Chat.FormatableChat; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.TranslationArgument; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.format.TextDecoration; +import net.kyori.adventure.text.format.TextDecoration.State; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -10,19 +22,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.ComponentLike; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.TranslatableComponent; -import net.kyori.adventure.text.TranslationArgument; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import net.kyori.adventure.text.format.TextDecoration; -import net.kyori.adventure.text.format.TextDecoration.State; -import net.md_5.bungee.api.ChatColor; - -import fr.pandacube.lib.chat.Chat.FormatableChat; - import static fr.pandacube.lib.chat.ChatStatic.chat; /** @@ -351,7 +350,7 @@ public class ChatUtil { do { char c = legacyText.charAt(index); - if (c == ChatColor.COLOR_CHAR && index < legacyText.length() - 1) { + if (c == LegacyComponentSerializer.SECTION_CHAR && index < legacyText.length() - 1) { currentWord.append(c); c = legacyText.charAt(++index); currentWord.append(c); @@ -482,7 +481,7 @@ public class ChatUtil { } if (!row.isEmpty()) spacedRow.then(row.getLast()); - spacedRows.add(spacedRow.getAdv()); + spacedRows.add(spacedRow.get()); } return spacedRows; @@ -504,14 +503,14 @@ public class ChatUtil { */ public static Component customWidthSpace(int width, boolean console) { if (console) - return Chat.text(" ".repeat(width)).getAdv(); + return Chat.text(" ".repeat(width)).get(); return switch (width) { case 0, 1 -> Component.empty(); - case 2 -> Chat.text(".").black().getAdv(); - case 3 -> Chat.text("`").black().getAdv(); - case 6 -> Chat.text(". ").black().getAdv(); - case 7 -> Chat.text("` ").black().getAdv(); - case 11 -> Chat.text("` ").black().getAdv(); + case 2 -> Chat.text(".").black().get(); + case 3 -> Chat.text("`").black().get(); + case 6 -> Chat.text(". ").black().get(); + case 7 -> Chat.text("` ").black().get(); + case 11 -> Chat.text("` ").black().get(); default -> { int nbSpace = width / 4; int nbBold = width % 4; @@ -520,13 +519,13 @@ public class ChatUtil { if (nbBold > 0) { yield Chat.text(" ".repeat(nbNotBold)).bold(false) .then(Chat.text(" ".repeat(nbBold)).bold(true)) - .getAdv(); + .get(); } else - yield Chat.text(" ".repeat(nbNotBold)).bold(false).getAdv(); + yield Chat.text(" ".repeat(nbNotBold)).bold(false).get(); } else if (nbBold > 0) { - yield Chat.text(" ".repeat(nbBold)).bold(true).getAdv(); + yield Chat.text(" ".repeat(nbBold)).bold(true).get(); } throw new IllegalStateException("Should not be here (width=" + width + "; nbSpace=" + nbSpace + "; nbBold=" + nbBold + "; nbNotBold=" + nbNotBold + ")"); } diff --git a/pandalib-chat/src/main/java/fr/pandacube/lib/chat/LegacyChatFormat.java b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/LegacyChatFormat.java new file mode 100644 index 0000000..3bfc866 --- /dev/null +++ b/pandalib-chat/src/main/java/fr/pandacube/lib/chat/LegacyChatFormat.java @@ -0,0 +1,122 @@ +package fr.pandacube.lib.chat; + +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.format.TextDecoration; +import net.kyori.adventure.text.format.TextFormat; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyFormat; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; + +public enum LegacyChatFormat { + + BLACK('0'), + DARK_BLUE('1'), + DARK_GREEN('2'), + DARK_AQUA('3'), + DARK_RED('4'), + DARK_PURPLE('5'), + GOLD('6'), + GRAY('7'), + DARK_GRAY('8'), + BLUE('9'), + GREEN('a'), + AQUA('b'), + RED('c'), + LIGHT_PURPLE('d'), + YELLOW('e'), + WHITE('f'), + MAGIC('k'), + BOLD('l'), + STRIKETHROUGH('m'), + UNDERLINED('n'), + ITALIC('o'), + RESET('r'); + + + + + + public static final char COLOR_CHAR = LegacyComponentSerializer.SECTION_CHAR; + public static final String COLOR_STR_PREFIX = Character.toString(COLOR_CHAR); + + private static final Map BY_CHAR; + private static final Map BY_FORMAT; + private static final Map BY_LEGACY; + + + public static LegacyChatFormat of(char code) { + return BY_CHAR.get(Character.toLowerCase(code)); + } + + public static LegacyChatFormat of(TextFormat format) { + LegacyChatFormat colorOrDecoration = BY_FORMAT.get(format); + if (colorOrDecoration != null) + return colorOrDecoration; + if (format.getClass().getSimpleName().equals("Reset")) // an internal class of legacy serializer library + return RESET; + throw new IllegalArgumentException("Unsupported format of type " + format.getClass()); + } + + public static LegacyChatFormat of(LegacyFormat advLegacy) { + return BY_LEGACY.get(advLegacy); + } + + + + + + + + + + public final char code; + public final LegacyFormat advLegacyFormat; + + LegacyChatFormat(char code) { + this.code = code; + advLegacyFormat = LegacyComponentSerializer.parseChar(code); + } + + public TextColor getTextColor() { + return advLegacyFormat.color(); + } + + public boolean isColor() { + return getTextColor() != null; + } + + public TextDecoration getTextDecoration() { + return advLegacyFormat.decoration(); + } + + public boolean isDecoration() { + return getTextDecoration() != null; + } + + public boolean isReset() { + return this == RESET; + } + + @Override + public String toString() { + return COLOR_STR_PREFIX + code; + } + + + + static { + BY_CHAR = Arrays.stream(values()).sequential().collect(Collectors.toMap(e -> e.code, e -> e, (e1, e2) -> e1, LinkedHashMap::new)); + BY_FORMAT = Arrays.stream(values()).sequential() + .filter(e -> e.isColor() || e.isDecoration()) + .collect(Collectors.toMap(e -> { + if (e.isColor()) + return e.getTextColor(); + return e.getTextDecoration(); + }, e -> e, (e1, e2) -> e1, LinkedHashMap::new)); + BY_LEGACY = Arrays.stream(values()).sequential().collect(Collectors.toMap(e -> e.advLegacyFormat, e -> e, (e1, e2) -> e1, LinkedHashMap::new)); + } +} diff --git a/pandalib-cli/src/main/java/fr/pandacube/lib/cli/commands/CommandAdmin.java b/pandalib-cli/src/main/java/fr/pandacube/lib/cli/commands/CommandAdmin.java index 7e3d59d..0fbddc0 100644 --- a/pandalib-cli/src/main/java/fr/pandacube/lib/cli/commands/CommandAdmin.java +++ b/pandalib-cli/src/main/java/fr/pandacube/lib/cli/commands/CommandAdmin.java @@ -18,7 +18,7 @@ import fr.pandacube.lib.chat.Chat.FormatableChat; import fr.pandacube.lib.chat.ChatTreeNode; import fr.pandacube.lib.cli.CLIApplication; import fr.pandacube.lib.util.log.Log; -import net.md_5.bungee.api.chat.BaseComponent; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.Arrays; @@ -192,7 +192,7 @@ public class CommandAdmin extends CLIBrigadierCommand { - private BaseComponent displayCurrentNode(CommandNode node, boolean redirectTarget, CLICommandSender sender) { + private Component displayCurrentNode(CommandNode node, boolean redirectTarget, CLICommandSender sender) { if (node == null) throw new IllegalArgumentException("node must not be null"); FormatableChat d; diff --git a/pandalib-core/pom.xml b/pandalib-core/pom.xml index c7ffe9d..cc2b2ac 100644 --- a/pandalib-core/pom.xml +++ b/pandalib-core/pom.xml @@ -37,6 +37,12 @@ ${project.version} + + com.google.guava + guava + ${guava.version} + + ch.eitchnet diff --git a/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/BackupCleaner.java b/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/BackupCleaner.java index 67e8e4c..d25846f 100644 --- a/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/BackupCleaner.java +++ b/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/BackupCleaner.java @@ -1,8 +1,8 @@ package fr.pandacube.lib.core.backup; import fr.pandacube.lib.chat.Chat; +import fr.pandacube.lib.chat.LegacyChatFormat; import fr.pandacube.lib.util.log.Log; -import net.md_5.bungee.api.ChatColor; import java.io.File; import java.time.LocalDateTime; @@ -107,14 +107,14 @@ public abstract class BackupCleaner implements UnaryOperator datedFiles = new TreeMap<>(); for (String filename : files) { File file = new File(archiveDir, filename); if (!filename.matches("\\d{8}-\\d{6}\\.zip")) { - Log.warning("[Backup] " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + " Invalid file in backup directory: " + filename); + Log.warning("[Backup] " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + " Invalid file in backup directory: " + filename); continue; } @@ -123,7 +123,7 @@ public abstract class BackupCleaner implements UnaryOperator, Runnab File sourceDir = getSourceDir(); if (!sourceDir.exists()) { - Log.warning("[Backup] Unable to compress " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + ": source directory " + sourceDir + " doesn't exist"); + Log.warning("[Backup] Unable to compress " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + ": source directory " + sourceDir + " doesn't exist"); return; } @@ -219,7 +219,7 @@ public abstract class BackupProcess implements Comparable, Runnab onBackupStart(); new Thread(() -> { - Log.info("[Backup] Starting for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " ..."); + Log.info("[Backup] Starting for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " ..."); compressor = new ZipCompressor(sourceDir, target, 9, filter); @@ -229,7 +229,7 @@ public abstract class BackupProcess implements Comparable, Runnab success = true; - Log.info("[Backup] Finished for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET); + Log.info("[Backup] Finished for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET); try { BackupCleaner cleaner = getBackupCleaner(); @@ -267,7 +267,7 @@ public abstract class BackupProcess implements Comparable, Runnab * Logs the scheduling status of this backup process. */ public void displayNextSchedule() { - Log.info("[Backup] " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " next backup on " + Log.info("[Backup] " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " next backup on " + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date(getNext()))); } @@ -297,7 +297,7 @@ public abstract class BackupProcess implements Comparable, Runnab public void logProgress() { if (compressor == null) return; - Log.info("[Backup] " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + ": " + compressor.getState().getLegacyText()); + Log.info("[Backup] " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + ": " + compressor.getState().getLegacyText()); } diff --git a/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/RotatedLogsBackupProcess.java b/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/RotatedLogsBackupProcess.java index d6f677b..7a5d95f 100644 --- a/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/RotatedLogsBackupProcess.java +++ b/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/RotatedLogsBackupProcess.java @@ -1,8 +1,8 @@ package fr.pandacube.lib.core.backup; import com.google.common.io.Files; +import fr.pandacube.lib.chat.LegacyChatFormat; import fr.pandacube.lib.util.log.Log; -import net.md_5.bungee.api.ChatColor; import java.io.File; import java.io.IOException; @@ -53,7 +53,7 @@ public class RotatedLogsBackupProcess extends BackupProcess { if (!getSourceDir().isDirectory()) return; - Log.info("[Backup] Starting for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " ..."); + Log.info("[Backup] Starting for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " ..."); try { // wait a little after the log message above, in case the log file rotation has to be performed. @@ -82,9 +82,9 @@ public class RotatedLogsBackupProcess extends BackupProcess { success = true; - Log.info("[Backup] Finished for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET); + Log.info("[Backup] Finished for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET); } catch (Exception e) { - Log.severe("[Backup] Failed for : " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET, e); + Log.severe("[Backup] Failed for : " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET, e); } finally { onBackupEnd(success); diff --git a/pandalib-paper/pom.xml b/pandalib-paper/pom.xml index a70102e..c1a59d0 100644 --- a/pandalib-paper/pom.xml +++ b/pandalib-paper/pom.xml @@ -71,6 +71,12 @@ ${project.version} + + fr.pandacube.lib + pandalib-bungee-chat + ${project.version} + + fr.pandacube.lib pandalib-paper-permissions diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java index 8d10d6e..08cfab0 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java @@ -38,7 +38,7 @@ public class GUIInventory implements Listener { if (title == null) inv = Bukkit.createInventory(null, nbLines * 9); else - inv = Bukkit.createInventory(null, nbLines * 9, title.getAdv()); + inv = Bukkit.createInventory(null, nbLines * 9, title.get()); setCloseEvent(closeEventAction); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java index 812fbec..83e9af5 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java @@ -4,7 +4,6 @@ import com.destroystokyo.paper.event.server.ServerTickEndEvent; import com.destroystokyo.paper.event.server.ServerTickStartEvent; import fr.pandacube.lib.chat.Chat; import fr.pandacube.lib.chat.ChatColorGradient; -import fr.pandacube.lib.chat.ChatColorUtil; import fr.pandacube.lib.chat.ChatConfig.PandaTheme; import fr.pandacube.lib.paper.PandaLibPaper; import fr.pandacube.lib.paper.players.PaperOffPlayer; @@ -13,16 +12,16 @@ import fr.pandacube.lib.paper.scheduler.SchedulerUtil; import fr.pandacube.lib.paper.util.AutoUpdatedBossBar; import fr.pandacube.lib.paper.util.AutoUpdatedBossBar.BarUpdater; import fr.pandacube.lib.players.standalone.AbstractPlayerManager; -import fr.pandacube.lib.util.log.Log; import fr.pandacube.lib.util.MemoryUtil; import fr.pandacube.lib.util.MemoryUtil.MemoryUnit; import fr.pandacube.lib.util.TimeUtil; +import fr.pandacube.lib.util.log.Log; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.bossbar.BossBar.Color; import net.kyori.adventure.bossbar.BossBar.Overlay; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; -import net.md_5.bungee.api.ChatColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -299,15 +298,17 @@ public class PerformanceAnalysisManager implements Listener { // keep the legacy text when generating the bar to save space when converting to component StringBuilder s = new StringBuilder(); - ChatColor prevC = ChatColor.RESET; + TextColor prevC = null; for (int i = 58; i >= 0; i--) { int t = tpsHistory[i]; - ChatColor newC = ChatColorUtil.toBungee(tps1sGradient.pickColorAt(t)); + TextColor newC = tps1sGradient.pickColorAt(t); if (!newC.equals(prevC)) { - s.append(newC); + s.append(text("|").color(newC).getLegacyText()); prevC = newC; } - s.append("|"); + else { + s.append("|"); + } } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java index 11a10e6..941dd52 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java @@ -113,7 +113,7 @@ public class ItemStackBuilder { public ItemStackBuilder lore(List lore) { if (lore != null) { return rawLore(lore.stream() - .map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv()) + .map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).get()) .toList()); } else @@ -128,7 +128,7 @@ public class ItemStackBuilder { Streams.concat( baseLore.stream(), lores.stream() - .map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv()) + .map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).get()) ) .toList()); } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java index e80d1aa..6d6e660 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ScoreboardUtil.java @@ -116,9 +116,9 @@ public class ScoreboardUtil { public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, Chat[] lines) { Component[] cmpLines = new Component[lines.length]; for (int i = 0; i < lines.length; i++) { - cmpLines[i] = lines[i].getAdv(); + cmpLines[i] = lines[i].get(); } - updateScoreboardSidebar(scBrd, title.getAdv(), cmpLines); + updateScoreboardSidebar(scBrd, title.get(), cmpLines); } @@ -135,9 +135,9 @@ public class ScoreboardUtil { public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, List lines) { Component[] cmpLines = new Component[lines.size()]; for (int i = 0; i < cmpLines.length; i++) { - cmpLines[i] = lines.get(i).getAdv(); + cmpLines[i] = lines.get(i).get(); } - updateScoreboardSidebar(scBrd, title.getAdv(), cmpLines); + updateScoreboardSidebar(scBrd, title.get(), cmpLines); } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/Skull.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/Skull.java index 875c547..2bd807b 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/Skull.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/Skull.java @@ -99,10 +99,10 @@ public enum Skull { boolean b = meta.setOwner(name); if (displayName != null) - meta.displayName(displayName.getAdv()); + meta.displayName(displayName.get()); if (lore != null) - meta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList())); + meta.lore(lore.stream().map(Chat::get).collect(Collectors.toList())); itemStack.setItemMeta(meta); return itemStack; @@ -172,10 +172,10 @@ public enum Skull { headMeta.setPlayerProfile(profile); if (displayName != null) - headMeta.displayName(displayName.getAdv()); + headMeta.displayName(displayName.get()); if (lore != null) - headMeta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList())); + headMeta.lore(lore.stream().map(Chat::get).collect(Collectors.toList())); head.setItemMeta(headMeta); diff --git a/pandalib-permissions/pom.xml b/pandalib-permissions/pom.xml index fc984b9..bdd80d1 100644 --- a/pandalib-permissions/pom.xml +++ b/pandalib-permissions/pom.xml @@ -37,6 +37,12 @@ javaluator 3.0.3 + + + com.google.guava + guava + ${guava.version} + diff --git a/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermissionsResolver.java b/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermissionsResolver.java index 51313d2..b1c2829 100644 --- a/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermissionsResolver.java +++ b/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermissionsResolver.java @@ -1,5 +1,18 @@ package fr.pandacube.lib.permissions; +import com.google.common.base.Preconditions; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import fr.pandacube.lib.chat.Chat; +import fr.pandacube.lib.chat.ChatTreeNode; +import fr.pandacube.lib.chat.LegacyChatFormat; +import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedEntity; +import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedGroup; +import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedPlayer; +import fr.pandacube.lib.permissions.SQLPermissions.EntityType; +import fr.pandacube.lib.util.log.Log; +import net.kyori.adventure.text.format.NamedTextColor; + import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedHashMap; @@ -12,19 +25,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import com.google.common.base.Preconditions; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import net.md_5.bungee.api.ChatColor; - -import fr.pandacube.lib.chat.Chat; -import fr.pandacube.lib.chat.ChatTreeNode; -import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedEntity; -import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedGroup; -import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedPlayer; -import fr.pandacube.lib.permissions.SQLPermissions.EntityType; -import fr.pandacube.lib.util.log.Log; - /* package */ class PermissionsResolver { private final PermissionsCachedBackendReader backendReader; @@ -105,7 +105,7 @@ import fr.pandacube.lib.util.log.Log; Log.warning("For data " + dataType + ":\n" + resolutionResult.toDisplayTreeNode().render(true).stream() .map(Chat::getLegacyText) - .collect(Collectors.joining(ChatColor.RESET + "\n"))); + .collect(Collectors.joining(LegacyChatFormat.RESET + "\n"))); } return resolutionResult.result != null ? resolutionResult.result : ""; @@ -167,7 +167,7 @@ import fr.pandacube.lib.util.log.Log; if (result == null) c.then(Chat.text(" (non défini)").gray()); else - c.thenLegacyText(" \"" + ChatColor.RESET + result + ChatColor.RESET + "\""); + c.thenLegacyText(" \"" + LegacyChatFormat.RESET + result + LegacyChatFormat.RESET + "\""); if (conflictMessage != null) c.thenFailure(" " + conflictMessage); ChatTreeNode node = new ChatTreeNode(c); @@ -307,7 +307,7 @@ import fr.pandacube.lib.util.log.Log; Log.warning("For permission " + permission + ":\n" + resolutionResult.toDisplayTreeNode().render(true).stream() .map(Chat::getLegacyText) - .collect(Collectors.joining(ChatColor.RESET + "\n"))); + .collect(Collectors.joining(LegacyChatFormat.RESET + "\n"))); } return resolutionResult.result; @@ -487,7 +487,7 @@ import fr.pandacube.lib.util.log.Log; Chat c = Chat.chat() .then(result == PermState.UNDEFINED ? Chat.dataText("■") : result == PermState.GRANTED ? Chat.successText("✔") : Chat.failureText("✘")) .then(Chat.text(entity instanceof CachedPlayer cp ? Permissions.playerNameGetter.apply(cp.playerId) : entity.name) - .color(entity instanceof CachedPlayer ? ChatColor.GOLD : ChatColor.DARK_AQUA) + .color(entity instanceof CachedPlayer ? NamedTextColor.GOLD : NamedTextColor.DARK_AQUA) ); if (server != null) c.thenData(" s=" + server); @@ -523,7 +523,7 @@ import fr.pandacube.lib.util.log.Log; public ChatTreeNode toDisplayTreeNode() { return new ChatTreeNode(Chat.chat() .then(result ? Chat.successText("✔") : Chat.failureText("✘")) - .then(Chat.text(permission).color(type == PermType.WILDCARD ? ChatColor.YELLOW : type == PermType.SPECIAL ? ChatColor.LIGHT_PURPLE : ChatColor.WHITE))); + .then(Chat.text(permission).color(type == PermType.WILDCARD ? NamedTextColor.YELLOW : type == PermType.SPECIAL ? NamedTextColor.LIGHT_PURPLE : NamedTextColor.WHITE))); } } diff --git a/pandalib-players/pom.xml b/pandalib-players/pom.xml index 1bbbd90..56c2883 100644 --- a/pandalib-players/pom.xml +++ b/pandalib-players/pom.xml @@ -21,12 +21,11 @@ ${project.version} - + + com.google.guava + guava + ${guava.version} + diff --git a/pom.xml b/pom.xml index ffd1d4c..04f6675 100644 --- a/pom.xml +++ b/pom.xml @@ -58,10 +58,13 @@ 1.21-R0.1-SNAPSHOT 1.20.6-R0.1 1.20.6 + + 32.1.2-jre pandalib-bungee + pandalib-bungee-chat pandalib-bungee-permissions pandalib-chat pandalib-cli