Fix MiniMessage color parsing in commands - Added send() method to GradientMessages for proper Component parsing - Updated all gradient commands to use msg.send() instead of player.sendMessage(msg.get()) - Now <#RRGGBB> tags are properly converted to colors in chat

This commit is contained in:
loki5512344 2025-12-30 21:59:33 +01:00
parent 29ae373554
commit d2c45b3f0c
5 changed files with 89 additions and 53 deletions

View file

@ -1,6 +1,8 @@
package com.loki.lochat.gradient.config;
import com.loki.lochat.utils.ChatFormatter;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
@ -43,11 +45,17 @@ public class GradientMessages {
loadMessages();
}
/**
* Получает сообщение как строку с MiniMessage тегами
*/
public String get(String key) {
String message = messages.getString(key, "&#FF0000Сообщение не найдено: " + key);
return ChatFormatter.convertAllColors(message);
}
/**
* Получает сообщение как строку с заменами
*/
public String get(String key, String... replacements) {
String message = messages.getString(key, "&#FF0000Сообщение не найдено: " + key);
for (int i = 0; i < replacements.length; i += 2) {
@ -57,4 +65,32 @@ public class GradientMessages {
}
return ChatFormatter.convertAllColors(message);
}
/**
* Получает сообщение как Component
*/
public Component getComponent(String key) {
return ChatFormatter.parse(get(key));
}
/**
* Получает сообщение как Component с заменами
*/
public Component getComponent(String key, String... replacements) {
return ChatFormatter.parse(get(key, replacements));
}
/**
* Отправляет сообщение игроку
*/
public void send(CommandSender sender, String key) {
sender.sendMessage(getComponent(key));
}
/**
* Отправляет сообщение игроку с заменами
*/
public void send(CommandSender sender, String key, String... replacements) {
sender.sendMessage(getComponent(key, replacements));
}
}