Переделал настройки цветов: /chatcolor теперь принимает &b формат, добавлена поддержка #RRGGBB в конфигах
This commit is contained in:
parent
c6442bc88f
commit
ee67dcc12a
4 changed files with 99 additions and 34 deletions
|
|
@ -11,12 +11,13 @@ import org.jetbrains.annotations.NotNull;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChatColorCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
private final LoChat plugin;
|
||||
private static final Pattern LEGACY_COLOR_PATTERN = Pattern.compile("^&([0-9a-fk-orA-FK-OR])$");
|
||||
|
||||
public ChatColorCommand(LoChat plugin) {
|
||||
this.plugin = plugin;
|
||||
|
|
@ -36,51 +37,51 @@ public class ChatColorCommand implements CommandExecutor, TabCompleter {
|
|||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().getInvalidUsage("/chatcolor <цвет>")));
|
||||
player.sendMessage(ChatFormatter.parse("<gray>Доступные цвета: <red>red</red>, <blue>blue</blue>, <green>green</green>, <yellow>yellow</yellow>, <gold>gold</gold>, <aqua>aqua</aqua>, <light_purple>light_purple</light_purple>, <white>white</white>, <gray>gray</gray>, <dark_gray>dark_gray</dark_gray>"));
|
||||
player.sendMessage(ChatFormatter.parse("<gray>Используйте Minecraft color codes: &a, &b, &c, &d, &e, &f, &0-&9, &k, &l, &m, &n, &o, &r</gray>"));
|
||||
player.sendMessage(ChatFormatter.parse("<gray>Пример: /chatcolor &b</gray>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
String color = args[0].toLowerCase();
|
||||
String color = args[0];
|
||||
|
||||
// Проверяем валидность цвета
|
||||
// Проверяем валидность цвета (формат &X где X - это цветовой код)
|
||||
if (!isValidColor(color)) {
|
||||
player.sendMessage(ChatFormatter.parse("<red>Неверный цвет! Используйте один из доступных цветов.</red>"));
|
||||
player.sendMessage(ChatFormatter.parse("<red>Неверный формат цвета! Используйте формат &X, например: &b, &a, &c</red>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Сохраняем цвет чата игрока
|
||||
plugin.getChatColorManager().setChatColor(player.getUniqueId(), color);
|
||||
player.sendMessage(ChatFormatter.parse("<green>Цвет чата установлен на <" + color + ">" + color + "</color>!"));
|
||||
|
||||
// Показываем пример с примененным цветом
|
||||
String preview = ChatFormatter.convertAllColors(color + "Пример текста");
|
||||
player.sendMessage(ChatFormatter.parse("<green>Цвет чата установлен! Пример: " + preview));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isValidColor(String color) {
|
||||
List<String> validColors = Arrays.asList(
|
||||
"red", "blue", "green", "yellow", "gold", "aqua",
|
||||
"light_purple", "white", "gray", "dark_gray", "black",
|
||||
"dark_red", "dark_green", "dark_blue", "dark_aqua", "dark_purple"
|
||||
);
|
||||
return validColors.contains(color);
|
||||
if (color == null || color.length() != 2) {
|
||||
return false;
|
||||
}
|
||||
if (!color.startsWith("&")) {
|
||||
return false;
|
||||
}
|
||||
char code = color.charAt(1);
|
||||
return (code >= '0' && code <= '9') ||
|
||||
(code >= 'a' && code <= 'f') ||
|
||||
(code >= 'A' && code <= 'F') ||
|
||||
code == 'k' || code == 'K' ||
|
||||
code == 'l' || code == 'L' ||
|
||||
code == 'm' || code == 'M' ||
|
||||
code == 'n' || code == 'N' ||
|
||||
code == 'o' || code == 'O' ||
|
||||
code == 'r' || code == 'R';
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> colors = Arrays.asList(
|
||||
"red", "blue", "green", "yellow", "gold", "aqua",
|
||||
"light_purple", "white", "gray", "dark_gray"
|
||||
);
|
||||
List<String> completions = new ArrayList<>();
|
||||
String input = args[0].toLowerCase();
|
||||
|
||||
for (String color : colors) {
|
||||
if (color.startsWith(input)) {
|
||||
completions.add(color);
|
||||
}
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
// Убираем автодополнение, так как теперь пользователь сам вводит цвет
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue