Do not use bungeecord-chat as a dependency for pandalib-chat anymore
This commit is contained in:
parent
4be37945cb
commit
36eb1227cf
1
pandalib-bungee-chat/.gitignore
vendored
Normal file
1
pandalib-bungee-chat/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target/
|
49
pandalib-bungee-chat/pom.xml
Normal file
49
pandalib-bungee-chat/pom.xml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?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>
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.pandacube.lib</groupId>
|
<groupId>fr.pandacube.lib</groupId>
|
||||||
<artifactId>pandalib-chat</artifactId>
|
<artifactId>pandalib-bungee-chat</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.pandacube.lib.bungee.commands;
|
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 fr.pandacube.lib.commands.BrigadierDispatcher;
|
||||||
import net.kyori.adventure.text.ComponentLike;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
@ -71,6 +71,6 @@ public class BungeeBrigadierDispatcher extends BrigadierDispatcher<CommandSender
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendSenderMessage(CommandSender sender, ComponentLike message) {
|
protected void sendSenderMessage(CommandSender sender, ComponentLike message) {
|
||||||
sender.sendMessage(Chat.toBungee(message.asComponent()));
|
sender.sendMessage(ChatBungee.toBungee(message.asComponent()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.pandacube.lib.bungee.players;
|
package fr.pandacube.lib.bungee.players;
|
||||||
|
|
||||||
import fr.pandacube.lib.chat.Chat;
|
import fr.pandacube.lib.bungee.chat.ChatBungee;
|
||||||
import fr.pandacube.lib.core.mc_version.ProtocolVersion;
|
import fr.pandacube.lib.core.mc_version.ProtocolVersion;
|
||||||
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
||||||
import fr.pandacube.lib.reflect.Reflect;
|
import fr.pandacube.lib.reflect.Reflect;
|
||||||
@ -84,13 +84,13 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void sendMessage(Component message) {
|
default void sendMessage(Component message) {
|
||||||
getBungeeProxiedPlayer().sendMessage(Chat.toBungee(message));
|
getBungeeProxiedPlayer().sendMessage(ChatBungee.toBungee(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void sendTitle(Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
|
default void sendTitle(Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
|
||||||
ProxyServer.getInstance().createTitle()
|
ProxyServer.getInstance().createTitle()
|
||||||
.title(Chat.toBungee(title)).subTitle(Chat.toBungee(subtitle))
|
.title(ChatBungee.toBungee(title)).subTitle(ChatBungee.toBungee(subtitle))
|
||||||
.fadeIn(fadeIn).stay(stay).fadeOut(fadeOut)
|
.fadeIn(fadeIn).stay(stay).fadeOut(fadeOut)
|
||||||
.send(getBungeeProxiedPlayer());
|
.send(getBungeeProxiedPlayer());
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
<artifactId>adventure-text-serializer-gson</artifactId>
|
||||||
<version>4.3.0</version>
|
<version>4.13.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||||
|
<version>4.13.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
@ -46,13 +51,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>bungeecord-chat</artifactId>
|
|
||||||
<version>${bungeecord.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
|
@ -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;
|
||||||
import net.kyori.adventure.text.format.TextDecoration.State;
|
import net.kyori.adventure.text.format.TextDecoration.State;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
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.gson.GsonComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.UnaryOperator;
|
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.
|
* Builds the component into Adventure Component instance.
|
||||||
* @return the {@link Component} built from this {@link Chat} component.
|
* @return the {@link Component} built from this {@link Chat} component.
|
||||||
*/
|
*/
|
||||||
public Component getAdv() {
|
public Component get() {
|
||||||
return builder.build();
|
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()
|
private static final LegacyComponentSerializer LEGACY_SERIALIZER_BUNGEE_FRIENDLY = LegacyComponentSerializer.builder()
|
||||||
.hexColors()
|
.hexColors()
|
||||||
.useUnusualXRepeatedCharacterHexFormat()
|
.useUnusualXRepeatedCharacterHexFormat()
|
||||||
@ -97,7 +79,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
|||||||
* @return the legacy text. RGB colors are in BungeeCord format.
|
* @return the legacy text. RGB colors are in BungeeCord format.
|
||||||
*/
|
*/
|
||||||
public String getLegacyText() {
|
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.
|
* @return the plain text of this component.
|
||||||
*/
|
*/
|
||||||
public String getPlainText() {
|
public String getPlainText() {
|
||||||
return PlainTextComponentSerializer.plainText().serializeOr(getAdv(), "");
|
return PlainTextComponentSerializer.plainText().serializeOr(get(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull HoverEvent<Component> asHoverEvent(@NotNull UnaryOperator<Component> op) {
|
public @NotNull HoverEvent<Component> asHoverEvent(@NotNull UnaryOperator<Component> 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
|
@Override
|
||||||
public @NotNull Component asComponent() {
|
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.
|
* @return the {@link Component} built from this {@link Chat} component, with down-sampled colors.
|
||||||
*/
|
*/
|
||||||
public Component getAsDownSampledColorsComponent() {
|
public Component getAsDownSampledColorsComponent() {
|
||||||
String json = GsonComponentSerializer.colorDownsamplingGson().serialize(getAdv());
|
String json = GsonComponentSerializer.colorDownsamplingGson().serialize(get());
|
||||||
return GsonComponentSerializer.gson().deserialize(json);
|
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.
|
* @return the MiniMessage representation if this {@link Chat} component.
|
||||||
*/
|
*/
|
||||||
public String getMiniMessage() {
|
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;
|
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.
|
* Appends a component to this component.
|
||||||
* @param comp the component to append.
|
* @param comp the component to append.
|
||||||
@ -207,15 +180,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
|||||||
return then(comp.asComponent());
|
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)); }
|
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
|
* Appends a component filling a chat line with the configured decoration character and
|
||||||
* color and a right-aligned text.
|
* 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)); }
|
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
|
* Appends a component filling a chat line with the configured decoration character and
|
||||||
* color and a centered text.
|
* color and a centered text.
|
||||||
@ -537,19 +479,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
|||||||
return then(centerText(centerText, console));
|
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.
|
* 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.
|
* @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.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public FormatableChat color(TextColor c) { builder.color(c); 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.
|
* Sets the color of this component.
|
||||||
* @param c the color.
|
* @param c the color.
|
||||||
@ -646,7 +569,16 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
|||||||
* @param c the color.
|
* @param c the color.
|
||||||
* @return this.
|
* @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.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public FormatableChat hover(ComponentLike v) { return hover(v.asComponent()); }
|
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.
|
* Configure this component to show the provided legacy text when hovered.
|
||||||
* @param legacyText the legacy text to show.
|
* @param legacyText the legacy text to show.
|
||||||
@ -963,7 +883,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getAdv().hashCode();
|
return get().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -976,8 +896,6 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
|||||||
|
|
||||||
/* package */ static ComponentLike filterObjToComponentLike(Object v) {
|
/* package */ static ComponentLike filterObjToComponentLike(Object v) {
|
||||||
return switch (v) {
|
return switch (v) {
|
||||||
case BaseComponent[] baseComponents -> toAdventure(baseComponents);
|
|
||||||
case BaseComponent baseComponent -> toAdventure(baseComponent);
|
|
||||||
case ComponentLike componentLike -> componentLike;
|
case ComponentLike componentLike -> componentLike;
|
||||||
case null, default -> Component.text(Objects.toString(v));
|
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.
|
* 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;
|
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 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 {
|
public class ChatColorUtil {
|
||||||
|
|
||||||
@ -38,12 +38,12 @@ public class ChatColorUtil {
|
|||||||
int length = legacyText.length();
|
int length = legacyText.length();
|
||||||
|
|
||||||
for (int index = length - 2; index >= 0; index--) {
|
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
|
// detection of rgb color §x§0§1§2§3§4§5
|
||||||
String rgb;
|
String rgb;
|
||||||
if (index > 11
|
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'
|
||||||
|| legacyText.charAt(index - 11) == 'X')
|
|| legacyText.charAt(index - 11) == 'X')
|
||||||
&& HEX_COLOR_PATTERN.matcher(rgb = legacyText.substring(index - 12, index + 2)).matches()) {
|
&& HEX_COLOR_PATTERN.matcher(rgb = legacyText.substring(index - 12, index + 2)).matches()) {
|
||||||
@ -64,7 +64,7 @@ public class ChatColorUtil {
|
|||||||
|
|
||||||
// try detect non-rgb format
|
// try detect non-rgb format
|
||||||
char colorChar = legacyText.charAt(index + 1);
|
char colorChar = legacyText.charAt(index + 1);
|
||||||
ChatColor legacyColor = getChatColorByChar(colorChar);
|
LegacyChatFormat legacyColor = LegacyChatFormat.of(colorChar);
|
||||||
|
|
||||||
if (legacyColor != null) {
|
if (legacyColor != null) {
|
||||||
result.insert(0, legacyColor);
|
result.insert(0, legacyColor);
|
||||||
@ -83,15 +83,6 @@ public class ChatColorUtil {
|
|||||||
return result.toString();
|
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
|
* Translate the color code of the provided string, that uses the alt color char, to the {@code §} color code
|
||||||
* format.
|
* format.
|
||||||
* <p>
|
* <p>
|
||||||
* 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).
|
* 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
|
* 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)}).
|
* to component (see {@link Chat#legacyText(Object)}).
|
||||||
@ -112,7 +103,7 @@ public class ChatColorUtil {
|
|||||||
*/
|
*/
|
||||||
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
|
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
|
||||||
{
|
{
|
||||||
char colorChar = ChatColor.COLOR_CHAR;
|
char colorChar = LegacyChatFormat.COLOR_CHAR;
|
||||||
StringBuilder acc = new StringBuilder();
|
StringBuilder acc = new StringBuilder();
|
||||||
char[] b = textToTranslate.toCharArray();
|
char[] b = textToTranslate.toCharArray();
|
||||||
for ( int i = 0; i < b.length; i++ )
|
for ( int i = 0; i < b.length; i++ )
|
||||||
@ -180,7 +171,7 @@ public class ChatColorUtil {
|
|||||||
* @return the text fully italic.
|
* @return the text fully italic.
|
||||||
*/
|
*/
|
||||||
public static String forceItalic(String legacyText) {
|
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.
|
* @return the text fully bold.
|
||||||
*/
|
*/
|
||||||
public static String forceBold(String legacyText) {
|
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.
|
* @return the text fully underlined.
|
||||||
*/
|
*/
|
||||||
public static String forceUnderline(String legacyText) {
|
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.
|
* @return the text fully stroked through.
|
||||||
*/
|
*/
|
||||||
public static String forceStrikethrough(String legacyText) {
|
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.
|
* @return the text fully obfuscated.
|
||||||
*/
|
*/
|
||||||
public static String forceObfuscated(String legacyText) {
|
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
|
return format + legacyText
|
||||||
.replace(format.toString(), "") // remove previous tag to make the result cleaner
|
.replace(formatStr, "") // remove previous tag to make the result cleaner
|
||||||
.replaceAll("§([a-frA-FR\\d])", "§$1" + format);
|
.replaceAll("§([a-frA-FR\\d])", "§$1" + formatStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -243,40 +235,12 @@ public class ChatColorUtil {
|
|||||||
* @return the resulting text.
|
* @return the resulting text.
|
||||||
*/
|
*/
|
||||||
public static String resetToColor(String legacyText, String color) {
|
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.
|
* Create a color, interpolating between 2 colors.
|
||||||
* @param v0 the value corresponding to color {@code cc0}.
|
* @param v0 the value corresponding to color {@code cc0}.
|
||||||
|
@ -87,7 +87,7 @@ public class ChatConfig {
|
|||||||
*/
|
*/
|
||||||
public static int getPrefixWidth(boolean console) {
|
public static int getPrefixWidth(boolean console) {
|
||||||
Chat c;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fr.pandacube.lib.chat;
|
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.BlockNBTComponent;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentBuilder;
|
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.format.TextColor;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
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.
|
* 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));
|
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}.
|
* 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
|
* 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());
|
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,5 +1,17 @@
|
|||||||
package fr.pandacube.lib.chat;
|
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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -10,19 +22,6 @@ import java.util.Set;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.stream.Collectors;
|
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;
|
import static fr.pandacube.lib.chat.ChatStatic.chat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,7 +350,7 @@ public class ChatUtil {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
char c = legacyText.charAt(index);
|
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);
|
currentWord.append(c);
|
||||||
c = legacyText.charAt(++index);
|
c = legacyText.charAt(++index);
|
||||||
currentWord.append(c);
|
currentWord.append(c);
|
||||||
@ -482,7 +481,7 @@ public class ChatUtil {
|
|||||||
}
|
}
|
||||||
if (!row.isEmpty())
|
if (!row.isEmpty())
|
||||||
spacedRow.then(row.getLast());
|
spacedRow.then(row.getLast());
|
||||||
spacedRows.add(spacedRow.getAdv());
|
spacedRows.add(spacedRow.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return spacedRows;
|
return spacedRows;
|
||||||
@ -504,14 +503,14 @@ public class ChatUtil {
|
|||||||
*/
|
*/
|
||||||
public static Component customWidthSpace(int width, boolean console) {
|
public static Component customWidthSpace(int width, boolean console) {
|
||||||
if (console)
|
if (console)
|
||||||
return Chat.text(" ".repeat(width)).getAdv();
|
return Chat.text(" ".repeat(width)).get();
|
||||||
return switch (width) {
|
return switch (width) {
|
||||||
case 0, 1 -> Component.empty();
|
case 0, 1 -> Component.empty();
|
||||||
case 2 -> Chat.text(".").black().getAdv();
|
case 2 -> Chat.text(".").black().get();
|
||||||
case 3 -> Chat.text("`").black().getAdv();
|
case 3 -> Chat.text("`").black().get();
|
||||||
case 6 -> Chat.text(". ").black().getAdv();
|
case 6 -> Chat.text(". ").black().get();
|
||||||
case 7 -> Chat.text("` ").black().getAdv();
|
case 7 -> Chat.text("` ").black().get();
|
||||||
case 11 -> Chat.text("` ").black().getAdv();
|
case 11 -> Chat.text("` ").black().get();
|
||||||
default -> {
|
default -> {
|
||||||
int nbSpace = width / 4;
|
int nbSpace = width / 4;
|
||||||
int nbBold = width % 4;
|
int nbBold = width % 4;
|
||||||
@ -520,13 +519,13 @@ public class ChatUtil {
|
|||||||
if (nbBold > 0) {
|
if (nbBold > 0) {
|
||||||
yield Chat.text(" ".repeat(nbNotBold)).bold(false)
|
yield Chat.text(" ".repeat(nbNotBold)).bold(false)
|
||||||
.then(Chat.text(" ".repeat(nbBold)).bold(true))
|
.then(Chat.text(" ".repeat(nbBold)).bold(true))
|
||||||
.getAdv();
|
.get();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yield Chat.text(" ".repeat(nbNotBold)).bold(false).getAdv();
|
yield Chat.text(" ".repeat(nbNotBold)).bold(false).get();
|
||||||
}
|
}
|
||||||
else if (nbBold > 0) {
|
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 + ")");
|
throw new IllegalStateException("Should not be here (width=" + width + "; nbSpace=" + nbSpace + "; nbBold=" + nbBold + "; nbNotBold=" + nbNotBold + ")");
|
||||||
}
|
}
|
||||||
|
@ -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<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.chat.ChatTreeNode;
|
||||||
import fr.pandacube.lib.cli.CLIApplication;
|
import fr.pandacube.lib.cli.CLIApplication;
|
||||||
import fr.pandacube.lib.util.log.Log;
|
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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -192,7 +192,7 @@ public class CommandAdmin extends CLIBrigadierCommand {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private BaseComponent displayCurrentNode(CommandNode<CLICommandSender> node, boolean redirectTarget, CLICommandSender sender) {
|
private Component displayCurrentNode(CommandNode<CLICommandSender> node, boolean redirectTarget, CLICommandSender sender) {
|
||||||
if (node == null)
|
if (node == null)
|
||||||
throw new IllegalArgumentException("node must not be null");
|
throw new IllegalArgumentException("node must not be null");
|
||||||
FormatableChat d;
|
FormatableChat d;
|
||||||
|
@ -37,6 +37,12 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>${guava.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Cron expression interpreter -->
|
<!-- Cron expression interpreter -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.eitchnet</groupId>
|
<groupId>ch.eitchnet</groupId>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package fr.pandacube.lib.core.backup;
|
package fr.pandacube.lib.core.backup;
|
||||||
|
|
||||||
import fr.pandacube.lib.chat.Chat;
|
import fr.pandacube.lib.chat.Chat;
|
||||||
|
import fr.pandacube.lib.chat.LegacyChatFormat;
|
||||||
import fr.pandacube.lib.util.log.Log;
|
import fr.pandacube.lib.util.log.Log;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -107,14 +107,14 @@ public abstract class BackupCleaner implements UnaryOperator<TreeSet<LocalDateTi
|
|||||||
if (files == null)
|
if (files == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log.info("[Backup] Cleaning up backup directory " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + "...");
|
Log.info("[Backup] Cleaning up backup directory " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + "...");
|
||||||
|
|
||||||
TreeMap<LocalDateTime, File> datedFiles = new TreeMap<>();
|
TreeMap<LocalDateTime, File> datedFiles = new TreeMap<>();
|
||||||
|
|
||||||
for (String filename : files) {
|
for (String filename : files) {
|
||||||
File file = new File(archiveDir, filename);
|
File file = new File(archiveDir, filename);
|
||||||
if (!filename.matches("\\d{8}-\\d{6}\\.zip")) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public abstract class BackupCleaner implements UnaryOperator<TreeSet<LocalDateTi
|
|||||||
try {
|
try {
|
||||||
ldt = LocalDateTime.parse(dateTimeStr, BackupProcess.dateFileNameFormatter);
|
ldt = LocalDateTime.parse(dateTimeStr, BackupProcess.dateFileNameFormatter);
|
||||||
} catch (DateTimeParseException e) {
|
} catch (DateTimeParseException e) {
|
||||||
Log.warning("[Backup] " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + " Unable to parse file name to a date-time: " + filename, e);
|
Log.warning("[Backup] " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + " Unable to parse file name to a date-time: " + filename, e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public abstract class BackupCleaner implements UnaryOperator<TreeSet<LocalDateTi
|
|||||||
if (testOnly || oneDeleted)
|
if (testOnly || oneDeleted)
|
||||||
Log.warning(c.getLegacyText());
|
Log.warning(c.getLegacyText());
|
||||||
|
|
||||||
Log.info("[Backup] Backup directory " + ChatColor.GRAY + compressDisplayName + ChatColor.RESET + " cleaned.");
|
Log.info("[Backup] Backup directory " + LegacyChatFormat.GRAY + compressDisplayName + LegacyChatFormat.RESET + " cleaned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package fr.pandacube.lib.core.backup;
|
package fr.pandacube.lib.core.backup;
|
||||||
|
|
||||||
import fc.cron.CronExpression;
|
import fc.cron.CronExpression;
|
||||||
|
import fr.pandacube.lib.chat.LegacyChatFormat;
|
||||||
import fr.pandacube.lib.core.cron.CronScheduler;
|
import fr.pandacube.lib.core.cron.CronScheduler;
|
||||||
import fr.pandacube.lib.util.FileUtils;
|
import fr.pandacube.lib.util.FileUtils;
|
||||||
import fr.pandacube.lib.util.log.Log;
|
import fr.pandacube.lib.util.log.Log;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
@ -209,7 +209,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
|||||||
File sourceDir = getSourceDir();
|
File sourceDir = getSourceDir();
|
||||||
|
|
||||||
if (!sourceDir.exists()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
|||||||
onBackupStart();
|
onBackupStart();
|
||||||
|
|
||||||
new Thread(() -> {
|
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);
|
compressor = new ZipCompressor(sourceDir, target, 9, filter);
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
|||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
|
|
||||||
Log.info("[Backup] Finished for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET);
|
Log.info("[Backup] Finished for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BackupCleaner cleaner = getBackupCleaner();
|
BackupCleaner cleaner = getBackupCleaner();
|
||||||
@ -267,7 +267,7 @@ public abstract class BackupProcess implements Comparable<BackupProcess>, Runnab
|
|||||||
* Logs the scheduling status of this backup process.
|
* Logs the scheduling status of this backup process.
|
||||||
*/
|
*/
|
||||||
public void displayNextSchedule() {
|
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())));
|
+ 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() {
|
public void logProgress() {
|
||||||
if (compressor == null)
|
if (compressor == null)
|
||||||
return;
|
return;
|
||||||
Log.info("[Backup] " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + ": " + compressor.getState().getLegacyText());
|
Log.info("[Backup] " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + ": " + compressor.getState().getLegacyText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package fr.pandacube.lib.core.backup;
|
package fr.pandacube.lib.core.backup;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
import fr.pandacube.lib.chat.LegacyChatFormat;
|
||||||
import fr.pandacube.lib.util.log.Log;
|
import fr.pandacube.lib.util.log.Log;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -53,7 +53,7 @@ public class RotatedLogsBackupProcess extends BackupProcess {
|
|||||||
if (!getSourceDir().isDirectory())
|
if (!getSourceDir().isDirectory())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log.info("[Backup] Starting for " + ChatColor.GRAY + getDisplayName() + ChatColor.RESET + " ...");
|
Log.info("[Backup] Starting for " + LegacyChatFormat.GRAY + getDisplayName() + LegacyChatFormat.RESET + " ...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// wait a little after the log message above, in case the log file rotation has to be performed.
|
// 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;
|
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) {
|
} 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 {
|
} finally {
|
||||||
onBackupEnd(success);
|
onBackupEnd(success);
|
||||||
|
|
||||||
|
@ -71,6 +71,12 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>fr.pandacube.lib</groupId>
|
||||||
|
<artifactId>pandalib-bungee-chat</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.pandacube.lib</groupId>
|
<groupId>fr.pandacube.lib</groupId>
|
||||||
<artifactId>pandalib-paper-permissions</artifactId>
|
<artifactId>pandalib-paper-permissions</artifactId>
|
||||||
|
@ -38,7 +38,7 @@ public class GUIInventory implements Listener {
|
|||||||
if (title == null)
|
if (title == null)
|
||||||
inv = Bukkit.createInventory(null, nbLines * 9);
|
inv = Bukkit.createInventory(null, nbLines * 9);
|
||||||
else
|
else
|
||||||
inv = Bukkit.createInventory(null, nbLines * 9, title.getAdv());
|
inv = Bukkit.createInventory(null, nbLines * 9, title.get());
|
||||||
|
|
||||||
setCloseEvent(closeEventAction);
|
setCloseEvent(closeEventAction);
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
|||||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||||
import fr.pandacube.lib.chat.Chat;
|
import fr.pandacube.lib.chat.Chat;
|
||||||
import fr.pandacube.lib.chat.ChatColorGradient;
|
import fr.pandacube.lib.chat.ChatColorGradient;
|
||||||
import fr.pandacube.lib.chat.ChatColorUtil;
|
|
||||||
import fr.pandacube.lib.chat.ChatConfig.PandaTheme;
|
import fr.pandacube.lib.chat.ChatConfig.PandaTheme;
|
||||||
import fr.pandacube.lib.paper.PandaLibPaper;
|
import fr.pandacube.lib.paper.PandaLibPaper;
|
||||||
import fr.pandacube.lib.paper.players.PaperOffPlayer;
|
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;
|
||||||
import fr.pandacube.lib.paper.util.AutoUpdatedBossBar.BarUpdater;
|
import fr.pandacube.lib.paper.util.AutoUpdatedBossBar.BarUpdater;
|
||||||
import fr.pandacube.lib.players.standalone.AbstractPlayerManager;
|
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;
|
||||||
import fr.pandacube.lib.util.MemoryUtil.MemoryUnit;
|
import fr.pandacube.lib.util.MemoryUtil.MemoryUnit;
|
||||||
import fr.pandacube.lib.util.TimeUtil;
|
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;
|
||||||
import net.kyori.adventure.bossbar.BossBar.Color;
|
import net.kyori.adventure.bossbar.BossBar.Color;
|
||||||
import net.kyori.adventure.bossbar.BossBar.Overlay;
|
import net.kyori.adventure.bossbar.BossBar.Overlay;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
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.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
@ -299,16 +298,18 @@ public class PerformanceAnalysisManager implements Listener {
|
|||||||
|
|
||||||
// keep the legacy text when generating the bar to save space when converting to component
|
// keep the legacy text when generating the bar to save space when converting to component
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
ChatColor prevC = ChatColor.RESET;
|
TextColor prevC = null;
|
||||||
for (int i = 58; i >= 0; i--) {
|
for (int i = 58; i >= 0; i--) {
|
||||||
int t = tpsHistory[i];
|
int t = tpsHistory[i];
|
||||||
ChatColor newC = ChatColorUtil.toBungee(tps1sGradient.pickColorAt(t));
|
TextColor newC = tps1sGradient.pickColorAt(t);
|
||||||
if (!newC.equals(prevC)) {
|
if (!newC.equals(prevC)) {
|
||||||
s.append(newC);
|
s.append(text("|").color(newC).getLegacyText());
|
||||||
prevC = newC;
|
prevC = newC;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
s.append("|");
|
s.append("|");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class ItemStackBuilder {
|
|||||||
public ItemStackBuilder lore(List<? extends ComponentLike> lore) {
|
public ItemStackBuilder lore(List<? extends ComponentLike> lore) {
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
return rawLore(lore.stream()
|
return rawLore(lore.stream()
|
||||||
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv())
|
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).get())
|
||||||
.toList());
|
.toList());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -128,7 +128,7 @@ public class ItemStackBuilder {
|
|||||||
Streams.concat(
|
Streams.concat(
|
||||||
baseLore.stream(),
|
baseLore.stream(),
|
||||||
lores.stream()
|
lores.stream()
|
||||||
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv())
|
.map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).get())
|
||||||
)
|
)
|
||||||
.toList());
|
.toList());
|
||||||
}
|
}
|
||||||
|
@ -116,9 +116,9 @@ public class ScoreboardUtil {
|
|||||||
public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, Chat[] lines) {
|
public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, Chat[] lines) {
|
||||||
Component[] cmpLines = new Component[lines.length];
|
Component[] cmpLines = new Component[lines.length];
|
||||||
for (int i = 0; i < lines.length; i++) {
|
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<Chat> lines) {
|
public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, List<Chat> lines) {
|
||||||
Component[] cmpLines = new Component[lines.size()];
|
Component[] cmpLines = new Component[lines.size()];
|
||||||
for (int i = 0; i < cmpLines.length; i++) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,10 +99,10 @@ public enum Skull {
|
|||||||
boolean b = meta.setOwner(name);
|
boolean b = meta.setOwner(name);
|
||||||
|
|
||||||
if (displayName != null)
|
if (displayName != null)
|
||||||
meta.displayName(displayName.getAdv());
|
meta.displayName(displayName.get());
|
||||||
|
|
||||||
if (lore != null)
|
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);
|
itemStack.setItemMeta(meta);
|
||||||
return itemStack;
|
return itemStack;
|
||||||
@ -172,10 +172,10 @@ public enum Skull {
|
|||||||
headMeta.setPlayerProfile(profile);
|
headMeta.setPlayerProfile(profile);
|
||||||
|
|
||||||
if (displayName != null)
|
if (displayName != null)
|
||||||
headMeta.displayName(displayName.getAdv());
|
headMeta.displayName(displayName.get());
|
||||||
|
|
||||||
if (lore != null)
|
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);
|
head.setItemMeta(headMeta);
|
||||||
|
|
||||||
|
@ -37,6 +37,12 @@
|
|||||||
<artifactId>javaluator</artifactId>
|
<artifactId>javaluator</artifactId>
|
||||||
<version>3.0.3</version>
|
<version>3.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>${guava.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
package fr.pandacube.lib.permissions;
|
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.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -12,19 +25,6 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
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 {
|
/* package */ class PermissionsResolver {
|
||||||
|
|
||||||
private final PermissionsCachedBackendReader backendReader;
|
private final PermissionsCachedBackendReader backendReader;
|
||||||
@ -105,7 +105,7 @@ import fr.pandacube.lib.util.log.Log;
|
|||||||
Log.warning("For data " + dataType + ":\n"
|
Log.warning("For data " + dataType + ":\n"
|
||||||
+ resolutionResult.toDisplayTreeNode().render(true).stream()
|
+ resolutionResult.toDisplayTreeNode().render(true).stream()
|
||||||
.map(Chat::getLegacyText)
|
.map(Chat::getLegacyText)
|
||||||
.collect(Collectors.joining(ChatColor.RESET + "\n")));
|
.collect(Collectors.joining(LegacyChatFormat.RESET + "\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolutionResult.result != null ? resolutionResult.result : "";
|
return resolutionResult.result != null ? resolutionResult.result : "";
|
||||||
@ -167,7 +167,7 @@ import fr.pandacube.lib.util.log.Log;
|
|||||||
if (result == null)
|
if (result == null)
|
||||||
c.then(Chat.text(" (non défini)").gray());
|
c.then(Chat.text(" (non défini)").gray());
|
||||||
else
|
else
|
||||||
c.thenLegacyText(" \"" + ChatColor.RESET + result + ChatColor.RESET + "\"");
|
c.thenLegacyText(" \"" + LegacyChatFormat.RESET + result + LegacyChatFormat.RESET + "\"");
|
||||||
if (conflictMessage != null)
|
if (conflictMessage != null)
|
||||||
c.thenFailure(" " + conflictMessage);
|
c.thenFailure(" " + conflictMessage);
|
||||||
ChatTreeNode node = new ChatTreeNode(c);
|
ChatTreeNode node = new ChatTreeNode(c);
|
||||||
@ -307,7 +307,7 @@ import fr.pandacube.lib.util.log.Log;
|
|||||||
Log.warning("For permission " + permission + ":\n"
|
Log.warning("For permission " + permission + ":\n"
|
||||||
+ resolutionResult.toDisplayTreeNode().render(true).stream()
|
+ resolutionResult.toDisplayTreeNode().render(true).stream()
|
||||||
.map(Chat::getLegacyText)
|
.map(Chat::getLegacyText)
|
||||||
.collect(Collectors.joining(ChatColor.RESET + "\n")));
|
.collect(Collectors.joining(LegacyChatFormat.RESET + "\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolutionResult.result;
|
return resolutionResult.result;
|
||||||
@ -487,7 +487,7 @@ import fr.pandacube.lib.util.log.Log;
|
|||||||
Chat c = Chat.chat()
|
Chat c = Chat.chat()
|
||||||
.then(result == PermState.UNDEFINED ? Chat.dataText("■") : result == PermState.GRANTED ? Chat.successText("✔") : Chat.failureText("✘"))
|
.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)
|
.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)
|
if (server != null)
|
||||||
c.thenData(" s=" + server);
|
c.thenData(" s=" + server);
|
||||||
@ -523,7 +523,7 @@ import fr.pandacube.lib.util.log.Log;
|
|||||||
public ChatTreeNode toDisplayTreeNode() {
|
public ChatTreeNode toDisplayTreeNode() {
|
||||||
return new ChatTreeNode(Chat.chat()
|
return new ChatTreeNode(Chat.chat()
|
||||||
.then(result ? Chat.successText("✔") : Chat.failureText("✘"))
|
.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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,11 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>
|
<dependency>
|
||||||
<groupId>fr.pandacube.lib</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>pandalib-util</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${guava.version}</version>
|
||||||
<scope>provided</scope>
|
</dependency>
|
||||||
</dependency> -->
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
3
pom.xml
3
pom.xml
@ -58,10 +58,13 @@
|
|||||||
<bungeecord.version>1.21-R0.1-SNAPSHOT</bungeecord.version>
|
<bungeecord.version>1.21-R0.1-SNAPSHOT</bungeecord.version>
|
||||||
<paper.version>1.20.6-R0.1</paper.version>
|
<paper.version>1.20.6-R0.1</paper.version>
|
||||||
<mc.version>1.20.6</mc.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>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>pandalib-bungee</module>
|
<module>pandalib-bungee</module>
|
||||||
|
<module>pandalib-bungee-chat</module>
|
||||||
<module>pandalib-bungee-permissions</module>
|
<module>pandalib-bungee-permissions</module>
|
||||||
<module>pandalib-chat</module>
|
<module>pandalib-chat</module>
|
||||||
<module>pandalib-cli</module>
|
<module>pandalib-cli</module>
|
||||||
|
Loading…
Reference in New Issue
Block a user