package org.black_ixx.bossshop.managers;

import org.black_ixx.bossshop.BossShop;
import org.bukkit.ChatColor;

import cc.util.bossshop.filemanager.ALangManager;

public class LangManager extends ALangManager{
    
    /**
     * 语言翻译系统
     * @param plugin
     */
    public LangManager(BossShop pplugin){
        super(pplugin,"messages.yml","1.1");
    }

    @Override
    public boolean reloadConfig(){
        if(!super.reloadConfig()) return false;
        this.checkUpdate();
        this.addDefaults();
        this.saveConfig();
        return false;
    }
    
    public boolean checkUpdate(){
        boolean update=super.checkUpdate();
        if(!update) return false;
        String tVersion=this.mConfig.getString(SEC_CFG_VERSION,"1.0");
        if(tVersion.equalsIgnoreCase("1.0")){// 1.0-->1.1
            tVersion="1.1";
            this.mConfig.set("Mail.MailMaxSaveNumb","====邮件最大保存数量[%numb%]====");
            String tMsg=this.mConfig.getString("Mail.YouReciveMailFrom");
            if(tMsg!=null){
                tMsg=tMsg.replace("你收到了来自","你收到了");
                this.mConfig.set("Mail.YouReciveMailFrom",null);
                this.mConfig.set("Mail.YouReciveMail",tMsg);
            }
        }
        this.mConfig.set(SEC_CFG_VERSION,this.mVersion);
        return true;
    }
    
