Compare commits
No commits in common. "36eb1227cf747ec06efda1d9855f98b171e17609" and "3e6cf96040ccf017a15f93ca821fbe043108f371" have entirely different histories.
36eb1227cf
...
3e6cf96040
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,3 @@
|
||||
/.idea
|
||||
/*/target
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
*.iml
|
1
pandalib-bungee-chat/.gitignore
vendored
1
pandalib-bungee-chat/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/target/
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>pandalib-parent</artifactId>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>pandalib-bungee-chat</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-chat</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>${bungeecord.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,71 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-bungee-chat</artifactId>
|
||||
<artifactId>pandalib-chat</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,6 +1,6 @@
|
||||
package fr.pandacube.lib.bungee.commands;
|
||||
|
||||
import fr.pandacube.lib.bungee.chat.ChatBungee;
|
||||
import fr.pandacube.lib.chat.Chat;
|
||||
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<CommandSender
|
||||
|
||||
@Override
|
||||
protected void sendSenderMessage(CommandSender sender, ComponentLike message) {
|
||||
sender.sendMessage(ChatBungee.toBungee(message.asComponent()));
|
||||
sender.sendMessage(Chat.toBungee(message.asComponent()));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package fr.pandacube.lib.bungee.players;
|
||||
|
||||
import fr.pandacube.lib.bungee.chat.ChatBungee;
|
||||
import fr.pandacube.lib.chat.Chat;
|
||||
import fr.pandacube.lib.core.mc_version.ProtocolVersion;
|
||||
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
||||
import fr.pandacube.lib.reflect.Reflect;
|
||||
@ -84,13 +84,13 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
|
||||
|
||||
@Override
|
||||
default void sendMessage(Component message) {
|
||||
getBungeeProxiedPlayer().sendMessage(ChatBungee.toBungee(message));
|
||||
getBungeeProxiedPlayer().sendMessage(Chat.toBungee(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
default void sendTitle(Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
ProxyServer.getInstance().createTitle()
|
||||
.title(ChatBungee.toBungee(title)).subTitle(ChatBungee.toBungee(subtitle))
|
||||
.title(Chat.toBungee(title)).subTitle(Chat.toBungee(subtitle))
|
||||
.fadeIn(fadeIn).stay(stay).fadeOut(fadeOut)
|
||||
.send(getBungeeProxiedPlayer());
|
||||
}
|
||||
|
@ -30,13 +30,8 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-gson</artifactId>
|
||||
<version>4.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||
<version>4.13.0</version>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
@ -51,6 +46,13 @@
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>${bungeecord.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
|
@ -16,13 +16,15 @@ 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;
|
||||
@ -65,10 +67,26 @@ 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 get() {
|
||||
public Component getAdv() {
|
||||
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()
|
||||
@ -79,7 +97,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(get());
|
||||
return LEGACY_SERIALIZER_BUNGEE_FRIENDLY.serialize(getAdv());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,12 +105,12 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
* @return the plain text of this component.
|
||||
*/
|
||||
public String getPlainText() {
|
||||
return PlainTextComponentSerializer.plainText().serializeOr(get(), "");
|
||||
return PlainTextComponentSerializer.plainText().serializeOr(getAdv(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HoverEvent<Component> asHoverEvent(@NotNull UnaryOperator<Component> op) {
|
||||
return HoverEvent.showText(op.apply(get()));
|
||||
return HoverEvent.showText(op.apply(getAdv()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +119,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Component asComponent() {
|
||||
return get();
|
||||
return getAdv();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +127,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(get());
|
||||
String json = GsonComponentSerializer.colorDownsamplingGson().serialize(getAdv());
|
||||
return GsonComponentSerializer.gson().deserialize(json);
|
||||
}
|
||||
|
||||
@ -126,7 +144,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(get());
|
||||
return MiniMessage.miniMessage().serialize(getAdv());
|
||||
}
|
||||
|
||||
|
||||
@ -166,6 +184,15 @@ 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.
|
||||
@ -180,6 +207,15 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -459,6 +495,17 @@ 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.
|
||||
@ -468,6 +515,17 @@ 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.
|
||||
@ -479,6 +537,19 @@ 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.
|
||||
@ -558,6 +629,12 @@ 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.
|
||||
@ -569,16 +646,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
* @param c the color.
|
||||
* @return this.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
public FormatableChat color(String c) { return color(c == null ? null : ChatColor.of(c)); }
|
||||
|
||||
|
||||
/**
|
||||
@ -856,6 +924,18 @@ 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.
|
||||
@ -883,7 +963,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return get().hashCode();
|
||||
return getAdv().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -896,6 +976,8 @@ 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));
|
||||
};
|
||||
@ -929,6 +1011,40 @@ 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.
|
||||
|
@ -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.
|
||||
* Provides methods to manipulate legacy colors and {@link ChatColor} class.
|
||||
*/
|
||||
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) == LegacyChatFormat.COLOR_CHAR) {
|
||||
if (legacyText.charAt(index) == ChatColor.COLOR_CHAR) {
|
||||
|
||||
// detection of rgb color §x§0§1§2§3§4§5
|
||||
String rgb;
|
||||
if (index > 11
|
||||
&& legacyText.charAt(index - 12) == LegacyChatFormat.COLOR_CHAR
|
||||
&& legacyText.charAt(index - 12) == ChatColor.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);
|
||||
LegacyChatFormat legacyColor = LegacyChatFormat.of(colorChar);
|
||||
ChatColor legacyColor = getChatColorByChar(colorChar);
|
||||
|
||||
if (legacyColor != null) {
|
||||
result.insert(0, legacyColor);
|
||||
@ -83,6 +83,15 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -90,7 +99,7 @@ public class ChatColorUtil {
|
||||
* Translate the color code of the provided string, that uses the alt color char, to the {@code §} color code
|
||||
* format.
|
||||
* <p>
|
||||
* This method is the improved version of Bukkit’s {@code ChatColor.translateAlternateColorCodes(char, String)},
|
||||
* This method is the improved version of {@link 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)}).
|
||||
@ -103,7 +112,7 @@ public class ChatColorUtil {
|
||||
*/
|
||||
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
|
||||
{
|
||||
char colorChar = LegacyChatFormat.COLOR_CHAR;
|
||||
char colorChar = ChatColor.COLOR_CHAR;
|
||||
StringBuilder acc = new StringBuilder();
|
||||
char[] b = textToTranslate.toCharArray();
|
||||
for ( int i = 0; i < b.length; i++ )
|
||||
@ -171,7 +180,7 @@ public class ChatColorUtil {
|
||||
* @return the text fully italic.
|
||||
*/
|
||||
public static String forceItalic(String legacyText) {
|
||||
return forceFormat(legacyText, TextDecoration.ITALIC);
|
||||
return forceFormat(legacyText, ChatColor.ITALIC);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +190,7 @@ public class ChatColorUtil {
|
||||
* @return the text fully bold.
|
||||
*/
|
||||
public static String forceBold(String legacyText) {
|
||||
return forceFormat(legacyText, TextDecoration.BOLD);
|
||||
return forceFormat(legacyText, ChatColor.BOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +200,7 @@ public class ChatColorUtil {
|
||||
* @return the text fully underlined.
|
||||
*/
|
||||
public static String forceUnderline(String legacyText) {
|
||||
return forceFormat(legacyText, TextDecoration.UNDERLINED);
|
||||
return forceFormat(legacyText, ChatColor.UNDERLINE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,7 +210,7 @@ public class ChatColorUtil {
|
||||
* @return the text fully stroked through.
|
||||
*/
|
||||
public static String forceStrikethrough(String legacyText) {
|
||||
return forceFormat(legacyText, TextDecoration.STRIKETHROUGH);
|
||||
return forceFormat(legacyText, ChatColor.STRIKETHROUGH);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,16 +220,15 @@ public class ChatColorUtil {
|
||||
* @return the text fully obfuscated.
|
||||
*/
|
||||
public static String forceObfuscated(String legacyText) {
|
||||
return forceFormat(legacyText, TextDecoration.OBFUSCATED);
|
||||
return forceFormat(legacyText, ChatColor.MAGIC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static String forceFormat(String legacyText, TextFormat format) {
|
||||
String formatStr = LegacyChatFormat.of(format).toString();
|
||||
private static String forceFormat(String legacyText, ChatColor format) {
|
||||
return format + legacyText
|
||||
.replace(formatStr, "") // remove previous tag to make the result cleaner
|
||||
.replaceAll("§([a-frA-FR\\d])", "§$1" + formatStr);
|
||||
.replace(format.toString(), "") // remove previous tag to make the result cleaner
|
||||
.replaceAll("§([a-frA-FR\\d])", "§$1" + format);
|
||||
}
|
||||
|
||||
|
||||
@ -235,12 +243,40 @@ public class ChatColorUtil {
|
||||
* @return the resulting text.
|
||||
*/
|
||||
public static String resetToColor(String legacyText, String color) {
|
||||
return legacyText.replace(LegacyChatFormat.RESET.toString(), color);
|
||||
return legacyText.replace(ChatColor.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}.
|
||||
|
@ -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.get(), console);
|
||||
return prefix == null ? 0 : (c = prefix.get()) == null ? 0 : ChatUtil.componentWidth(c.getAdv(), console);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.pandacube.lib.chat;
|
||||
|
||||
import fr.pandacube.lib.chat.Chat.FormatableChat;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.kyori.adventure.text.BlockNBTComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
@ -17,8 +18,9 @@ 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 java.util.Objects;
|
||||
import fr.pandacube.lib.chat.Chat.FormatableChat;
|
||||
|
||||
/**
|
||||
* Abstract class holding the publicly accessible methods to create an instance of {@link Chat} component.
|
||||
@ -31,6 +33,15 @@ 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
|
||||
@ -50,6 +61,15 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,17 +1,5 @@
|
||||
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;
|
||||
@ -22,6 +10,19 @@ 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;
|
||||
|
||||
/**
|
||||
@ -350,7 +351,7 @@ public class ChatUtil {
|
||||
|
||||
do {
|
||||
char c = legacyText.charAt(index);
|
||||
if (c == LegacyComponentSerializer.SECTION_CHAR && index < legacyText.length() - 1) {
|
||||
if (c == ChatColor.COLOR_CHAR && index < legacyText.length() - 1) {
|
||||
currentWord.append(c);
|
||||
c = legacyText.charAt(++index);
|
||||
currentWord.append(c);
|
||||
@ -481,7 +482,7 @@ public class ChatUtil {
|
||||
}
|
||||
if (!row.isEmpty())
|
||||
spacedRow.then(row.getLast());
|
||||
spacedRows.add(spacedRow.get());
|
||||
spacedRows.add(spacedRow.getAdv());
|
||||
}
|
||||
|
||||
return spacedRows;
|
||||
@ -503,14 +504,14 @@ public class ChatUtil {
|
||||
*/
|
||||
public static Component customWidthSpace(int width, boolean console) {
|
||||
if (console)
|
||||
return Chat.text(" ".repeat(width)).get();
|
||||
return Chat.text(" ".repeat(width)).getAdv();
|
||||
return switch (width) {
|
||||
case 0, 1 -> Component.empty();
|
||||
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();
|
||||
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();
|
||||
default -> {
|
||||
int nbSpace = width / 4;
|
||||
int nbBold = width % 4;
|
||||
@ -519,13 +520,13 @@ public class ChatUtil {
|
||||
if (nbBold > 0) {
|
||||
yield Chat.text(" ".repeat(nbNotBold)).bold(false)
|
||||
.then(Chat.text(" ".repeat(nbBold)).bold(true))
|
||||
.get();
|
||||
.getAdv();
|
||||
}
|
||||
else
|
||||
yield Chat.text(" ".repeat(nbNotBold)).bold(false).get();
|
||||
yield Chat.text(" ".repeat(nbNotBold)).bold(false).getAdv();
|
||||
}
|
||||
else if (nbBold > 0) {
|
||||
yield Chat.text(" ".repeat(nbBold)).bold(true).get();
|
||||
yield Chat.text(" ".repeat(nbBold)).bold(true).getAdv();
|
||||
}
|
||||
throw new IllegalStateException("Should not be here (width=" + width + "; nbSpace=" + nbSpace + "; nbBold=" + nbBold + "; nbNotBold=" + nbNotBold + ")");
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
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<Character, LegacyChatFormat> BY_CHAR;
|
||||
private static final Map<TextFormat, LegacyChatFormat> BY_FORMAT;
|
||||
private static final Map<LegacyFormat, LegacyChatFormat> 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));
|
||||
}
|
||||
}
|
@ -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.kyori.adventure.text.Component;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -192,7 +192,7 @@ public class CommandAdmin extends CLIBrigadierCommand {
|
||||
|
||||
|
||||
|
||||
private Component displayCurrentNode(CommandNode<CLICommandSender> node, boolean redirectTarget, CLICommandSender sender) {
|
||||
private BaseComponent displayCurrentNode(CommandNode<CLICommandSender> node, boolean redirectTarget, CLICommandSender sender) {
|
||||
if (node == null)
|
||||
throw new IllegalArgumentException("node must not be null");
|
||||
FormatableChat d;
|
||||
|
@ -37,12 +37,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Cron expression interpreter -->
|
||||
<dependency>
|
||||
<groupId>ch.eitchnet</groupId>
|
||||
|
@ -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<TreeSet<LocalDateTi
|
||||
if (files == null)
|
||||
return;
|
||||
|
||||
Log.info("[Backup] Cleaning up backup directory " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + "...");
|
||||
Log.info("[Backup] Cleaning up backup directory " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + "...");
|
||||
|
||||
TreeMap<LocalDateTime, File> datedFiles = new TreeMap<>();
|
||||
|
||||
for (String filename : files) {
|
||||
File file = new File(archiveDir, filename);
|
||||
if (!filename.matches("\\d{8}-\\d{6}\\.zip")) {
|
||||
Log.warning("[Backup] " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + " Invalid file in backup directory: " + filename);
|
||||
Log.warning("[Backup] " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + " Invalid file in backup directory: " + filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public abstract class BackupCleaner implements UnaryOperator<TreeSet<LocalDateTi
|
||||
try {
|
||||
ldt = LocalDateTime.parse(dateTimeStr, BackupProcess.dateFileNameFormatter);
|
||||
} catch (DateTimeParseException e) {
|
||||
Log.warning("[Backup] " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + " Unable to parse file name to a date-time: " + filename, e);
|
||||
Log.warning("[Backup] " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + " Unable to parse file name to a date-time: " + filename, e);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public abstract class BackupCleaner implements UnaryOperator<TreeSet<LocalDateTi
|
||||
if (testOnly || oneDeleted)
|
||||
Log.warning(c.getLegacyText());
|
||||
|
||||
Log.info("[Backup] Backup directory " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + " cleaned.");
|
||||
Log.info("[Backup] Backup directory " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + " cleaned.");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package fr.pandacube.lib.core.backup;
|
||||
|
||||
import fc.cron.CronExpression;
|
||||
import fr.pandacube.lib.chat.LegacyChatFormat;
|
||||
import fr.pandacube.lib.core.cron.CronScheduler;
|
||||
import fr.pandacube.lib.util.FileUtils;
|
||||
import fr.pandacube.lib.util.log.Log;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
@ -209,7 +209,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
||||
File sourceDir = getSourceDir();
|
||||
|
||||
if (!sourceDir.exists()) {
|
||||
Log.warning("[Backup] Unable to compress " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + ": source directory " + sourceDir + " doesn't exist");
|
||||
Log.warning("[Backup] Unable to compress " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + ": source directory " + sourceDir + " doesn't exist");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
||||
onBackupStart();
|
||||
|
||||
new Thread(() -> {
|
||||
Log.info("[Backup] Starting for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " ...");
|
||||
Log.info("[Backup] Starting for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " ...");
|
||||
|
||||
compressor = new ZipCompressor(sourceDir, target, 9, filter);
|
||||
|
||||
@ -229,7 +229,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
||||
|
||||
success = true;
|
||||
|
||||
Log.info("[Backup] Finished for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET);
|
||||
Log.info("[Backup] Finished for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET);
|
||||
|
||||
try {
|
||||
BackupCleaner cleaner = getBackupCleaner();
|
||||
@ -267,7 +267,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
||||
* Logs the scheduling status of this backup process.
|
||||
*/
|
||||
public void displayNextSchedule() {
|
||||
Log.info("[Backup] " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " next backup on "
|
||||
Log.info("[Backup] " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " next backup on "
|
||||
+ DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date(getNext())));
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
||||
public void logProgress() {
|
||||
if (compressor == null)
|
||||
return;
|
||||
Log.info("[Backup] " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + ": " + compressor.getState().getLegacyText());
|
||||
Log.info("[Backup] " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + ": " + compressor.getState().getLegacyText());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " ...");
|
||||
Log.info("[Backup] Starting for " + ChatColor.GRAY + getDisplayName() + ChatColor.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 " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET);
|
||||
Log.info("[Backup] Finished for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET);
|
||||
} catch (Exception e) {
|
||||
Log.severe("[Backup] Failed for : " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET, e);
|
||||
Log.severe("[Backup] Failed for : " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET, e);
|
||||
} finally {
|
||||
onBackupEnd(success);
|
||||
|
||||
|
@ -71,12 +71,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-bungee-chat</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-paper-permissions</artifactId>
|
||||
|
@ -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.get());
|
||||
inv = Bukkit.createInventory(null, nbLines * 9, title.getAdv());
|
||||
|
||||
setCloseEvent(closeEventAction);
|
||||
|
||||
|
@ -4,6 +4,7 @@ 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;
|
||||
@ -12,16 +13,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.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@ -298,17 +299,15 @@ public class PerformanceAnalysisManager implements Listener {
|
||||
|
||||
// keep the legacy text when generating the bar to save space when converting to component
|
||||
StringBuilder s = new StringBuilder();
|
||||
TextColor prevC = null;
|
||||
ChatColor prevC = ChatColor.RESET;
|
||||
for (int i = 58; i >= 0; i--) {
|
||||
int t = tpsHistory[i];
|
||||
TextColor newC = tps1sGradient.pickColorAt(t);
|
||||
ChatColor newC = ChatColorUtil.toBungee(tps1sGradient.pickColorAt(t));
|
||||
if (!newC.equals(prevC)) {
|
||||
s.append(text("|").color(newC).getLegacyText());
|
||||
s.append(newC);
|
||||
prevC = newC;
|
||||
}
|
||||
else {
|
||||
s.append("|");
|
||||
}
|
||||
s.append("|");
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class ItemStackBuilder {
|
||||
public ItemStackBuilder lore(List<? extends ComponentLike> lore) {
|
||||
if (lore != null) {
|
||||
return rawLore(lore.stream()
|
||||
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).get())
|
||||
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv())
|
||||
.toList());
|
||||
}
|
||||
else
|
||||
@ -128,7 +128,7 @@ public class ItemStackBuilder {
|
||||
Streams.concat(
|
||||
baseLore.stream(),
|
||||
lores.stream()
|
||||
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).get())
|
||||
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv())
|
||||
)
|
||||
.toList());
|
||||
}
|
||||
|
@ -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].get();
|
||||
cmpLines[i] = lines[i].getAdv();
|
||||
}
|
||||
updateScoreboardSidebar(scBrd, title.get(), cmpLines);
|
||||
updateScoreboardSidebar(scBrd, title.getAdv(), cmpLines);
|
||||
}
|
||||
|
||||
|
||||
@ -135,9 +135,9 @@ public class ScoreboardUtil {
|
||||
public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, List<Chat> lines) {
|
||||
Component[] cmpLines = new Component[lines.size()];
|
||||
for (int i = 0; i < cmpLines.length; i++) {
|
||||
cmpLines[i] = lines.get(i).get();
|
||||
cmpLines[i] = lines.get(i).getAdv();
|
||||
}
|
||||
updateScoreboardSidebar(scBrd, title.get(), cmpLines);
|
||||
updateScoreboardSidebar(scBrd, title.getAdv(), cmpLines);
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,10 +99,10 @@ public enum Skull {
|
||||
boolean b = meta.setOwner(name);
|
||||
|
||||
if (displayName != null)
|
||||
meta.displayName(displayName.get());
|
||||
meta.displayName(displayName.getAdv());
|
||||
|
||||
if (lore != null)
|
||||
meta.lore(lore.stream().map(Chat::get).collect(Collectors.toList()));
|
||||
meta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList()));
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
@ -172,10 +172,10 @@ public enum Skull {
|
||||
headMeta.setPlayerProfile(profile);
|
||||
|
||||
if (displayName != null)
|
||||
headMeta.displayName(displayName.get());
|
||||
headMeta.displayName(displayName.getAdv());
|
||||
|
||||
if (lore != null)
|
||||
headMeta.lore(lore.stream().map(Chat::get).collect(Collectors.toList()));
|
||||
headMeta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList()));
|
||||
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
|
@ -37,12 +37,6 @@
|
||||
<artifactId>javaluator</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,18 +1,5 @@
|
||||
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;
|
||||
@ -25,6 +12,19 @@ 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 java.util.stream.Collectors;
|
||||
Log.warning("For data " + dataType + ":\n"
|
||||
+ resolutionResult.toDisplayTreeNode().render(true).stream()
|
||||
.map(Chat::getLegacyText)
|
||||
.collect(Collectors.joining(LegacyChatFormat.RESET + "\n")));
|
||||
.collect(Collectors.joining(ChatColor.RESET + "\n")));
|
||||
}
|
||||
|
||||
return resolutionResult.result != null ? resolutionResult.result : "";
|
||||
@ -167,7 +167,7 @@ import java.util.stream.Collectors;
|
||||
if (result == null)
|
||||
c.then(Chat.text(" (non défini)").gray());
|
||||
else
|
||||
c.thenLegacyText(" \"" + LegacyChatFormat.RESET + result + LegacyChatFormat.RESET + "\"");
|
||||
c.thenLegacyText(" \"" + ChatColor.RESET + result + ChatColor.RESET + "\"");
|
||||
if (conflictMessage != null)
|
||||
c.thenFailure(" " + conflictMessage);
|
||||
ChatTreeNode node = new ChatTreeNode(c);
|
||||
@ -307,7 +307,7 @@ import java.util.stream.Collectors;
|
||||
Log.warning("For permission " + permission + ":\n"
|
||||
+ resolutionResult.toDisplayTreeNode().render(true).stream()
|
||||
.map(Chat::getLegacyText)
|
||||
.collect(Collectors.joining(LegacyChatFormat.RESET + "\n")));
|
||||
.collect(Collectors.joining(ChatColor.RESET + "\n")));
|
||||
}
|
||||
|
||||
return resolutionResult.result;
|
||||
@ -487,7 +487,7 @@ import java.util.stream.Collectors;
|
||||
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 ? NamedTextColor.GOLD : NamedTextColor.DARK_AQUA)
|
||||
.color(entity instanceof CachedPlayer ? ChatColor.GOLD : ChatColor.DARK_AQUA)
|
||||
);
|
||||
if (server != null)
|
||||
c.thenData(" s=" + server);
|
||||
@ -523,7 +523,7 @@ import java.util.stream.Collectors;
|
||||
public ChatTreeNode toDisplayTreeNode() {
|
||||
return new ChatTreeNode(Chat.chat()
|
||||
.then(result ? Chat.successText("✔") : Chat.failureText("✘"))
|
||||
.then(Chat.text(permission).color(type == PermType.WILDCARD ? NamedTextColor.YELLOW : type == PermType.SPECIAL ? NamedTextColor.LIGHT_PURPLE : NamedTextColor.WHITE)));
|
||||
.then(Chat.text(permission).color(type == PermType.WILDCARD ? ChatColor.YELLOW : type == PermType.SPECIAL ? ChatColor.LIGHT_PURPLE : ChatColor.WHITE)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,12 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency> -->
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -25,9 +25,9 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.plumelib</groupId>
|
||||
<artifactId>hashmap-util</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>32.1.2-jre</version> <!-- Match the version imported by Paper API/BungeeCord API if possible -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -47,7 +47,6 @@
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>io.github.classgraph:classgraph</include>
|
||||
<include>org.plumelib:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
@ -61,26 +60,6 @@
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>org.plumelib:hashmap-util</artifact>
|
||||
<excludes>
|
||||
<exclude>module-info.class</exclude>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>org.plumelib:reflection-util</artifact>
|
||||
<excludes>
|
||||
<exclude>module-info.class</exclude>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
@ -91,10 +70,6 @@
|
||||
<pattern>nonapi.io.github.classgraph</pattern>
|
||||
<shadedPattern>fr.pandacube.lib.reflect.shaded.classgraph.nonapi</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.plumelib</pattern>
|
||||
<shadedPattern>fr.pandacube.lib.reflect.shaded.plumelib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -1,7 +1,8 @@
|
||||
package fr.pandacube.lib.reflect.wrapper;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
||||
import fr.pandacube.lib.reflect.ReflectConstructor;
|
||||
import org.plumelib.util.WeakIdentityHashMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -16,10 +17,7 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
public abstract class ReflectWrapper implements ReflectWrapperI {
|
||||
|
||||
|
||||
private static final Map<Object, ReflectWrapperI> objectWrapperCache = new WeakIdentityHashMap<>();
|
||||
/*
|
||||
* WeakHashMap is not suitable because we want the keys to be compared by reference (==) and not by the .equals() method.
|
||||
*/
|
||||
private static final Map<Object, ReflectWrapperI> objectWrapperCache = new MapMaker().weakKeys().makeMap();
|
||||
|
||||
/**
|
||||
* Unwraps the object from the provided reflect wrapper.
|
||||
|
3
pom.xml
3
pom.xml
@ -58,13 +58,10 @@
|
||||
<bungeecord.version>1.21-R0.1-SNAPSHOT</bungeecord.version>
|
||||
<paper.version>1.20.6-R0.1</paper.version>
|
||||
<mc.version>1.20.6</mc.version>
|
||||
|
||||
<guava.version>32.1.2-jre</guava.version> <!-- Match the version imported by Paper API/BungeeCord API if possible -->
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>pandalib-bungee</module>
|
||||
<module>pandalib-bungee-chat</module>
|
||||
<module>pandalib-bungee-permissions</module>
|
||||
<module>pandalib-chat</module>
|
||||
<module>pandalib-cli</module>
|
||||
|
Loading…
Reference in New Issue
Block a user