package cn.citycraft.AuthMe.settings;

import org.bukkit.command.CommandSender;

import cn.citycraft.AuthMe.AuthMe;
import cn.citycraft.AuthMe.ConsoleLogger;
import cn.citycraft.PluginHelper.config.FileConfig;

public class Messages {

	private static Messages singleton = null;
	private final FileConfig msgcfg;

	public Messages() {
		msgcfg = new FileConfig(AuthMe.getInstance(), "messages_zhcn.yml");
		singleton = this;
	}

	public static Messages getInstance() {
		if (singleton == null) {
			singleton = new Messages();
		}
		return singleton;
	}

	public String getString(final String string) {
		return msgcfg.getMessage(string);
	}

	public void reloadMessages() {
		msgcfg.reload();
	}

	public void send(final CommandSender sender, final String msg) {
		final String[] loc = send(msg);
		for (final String l : loc) {
			sender.sendMessage(l);
		}
	}

	public String[] send(final String msg) {
		String loc = msgcfg.getMessage(msg);
		if (loc == null || loc.isEmpty()) {
			loc = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
			ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !");
		}
		return loc.split("&n");
	}

}
