Пример #1
0
 /// <summary>
 /// 初始化文件
 /// </summary>
 private static void initPlugin()
 {
     if (!Directory.Exists(BDSName))
     {
         Directory.CreateDirectory(BDSName);
     }
     if (!Directory.Exists(FolderName))
     {
         Directory.CreateDirectory(FolderName);
     }
     if (!Directory.Exists(MenuName))
     {
         Directory.CreateDirectory(MenuName);
     }
     if (!File.Exists(configFile))
     {
         initConfig();
     }
     if (!File.Exists(defaultFile))
     {
         initDefault();
     }
     try
     {
         config = JObject.Parse(File.ReadAllText(configFile));
         mcapi.setCommandDescribe("menu", "打开主菜单");
         foreach (JObject menu in config["menu"])
         {
             mcapi.setCommandDescribeEx((string)menu["command"], (string)menu["description"], (bool)config["admin"] ? MCCSAPI.CommandPermissionLevel.Admin : MCCSAPI.CommandPermissionLevel.Any, (byte)MCCSAPI.CommandCheatFlag.NotCheat, (byte)MCCSAPI.CommandVisibilityFlag.Visible);
         }
     }
     catch
     {
         Console.WriteLine("Menu >> 配置文件 config.json 读取失败!");
         Console.WriteLine("Menu >> 为了服务器的安全,已卸载本插件的所有功能,请重启服务器确保插件正常运行!");
         mcapi.removeAfterActListener(EventKey.onUseItem, UseItem);
         mcapi.removeAfterActListener(EventKey.onLoadName, PlayerJoin);
         mcapi.removeAfterActListener(EventKey.onPlayerLeft, PlayerLeft);
         mcapi.removeAfterActListener(EventKey.onFormSelect, FormSelect);
         mcapi.removeBeforeActListener(EventKey.onServerCmd, ServerCmd);
         mcapi.removeBeforeActListener(EventKey.onInputCommand, InputCommand);
         return;
     }
     try { Mdefault = JObject.Parse(File.ReadAllText(defaultFile)); }
     catch { Console.WriteLine("Menu >> 菜单文件 default.json 读取失败!"); }
 }