Exemplo n.º 1
0
        /// <summary>
        /// 开始超时监听
        /// </summary>
        public void startTimeout()
        {
            Thread t = new Thread(() => {
                Thread.Sleep(timeout);
                if (!canceled)
                {
                    mapi.releaseForm(id);
                    mapi.removeBeforeActListener(EventKey.onFormSelect, fmcb);
                    if (ontimeout != null)
                    {
                        ontimeout();
                    }
                }
            });

            t.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 玩家选择按钮后执行的事件
        /// </summary>
        /// <param name="name">玩家名称</param>
        /// <param name="menuX">按钮相关信息</param>
        private static void Menu_Do(string name, JObject menuX)
        {
            string uuid = Function.getUuid(name),
                   command = (string)menuX["command"], path = string.Format(menuFile, command), type = (string)menuX["type"];
            bool isX = Function.Admin(Function.getXuid(name)),
                 defaultX = false, temporary = false, op = false,
                 cmd = false, MENU = false, AMenu = false;

            if (type == "default")
            {
                defaultX = true;
            }
            if (type == "temporary")
            {
                temporary = true;
                if (!isX)
                {
                    mcapi.runcmd($"op \"{name}\"");
                }
            }
            if (type == "operator")
            {
                if (!isX)
                {
                    uint failed = mcapi.sendModalForm(uuid, "菜单管理", "你没有权限执行该命令! ", "确定", "取消");
                    Thread.Sleep(timeout);
                    mcapi.releaseForm(failed);
                    return;
                }
                op = true;
            }
            if (type == "cmd")
            {
                cmd     = true;
                command = command.Replace("@s", $"\"{name}\"").Replace("@p", $"\"{name}\"");
            }
            if (type == "menu")
            {
                if (File.Exists(path))
                {
                    try { menu = JObject.Parse(File.ReadAllText(path)); }
                    catch
                    {
                        Console.WriteLine("Menu >> 配置文件 {0}.json 读取失败!", command);
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Menu >> 未找到配置文件 {0}.json,请自行生成!", command);
                    return;
                }
                MENU = true;
            }
            if (type == "AMenu")
            {
                if (!isX)
                {
                    uint failed = mcapi.sendModalForm(uuid, "菜单管理", "你没有权限打开该菜单! ", "确定", "取消");
                    Thread.Sleep(timeout);
                    mcapi.releaseForm(failed);
                    return;
                }
                if (File.Exists(path))
                {
                    try { menu = JObject.Parse(File.ReadAllText(path)); }
                    catch
                    {
                        Console.WriteLine("Menu >> 配置文件 {0}.json 读取失败!", command);
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Menu >> 未找到配置文件 {0}.json,请自行生成!", command);
                    return;
                }
                AMenu = true;
            }
            if ((defaultX || temporary || op) && !cmd && !MENU && !AMenu)
            {
                Thread.Sleep(200);
                mcapi.runcmdAs(uuid, $"/{command}");
                if (temporary && !isX)
                {
                    Thread.Sleep(500);
                    mcapi.runcmd($"deop \"{name}\"");
                }
            }
            else if (cmd)
            {
                mcapi.runcmd(command);
            }
            else if (MENU || AMenu)
            {
                Menu_Open(name);
            }
        }