    @Override
    public void addDefaults(){
        this.mConfig.addDefault("CFG.CannotCreatMailItem","&c无法创建邮件物品");
        this.mConfig.addDefault("CFG.UnableFoundSaleOwner","&c无法找到寄售商品的所有者");
        this.mConfig.addDefault("CFG.UnknowOutDateSaleItemType","&c未知的过期寄售物品类型");
        this.mConfig.addDefault("CFG.UnknowSalePriceType","&c未知的寄售价格类型,无法给寄售物品所有者所得");
        this.mConfig.addDefault("CFG.UnsupportMailItemType","&c不支持的邮件物品类型");
        this.mConfig.addDefault("CFG.UnsupportSaleItemParam","&c不支持的寄售物品变量设置");
        this.mConfig.addDefault("Cmd.AlreadyReloadShop","已经重载%shop%商店");
        this.mConfig.addDefault("Cmd.ClearedModelStatus","&c清理了%numb%个模块的状态");
        this.mConfig.addDefault("Cmd.ClearedNoUsefulNBT","共清理了%numb%个未被引用且自动生成的NBT库存");
        this.mConfig.addDefault("Cmd.ConfigReloacded","已经重载配置");
        this.mConfig.addDefault("Cmd.ConsoleNotAllow","&c控制台不能执行该命令");
        this.mConfig.addDefault("Cmd.ErrorHappedWhenHandlerCmd","&c插件在处理命令的时候发生了异常");
        this.mConfig.addDefault("Cmd.ForSaleSuccessAndTisID","&c寄售物品成功,寄售物品的编号是: ");
        this.mConfig.addDefault("Cmd.GetHelp","&c获取帮助");
        this.mConfig.addDefault("Cmd.ItemMayDonotHaveNBT","&c物品可能没有nbt信息");
        this.mConfig.addDefault("Cmd.LangReloacded","&2已经重载语言文件");
        this.mConfig.addDefault("Cmd.MustAboveZero","&c必须大于零");
        this.mConfig.addDefault("Cmd.MustBeNumb","&c必须为数字");
        this.mConfig.addDefault("Cmd.NBTHasExistInStockAndItsID","NBT已经存在在NBT库存中,它的ID是: ");
        this.mConfig.addDefault("Cmd.NBTHaveAddAndItsID","NBT已经添加到NBT库存,它的ID是: ");
        this.mConfig.addDefault("Cmd.NoPermission","&c你没有权限");
        this.mConfig.addDefault("Cmd.NoPlayerFound","&c未发现该玩家");
        this.mConfig.addDefault("Cmd.NoShopFound","&c未发现该商店");
        this.mConfig.addDefault("Cmd.OpenShopForPlayer","&2为玩家%player%开启商店%shop%");
        this.mConfig.addDefault("Cmd.PluginReloaded","已经重载插件");
        this.mConfig.addDefault("Cmd.SaleItemShouldNotSameWithPrice","&c寄售物品类型和价格类型不能相同");
        this.mConfig.addDefault("Cmd.SaleReachPreOneLimit","&c寄售商品已达个人寄售上线");
        this.mConfig.addDefault("Cmd.SaleShopIsFull","&c寄售商店寄售数量已经达到上限");
        this.mConfig.addDefault("Cmd.ServerDisablePoints","&c服务器不支持点券或未启用点券");
        this.mConfig.addDefault("Cmd.UnknowCommand","&c未知指令,输入/BossShop help 获取帮助");
        this.mConfig.addDefault("Cmd.UnknowPriceType","&c未知的价格类型");
        this.mConfig.addDefault("Cmd.UnknowSaleItemType","&c未知的寄售物品类型");
        this.mConfig.addDefault("Cmd.UnsupportPriceType","&c不支持的价格类型");
        this.mConfig.addDefault("Cmd.UnsupportSaleItemType","&c不支持的寄售物品类型");
        this.mConfig.addDefault("Cmd.YouHaveNotOutDateSaleItem","&c你没有过期的寄售物品");
        this.mConfig.addDefault("Cmd.YouSaleHasSellOne","你的寄售物品售出一份");
        this.mConfig.addDefault("Cmd.YouShouldTakeItemInHand","&c你的手上必须拿着物品");
        this.mConfig.addDefault("Cmd.unknowChildCommand","&c未知子命令指令");
        this.mConfig.addDefault("Console.ErrorCreateSaleFile","&c创建寄售商店文件是发生了错误");
        this.mConfig.addDefault("Console.ShopFileNotExist","&c商店配置文件不存在");
        this.mConfig.addDefault("Console.StartReloadShop","开始重载商店");
        this.mConfig.addDefault("Console.MissingNBTNode","&cNBT库丢失NBT节点");
        this.mConfig.addDefault("Economy.NoAccount","&c你还没有开户");
        this.mConfig.addDefault("Enchantment.Invalid","&c这个物品不能附这个魔");
        this.mConfig.addDefault("Help.ClearModelStatus","&2清理插件中一些模块的状态");
        this.mConfig.addDefault("Help.ClosePlayerShop","&2关闭玩家打开的BossShop商店");
        this.mConfig.addDefault("Help.HelpOpen","&2获取有关/BossShop open的帮助指令");
        this.mConfig.addDefault("Help.MailCheck","&2检查你的邮件列表");
        this.mConfig.addDefault("Help.MailHelp","&2获取邮件命令的帮助");
        this.mConfig.addDefault("Help.MailRevice","&2接受邮件中的物品");
        this.mConfig.addDefault("Help.MailSend","&2发送物品到玩家的邮箱");
        this.mConfig.addDefault("Help.NBTAdd","&2添加当前手上物品的NBT信息到NBT库存");
        this.mConfig.addDefault("Help.NBTClear","&2清理由插件自动生成且引用次数为0的NBT库存");
        this.mConfig.addDefault("Help.NBTHelp","&2获取有关/BossShop nbt 的帮助指令");
        this.mConfig.addDefault("Help.OpenOtherShop","&2为别人打开商店");
        this.mConfig.addDefault("Help.OpenShop","&2为自己打开商店");
        this.mConfig.addDefault("Help.Reload","&2重载BossShop配置");
        this.mConfig.addDefault("Help.ReloadConfig","&2重载插件主配置");
        this.mConfig.addDefault("Help.ReloadHelp","&2获取有关/BossShop reload的帮助指令");
        this.mConfig.addDefault("Help.ReloadLang","&2重载语言文件,部分语言可能无法更新");
        this.mConfig.addDefault("Help.ReloadShop","&2重载指定商店配置,商店名需要文件名");
        this.mConfig.addDefault("Help.SaleHelp","&2获取有关/BossShop sale 的帮助命令");
        this.mConfig.addDefault("Help.StartSaleWithChat","&2使用聊天栏开始图形化寄售");
        this.mConfig.addDefault("Help.StopSaleWithChat","&2退出聊天栏寄售");
        this.mConfig.addDefault("Help.SaleForsale","&2寄售物品");
        this.mConfig.addDefault("Help.SaleOther","&2其他参数均为整数");
        this.mConfig.addDefault("Help.SalePriceType","&2支持的价格类型 money,points");
        this.mConfig.addDefault("Help.SaleSellType","&2支持的售卖类型 item,money,points");
        this.mConfig.addDefault("Help.Unsale","&2下架指定编号的寄售物品");
        this.mConfig.addDefault("Lore.AlreadySoldOut","&c商品已经售罄");
        this.mConfig.addDefault("Lore.BuyIsNotTime","§c商品未到购买时间,将于%time%开放购买");
        this.mConfig.addDefault("Lore.EveryoneLimit","§2每人限购%numb%件,你还可以购买%left%件");
        this.mConfig.addDefault("Lore.GoodsOutOfDate","&c商品已经过了购买日期");
        this.mConfig.addDefault("Lore.GoodsStockLeft","&2库存剩余%numb%件!");
        this.mConfig.addDefault("Lore.NowCanBuyGoods","&2现在可以购买该商品");
        this.mConfig.addDefault("Lore.WillCloseInTime","&c将于%time%结束开放购买");
        this.mConfig.addDefault("Mail.FromOutDateSale","来自过期寄售");
        this.mConfig.addDefault("Mail.FromPlayer","来自玩家");
        this.mConfig.addDefault("Mail.FromUnknow","来自未知");
        this.mConfig.addDefault("Mail.MailHasSend","邮件已经发送");
        this.mConfig.addDefault("Mail.MailMaxSaveNumb","====邮件最大保存数量====");
        this.mConfig.addDefault("Mail.NoPermitToCreateSignShop","没有权限创建牌子商店");
        this.mConfig.addDefault("Mail.NoPermitToOpenSignShop","没有权限打开牌子商店");
        this.mConfig.addDefault("Mail.PlayerMailIsFull","&c玩家[%player%]的邮箱已经满了");
        this.mConfig.addDefault("Mail.YouCannotSendMailToYouSelf","&c你不能给自己发邮件");
        this.mConfig.addDefault("Mail.YouHaveNoMail","你没有任何邮件");
        this.mConfig.addDefault("Mail.YouMailIsFull","&c你的邮箱已经满了");
        this.mConfig.addDefault("Mail.YouNeed%%MoneyToSendMail","&c你需要%numb%的金币来发送邮件");
        this.mConfig.addDefault("Mail.YouReciveMail","你收到了%where%的邮件,输入/BS mail check查看");
        this.mConfig.addDefault("Main.AlreadyBought","&c这东西你已经买过了");
        this.mConfig.addDefault("Main.AlreadyClosePlayerShop","&2已经关闭玩家商店");
        this.mConfig.addDefault("Main.AlreadySoldOut","&c商品已经售罄");
        this.mConfig.addDefault("Main.CannotBuyYourselfGoods","&c你不能购买自己的寄售物品");
        this.mConfig.addDefault("Main.CloseShop","&6下次再来??");
        this.mConfig.addDefault("Main.ErrorHappend","&c商店发生了一点小错误,请通知管理员");
        this.mConfig.addDefault("Main.FromHandUnsale","来自手动下架");
        this.mConfig.addDefault("Main.GoodsNotArriveTime","&c商品未到购买时间");
        this.mConfig.addDefault("Main.GoodsOutOfDate","&c商品已经过了购买时间");
        this.mConfig.addDefault("Main.ItemCannotPileMoreThan","&c此物品的堆叠数量不能超过");
        this.mConfig.addDefault("Main.NoPermitToBuyThisItem","&c你没有权限购买该物品");
        this.mConfig.addDefault("Main.NoPlayerFound","&c未找到该玩家");
        this.mConfig.addDefault("Main.NoSaleItemFound","&c未找到该寄售物品");
        this.mConfig.addDefault("Main.OpenShop","&6开启小店");
        this.mConfig.addDefault("Main.OutOfPersonalLimit","&c已经达到个人购买物品数量上限");
        this.mConfig.addDefault("Main.PlayerNotOpenBSShop","&c玩家没有打开BossShop商店");
        this.mConfig.addDefault("Main.PlayerOffline","&c玩家未在线");
        this.mConfig.addDefault("Main.PlayerSaleItem","&2玩家%player_name%寄售了%item%");
        this.mConfig.addDefault("Main.SuccessUnsaleItem","成功下架寄售物品");
        this.mConfig.addDefault("Main.YouCannotUnsaleOther","&c你不能下架别人的寄售的物品");
        this.mConfig.addDefault("Main.YouClickTooQuick","&c你点击的太快了");
        this.mConfig.addDefault("Main.YouNeed%%MoneyToUnsale","&c你需要%numb%的金币来下架物品");
        this.mConfig.addDefault("Main.YouTodayCannotUnsaleMore","&c你今天已经不能再下架更多物品了");
        this.mConfig.addDefault("NotEnough.Exp","&c你的经验太少了");
        this.mConfig.addDefault("NotEnough.Item","&c兑换需要的物品不足");
        this.mConfig.addDefault("NotEnough.Money","&c你钱不够了");
        this.mConfig.addDefault("NotEnough.Points","&c你点券不足");
        this.mConfig.addDefault("Sale.ChatSaleStart","你已经进入寄售物品状态,输入/BS sale stop 来退出");
        this.mConfig.addDefault("Sale.ChatSaleRepartStart","&c你已经开始寄售了,请勿重复开始");
        this.mConfig.addDefault("Sale.ChatSaleExit","你已经退出聊天栏寄售");
        this.mConfig.addDefault("Sale.ChatSaleFinish","你已经设置所有寄售参数");
        this.mConfig.addDefault("Sale.NowSaleParameter","当前寄售参数(§6可以重复使用)");
        this.mConfig.addDefault("Sale.NowSaleParameterColor","&a");
        this.mConfig.addDefault("Sale.ClickSaleButtonFor","点击寄售按钮来进行");
        this.mConfig.addDefault("Sale.YouSetSaleParamTo","&a你设置了%param%为%value%");
        this.mConfig.addDefault("Sale.IntroduceSellType","点击选择你要寄售的商品类型: ");
        this.mConfig.addDefault("Sale.IntroduceSingleNumb","请输入你要寄售物品每份的数量: ");
        this.mConfig.addDefault("Sale.IntroducePartNumb","请输入你要寄售物品的份数: ");
        this.mConfig.addDefault("Sale.IntroducePriceType","点击选择购买商品的支付方式: ");
        this.mConfig.addDefault("Sale.IntroducePrice","请输入每份商品的价格: ");
        this.mConfig.addDefault("Sale.IntroduceSingleNumb","请输入你要寄售物品每份的数量: ");
        this.mConfig.addDefault("Word.All","所有");
        this.mConfig.addDefault("Word.Count","个");
        this.mConfig.addDefault("Word.ForSale","寄售");
        this.mConfig.addDefault("Word.GoTo","前往");
        this.mConfig.addDefault("Word.Input","输入");
        this.mConfig.addDefault("Word.Item","物品");
        this.mConfig.addDefault("Word.Money","金币");
        this.mConfig.addDefault("Word.PartNumb","份数");
        this.mConfig.addDefault("Word.PlayerName","玩家名");
        this.mConfig.addDefault("Word.Points","点券");
        this.mConfig.addDefault("Word.Price","价格");
        this.mConfig.addDefault("Word.PriceType","价格类型");
        this.mConfig.addDefault("Word.Revive","接收");
        this.mConfig.addDefault("Word.SaleID","物品编号");
        this.mConfig.addDefault("Word.SaleShop","寄售商店");
        this.mConfig.addDefault("Word.SellType","寄售类型");
        this.mConfig.addDefault("Word.ShopName","商店名称");
        this.mConfig.addDefault("Word.SigleNumb","每份数量");
        this.mConfig.addDefault("Word.YouBought","你购买了");
        this.mConfig.options().copyDefaults(true);
    }
    
    /**
     * 获取消息节点(不做替换)
     * @param node
     * @return
     */
    public String get(String node){
        if(!this.mConfig.contains(node)){
            this.mPlugin.warn("missing language node(丢失语言节点)["+node+"]");
            return node;
        }
        return ChatColor.translateAlternateColorCodes('&',this.mConfig.getString(node,node));
    }

}
