- Msg.send/broadcast/actionBar/title/legacy/plain for all 58 files sendMessage replacements (plan step 3) - ChatEventListener: AsyncChatEvent->AsyncPlayerChatEvent, getRecipients filtering, manual render+Msg.send loop, HIGHEST|ignoreCancelled, nobodyHeard via Bukkit scheduler (step 4) - EnhancedChatRenderer: remove ChatRenderer/Audience, render(Player,Component,Component,Player), getLocale String, Msg.actionBar - PlayerEventListener: join/quit/death String API, getCustomName/getDisplayName legacy, Msg.broadcast - FoliaUtil: IS_FOLIA false, Bukkit scheduler only; AutoMessageManager BukkitTask - CustomCommandManager: reflective getCommandMap; other mechanical fixes (displayName, kick, inventory titles) - single universal jar (variant A) - loads on Spigot 1.20.1 and Paper
100 lines
3.1 KiB
Java
100 lines
3.1 KiB
Java
package com.loki.lochat.gradient.config;
|
||
|
||
import com.loki.lochat.compat.Msg;
|
||
|
||
import com.loki.lochat.utils.format.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;
|
||
|
||
import java.io.File;
|
||
import java.io.InputStream;
|
||
import java.io.InputStreamReader;
|
||
import java.nio.charset.StandardCharsets;
|
||
|
||
/**
|
||
* Сообщения градиентного модуля
|
||
*/
|
||
public class GradientMessages {
|
||
|
||
private final JavaPlugin plugin;
|
||
private FileConfiguration messages;
|
||
private File messagesFile;
|
||
|
||
public GradientMessages(JavaPlugin plugin) {
|
||
this.plugin = plugin;
|
||
loadMessages();
|
||
}
|
||
|
||
private void loadMessages() {
|
||
messagesFile = new File(plugin.getDataFolder(), "messages.yml");
|
||
if (!messagesFile.exists()) {
|
||
plugin.saveResource("messages.yml", false);
|
||
}
|
||
messages = YamlConfiguration.loadConfiguration(messagesFile);
|
||
|
||
InputStream defStream = plugin.getResource("messages.yml");
|
||
if (defStream != null) {
|
||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(
|
||
new InputStreamReader(defStream, StandardCharsets.UTF_8));
|
||
messages.setDefaults(defConfig);
|
||
}
|
||
}
|
||
|
||
public void reload() {
|
||
loadMessages();
|
||
}
|
||
|
||
/**
|
||
* Получает сообщение как строку с MiniMessage тегами
|
||
*/
|
||
public String get(String key) {
|
||
String message = messages.getString("gradient." + key, "&#FF0000Сообщение не найдено: " + key);
|
||
return ChatFormatter.convertAllColors(message);
|
||
}
|
||
|
||
/**
|
||
* Получает сообщение как строку с заменами
|
||
*/
|
||
public String get(String key, String... replacements) {
|
||
String message = messages.getString("gradient." + key, "&#FF0000Сообщение не найдено: " + key);
|
||
for (int i = 0; i < replacements.length; i += 2) {
|
||
if (i + 1 < replacements.length) {
|
||
message = message.replace("{" + replacements[i] + "}", replacements[i + 1]);
|
||
}
|
||
}
|
||
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) {
|
||
Msg.send(sender, getComponent(key));
|
||
}
|
||
|
||
/**
|
||
* Отправляет сообщение игроку с заменами
|
||
*/
|
||
public void send(CommandSender sender, String key, String... replacements) {
|
||
Msg.send(sender, getComponent(key, replacements));
|
||
}
|
||
}
|