Chat class is now sealed and easier usage of special colors

This commit is contained in:
Marc Baloup 2022-01-21 18:56:21 +01:00
parent 6a2f14ae39
commit 224d21a604
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
3 changed files with 10 additions and 6 deletions

View File

@ -34,7 +34,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
public abstract class Chat extends ChatStatic implements HoverEventSource<Component>, ComponentLike { public abstract sealed class Chat extends ChatStatic implements HoverEventSource<Component>, ComponentLike {
protected ComponentBuilder<?, ?> builder; protected ComponentBuilder<?, ?> builder;
protected boolean console = false; protected boolean console = false;
@ -244,6 +244,10 @@ public abstract class Chat extends ChatStatic implements HoverEventSource<Compon
public FormatableChat infoColor() { return color(config.infoColor); } public FormatableChat infoColor() { return color(config.infoColor); }
public FormatableChat dataColor() { return color(config.dataColor); } public FormatableChat dataColor() { return color(config.dataColor); }
public FormatableChat decorationColor() { return color(config.decorationColor); } public FormatableChat decorationColor() { return color(config.decorationColor); }
public FormatableChat urlColor() { return color(config.urlColor); }
public FormatableChat commandColor() { return color(config.commandColor); }
public FormatableChat highlightedCommandColor() { return color(config.highlightedCommandColor); }
public FormatableChat broadcastColor() { return color(config.broadcastColor); }
private FormatableChat setStyle(Consumer<Style.Builder> styleOp) { builder.style(styleOp); return this; } private FormatableChat setStyle(Consumer<Style.Builder> styleOp) { builder.style(styleOp); return this; }

View File

@ -65,7 +65,7 @@ public class ChatUtil {
String dispURL = (url.length() > 50) ? (url.substring(0, 48) + "...") : url; String dispURL = (url.length() > 50) ? (url.substring(0, 48) + "...") : url;
return (FormatableChat) chat() return (FormatableChat) chat()
.clickURL(url) .clickURL(url)
.color(Chat.getConfig().urlColor) .urlColor()
.hover( .hover(
hover != null ? hover : Chat.text(dispURL) hover != null ? hover : Chat.text(dispURL)
) )
@ -89,7 +89,7 @@ public class ChatUtil {
/* package */ static FormatableChat createCommandLink(Chat d, String commandWithSlash, Chat hoverText) { /* package */ static FormatableChat createCommandLink(Chat d, String commandWithSlash, Chat hoverText) {
FormatableChat c = chat() FormatableChat c = chat()
.clickCommand(commandWithSlash) .clickCommand(commandWithSlash)
.color(Chat.getConfig().commandColor); .commandColor();
if (hoverText != null) if (hoverText != null)
c.hover(hoverText); c.hover(hoverText);
return (FormatableChat) c.then(d); return (FormatableChat) c.then(d);
@ -114,7 +114,7 @@ public class ChatUtil {
/* package */ static FormatableChat createCommandSuggest(Chat d, String commandWithSlash, Chat hoverText) { /* package */ static FormatableChat createCommandSuggest(Chat d, String commandWithSlash, Chat hoverText) {
FormatableChat c = chat() FormatableChat c = chat()
.clickSuggest(commandWithSlash) .clickSuggest(commandWithSlash)
.color(Chat.getConfig().commandColor); .commandColor();
if (hoverText != null) if (hoverText != null)
c.hover(hoverText); c.hover(hoverText);
return (FormatableChat) c.then(d); return (FormatableChat) c.then(d);
@ -167,7 +167,7 @@ public class ChatUtil {
FormatableChat pDisp = createCommandLink(Integer.toString(page), String.format(cmdFormat, page), "Aller à la page " + page); FormatableChat pDisp = createCommandLink(Integer.toString(page), String.format(cmdFormat, page), "Aller à la page " + page);
if (page == currentPage) { if (page == currentPage) {
pDisp.color(Chat.getConfig().highlightedCommandColor); pDisp.highlightedCommandColor();
} }
d.then(pDisp); d.then(pDisp);

View File

@ -125,7 +125,7 @@ public abstract class IPlayerManager<OP extends IOnlinePlayer, OF extends IOffPl
public static Chat prefixedAndColored(Chat message) { public static Chat prefixedAndColored(Chat message) {
return Chat.chat() return Chat.chat()
.color(Chat.getConfig().broadcastColor) .broadcastColor()
.then(Chat.getConfig().prefix.get()) .then(Chat.getConfig().prefix.get())
.then(message); .then(message);
} }