LoChat/src/main/java/com/loki/lochat/config/MessageConfig.java
loki5512344 7f513a7104
port: replace Paper component APIs, chat pipeline, events and schedulers
- 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
2026-09-20 16:38:37 +02:00

108 lines
3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.loki.lochat.config;
import com.loki.lochat.compat.Msg;
import com.loki.lochat.LoChat;
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 java.io.File;
public class MessageConfig {
private final LoChat plugin;
private FileConfiguration messages;
public MessageConfig(LoChat plugin) {
this.plugin = plugin;
loadMessages();
}
private void loadMessages() {
File messagesFile = new File(plugin.getDataFolder(), "messages.yml");
if (!messagesFile.exists()) {
plugin.saveResource("messages.yml", false);
}
messages = YamlConfiguration.loadConfiguration(messagesFile);
}
public void reload() {
loadMessages();
}
public String get(String path) {
String message = messages.getString(path, "&#FF0000Message not found: " + path);
return ChatFormatter.convertAllColors(message);
}
public String get(String path, String... replacements) {
String message = messages.getString(path, "&#FF0000Message not found: " + path);
for (int i = 0; i < replacements.length - 1; i += 2) {
message = message.replace(replacements[i], replacements[i + 1]);
}
return ChatFormatter.convertAllColors(message);
}
/**
* Получает сообщение как Component
*/
public Component getComponent(String path) {
return ChatFormatter.parse(get(path));
}
/**
* Получает сообщение как Component с заменами
*/
public Component getComponent(String path, String... replacements) {
return ChatFormatter.parse(get(path, replacements));
}
/**
* Отправляет сообщение игроку
*/
public void send(CommandSender sender, String path) {
Msg.send(sender, getComponent(path));
}
/**
* Отправляет сообщение игроку с заменами
*/
public void send(CommandSender sender, String path, String... replacements) {
Msg.send(sender, getComponent(path, replacements));
}
// Shortcuts
public String getPrefix() {
return get("prefix");
}
public String getNoPermission() {
return get("errors.no-permission");
}
public String getPlayerNotFound() {
return get("errors.player-not-found");
}
public String getInvalidUsage(String usage) {
return get("errors.invalid-usage", "{usage}", usage);
}
// PM форматы
public String getPmFormatSent() {
return get("pm.format-sent");
}
public String getPmFormatReceived() {
return get("pm.format-received");
}
public boolean isPmUseGradientNames() {
return messages.getBoolean("pm.use-gradient-names", true);
}
}