Помощь с перегрузкой - messages.yml

Baraban4ik

Разработчик
Пользователь
Сообщения
297
Решения
1
Я хочу перезагрузить messages.yml командой
Java:
package com.specter.stem.msg;

import java.io.File;
import java.io.InputStreamReader;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

public class MessageFile {
    private FileConfiguration config = null;

    public MessageFile(String name) {
        this.config = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(name)));
    }

    public MessageFile(File file) {
        this.config = YamlConfiguration.loadConfiguration(file);
    }

    public FileConfiguration getConfig() {
        return this.config;
    }

    public String get(String key) {
        return this.config.getString(key);
    }
}
Java:
package com.specter.stem.msg;

import java.io.File;
import org.bukkit.ChatColor;

public class MessageFormatter {
    private final MessageFile messageFile;

    public MessageFormatter() {
        this.messageFile = new MessageFile(new File("plugins" + File.separator + "Stem", "messages.yml"));
    }

    public String format(String key, Object... args) {
        return this.format(true, key, args);
    }

    public String format(boolean prefix, String key, Object... args) {
        String message = prefix ? this.messageFile.get("prefix") + this.messageFile.get(key) : this.messageFile.get(key);

        return ChatColor.translateAlternateColorCodes('&', message);
    }

    public String prefix(String msg) {
        return ChatColor.translateAlternateColorCodes('&', this.messageFile.get("prefix") + msg);
    }

    public MessageFile getMessageFile() {
        return this.messageFile;
    }
}
 
Назад
Сверху Снизу