Improved Chat API

This commit is contained in:
Marc Baloup 2021-08-29 00:56:57 +02:00
parent e721642780
commit c8b626f655
2 changed files with 46 additions and 26 deletions

View File

@ -218,26 +218,26 @@ public abstract class Chat extends ChatStatic implements HoverEventSource<Compon
public FormatableChat console(boolean c) { console = c; return this; }
public FormatableChat color(TextColor c) { builder.color(c); return this; }
public FormatableChat color(ChatColor c) { return color(TextColor.color(c.getColor().getRGB())); }
public FormatableChat color(Color c) { return color(TextColor.color(c.getRGB())); }
public FormatableChat color(String c) { return color(ChatColor.of(c)); }
public FormatableChat color(ChatColor c) { return color(c == null ? null : TextColor.color(c.getColor().getRGB())); }
public FormatableChat color(Color c) { return color(c == null ? null : TextColor.color(c.getRGB())); }
public FormatableChat color(String c) { return color(c == null ? null : ChatColor.of(c)); }
public FormatableChat black() { return color(ChatColor.BLACK); }
public FormatableChat darkBlue() { return color(ChatColor.DARK_BLUE); }
public FormatableChat darkGreen() { return color(ChatColor.DARK_GREEN); }
public FormatableChat darkAqua() { return color(ChatColor.DARK_AQUA); }
public FormatableChat darkRed() { return color(ChatColor.DARK_RED); }
public FormatableChat darkPurple() { return color(ChatColor.DARK_PURPLE); }
public FormatableChat gold() { return color(ChatColor.GOLD); }
public FormatableChat gray() { return color(ChatColor.GRAY); }
public FormatableChat darkGray() { return color(ChatColor.DARK_GRAY); }
public FormatableChat blue() { return color(ChatColor.BLUE); }
public FormatableChat green() { return color(ChatColor.GREEN); }
public FormatableChat aqua() { return color(ChatColor.AQUA); }
public FormatableChat red() { return color(ChatColor.RED); }
public FormatableChat lightPurple() { return color(ChatColor.LIGHT_PURPLE); }
public FormatableChat yellow() { return color(ChatColor.YELLOW); }
public FormatableChat white() { return color(ChatColor.WHITE); }
public FormatableChat black() { return color(NamedTextColor.BLACK); }
public FormatableChat darkBlue() { return color(NamedTextColor.DARK_BLUE); }
public FormatableChat darkGreen() { return color(NamedTextColor.DARK_GREEN); }
public FormatableChat darkAqua() { return color(NamedTextColor.DARK_AQUA); }
public FormatableChat darkRed() { return color(NamedTextColor.DARK_RED); }
public FormatableChat darkPurple() { return color(NamedTextColor.DARK_PURPLE); }
public FormatableChat gold() { return color(NamedTextColor.GOLD); }
public FormatableChat gray() { return color(NamedTextColor.GRAY); }
public FormatableChat darkGray() { return color(NamedTextColor.DARK_GRAY); }
public FormatableChat blue() { return color(NamedTextColor.BLUE); }
public FormatableChat green() { return color(NamedTextColor.GREEN); }
public FormatableChat aqua() { return color(NamedTextColor.AQUA); }
public FormatableChat red() { return color(NamedTextColor.RED); }
public FormatableChat lightPurple() { return color(NamedTextColor.LIGHT_PURPLE); }
public FormatableChat yellow() { return color(NamedTextColor.YELLOW); }
public FormatableChat white() { return color(NamedTextColor.WHITE); }
public FormatableChat successColor() { return color(config.successColor); }
public FormatableChat failureColor() { return color(config.failureColor); }

View File

@ -42,6 +42,7 @@ public class ChatUtil {
public static final int DEFAULT_CHAT_WIDTH = 320;
public static final int SIGN_WIDTH = 90;
public static final int BOOK_WIDTH = 116;
public static final int MOTD_WIDTH = 270;
public static final int CONSOLE_NB_CHAR_DEFAULT = 50;
@ -163,7 +164,7 @@ public class ChatUtil {
else
first = false;
FormatableChat pDisp = (FormatableChat) 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) {
pDisp.color(Chat.getConfig().highlightedCommandColor);
}
@ -182,14 +183,25 @@ public class ChatUtil {
public static Chat centerText(Chat text, char repeatedChar, TextColor decorationColor,
boolean console) {
return centerText(text, repeatedChar, decorationColor, console, console ? CONSOLE_NB_CHAR_DEFAULT : DEFAULT_CHAT_WIDTH);
}
/**
*
* @param text
* @param repeatedChar
* @param decorationColor support null values
* @param console
* @param maxWidth
* @return
*/
public static Chat centerText(Chat text, char repeatedChar, TextColor decorationColor,
boolean console, int maxWidth) {
int textWidth = componentWidth(text.getAdv(), console);
int maxWidth = (console) ? CONSOLE_NB_CHAR_DEFAULT : DEFAULT_CHAT_WIDTH;
if (textWidth > maxWidth)
return text;
@ -215,9 +227,13 @@ public class ChatUtil {
public static Chat leftText(Chat text, char repeatedChar, TextColor decorationColor, int nbLeft,
boolean console) {
return leftText(text, repeatedChar, decorationColor, nbLeft, console, console ? CONSOLE_NB_CHAR_DEFAULT : DEFAULT_CHAT_WIDTH);
}
public static Chat leftText(Chat text, char repeatedChar, TextColor decorationColor, int nbLeft,
boolean console, int maxWidth) {
int textWidth = componentWidth(text.getAdv(), console);
int maxWidth = (console) ? CONSOLE_NB_CHAR_DEFAULT : DEFAULT_CHAT_WIDTH;
int repeatedCharWidth = charW(repeatedChar, console, false);
int leftWidth = nbLeft * repeatedCharWidth;
@ -238,9 +254,13 @@ public class ChatUtil {
public static Chat rightText(Chat text, char repeatedChar, TextColor decorationColor, int nbRight,
boolean console) {
return rightText(text, repeatedChar, decorationColor, nbRight, console, console ? CONSOLE_NB_CHAR_DEFAULT : DEFAULT_CHAT_WIDTH);
}
public static Chat rightText(Chat text, char repeatedChar, TextColor decorationColor, int nbRight,
boolean console, int maxWidth) {
int textWidth = componentWidth(text.getAdv(), console);
int maxWidth = (console) ? CONSOLE_NB_CHAR_DEFAULT : DEFAULT_CHAT_WIDTH;
int repeatedCharWidth = charW(repeatedChar, console, false);
int rightWidth = nbRight * repeatedCharWidth;