Refactor PlayerManager API + little fixes in Chat API
This commit is contained in:
@@ -20,12 +20,6 @@
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
@@ -38,8 +38,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
protected boolean console = false;
|
||||
|
||||
/* package */ Chat(ComponentBuilder<?, ?> b) {
|
||||
Objects.requireNonNull(b, "Provided component builder must not be null");
|
||||
builder = b;
|
||||
builder = Objects.requireNonNull(b, "Provided component builder must not be null");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -3,18 +3,18 @@ package fr.pandacube.lib.chat;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
import fr.pandacube.lib.chat.Chat.FormatableChat;
|
||||
import fr.pandacube.lib.util.Log;
|
||||
|
||||
public abstract class ChatStatic {
|
||||
|
||||
|
||||
|
||||
public static FormatableChat chatComponent(Component c) {
|
||||
private static FormatableChat chatComponent(Component c) {
|
||||
return new FormatableChat(Chat.componentToBuilder(c));
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public abstract class ChatStatic {
|
||||
return new FormatableChat(Chat.componentToBuilder(Chat.toAdventure(c)));
|
||||
}
|
||||
|
||||
public static FormatableChat chatComponent(Chat c) {
|
||||
return chatComponent(c.getAdv());
|
||||
public static FormatableChat chatComponent(ComponentLike c) {
|
||||
return chatComponent(c.asComponent());
|
||||
}
|
||||
|
||||
public static FormatableChat chat() {
|
||||
@@ -34,26 +34,38 @@ public abstract class ChatStatic {
|
||||
return chatComponent(Chat.toAdventure(c));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Chat instance with the provided plain text as its main text content.
|
||||
*
|
||||
* @param plainText the text to use as he content of the new Chat instance.
|
||||
* @return a Chat instance with the provided text as its main text content.
|
||||
*
|
||||
* @throws IllegalArgumentException If the {@code plainText} parameter is instance of {@link Chat} or
|
||||
* {@link Component}. The caller should use {@link #chatComponent(ComponentLike)}
|
||||
* instead.
|
||||
*/
|
||||
public static FormatableChat text(Object plainText) {
|
||||
if (plainText instanceof Chat) {
|
||||
Log.warning("Using Chat instance as plain text. Please use proper API method. I’ll properly use your Chat instance this time...", new Throwable());
|
||||
return (FormatableChat) plainText;
|
||||
}
|
||||
if (plainText instanceof Component) {
|
||||
Log.warning("Using Component instance as plain text. Please use proper API method. I’ll properly use your Component this time...", new Throwable());
|
||||
return chatComponent((Component) plainText);
|
||||
if (plainText instanceof ComponentLike) {
|
||||
throw new IllegalArgumentException("Expected any object except instance of " + ComponentLike.class + ". Received " + plainText + ". Please use ChatStatic.chatComponent(ComponentLike) instead.");
|
||||
}
|
||||
return new FormatableChat(Component.text().content(Objects.toString(plainText)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Chat instance with the provided legacy text as its main text content.
|
||||
*
|
||||
* @param legacyText the text to use as he content of the new Chat instance.
|
||||
* @return a Chat instance with the provided text as its main text content.
|
||||
*
|
||||
* @throws IllegalArgumentException If the {@code plainText} parameter is instance of {@link Chat} or
|
||||
* {@link Component}. The caller should use {@link #chatComponent(ComponentLike)}
|
||||
* instead.
|
||||
*/
|
||||
public static FormatableChat legacyText(Object legacyText) {
|
||||
if (legacyText instanceof Chat) {
|
||||
Log.warning("Using Chat instance as legacy text. Please use proper API method. I’ll properly use your Chat instance this time...", new Throwable());
|
||||
return (FormatableChat) legacyText;
|
||||
}
|
||||
if (legacyText instanceof Component) {
|
||||
Log.warning("Using Component instance as legacy text. Please use proper API method. I’ll properly use your Component this time...", new Throwable());
|
||||
return chatComponent((Component) legacyText);
|
||||
if (legacyText instanceof ComponentLike) {
|
||||
throw new IllegalArgumentException("Expected any object except instance of " + ComponentLike.class + ". Received " + legacyText + ". Please use ChatStatic.chatComponent(ComponentLike) instead.");
|
||||
}
|
||||
return chatComponent(LegacyComponentSerializer.legacySection().deserialize(Objects.toString(legacyText)));
|
||||
}
|
||||
@@ -113,6 +125,21 @@ public abstract class ChatStatic {
|
||||
.objective(objective)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static Component prefixedAndColored(ComponentLike message) {
|
||||
return prefixedAndColored(Chat.chatComponent(message)).getAdv();
|
||||
}
|
||||
|
||||
public static Chat prefixedAndColored(Chat message) {
|
||||
return Chat.chat()
|
||||
.broadcastColor()
|
||||
.then(Chat.getConfig().prefix.get())
|
||||
.then(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user