示例#1
0
        // 获取uuid
        public static string getUUUD(string name)
        {
            string uuid;

            if (nameuuids.TryGetValue(name, out uuid))
            {
                return(uuid);
            }
            // 重载在线列表
            nameuuids.Clear();
            string ols = mapi.getOnLinePlayers();

            if (!string.IsNullOrEmpty(ols))
            {
                var       ser = new JavaScriptSerializer();
                ArrayList ol  = ser.Deserialize <ArrayList>(ols);
                foreach (Dictionary <string, object> d in ol)
                {
                    object tname, tuuid;
                    if (d.TryGetValue("playername", out tname))
                    {
                        if (d.TryGetValue("uuid", out tuuid))
                        {
                            nameuuids[tname.ToString()] = tuuid.ToString();
                            if (tname.ToString() == name)
                            {
                                uuid = tuuid.ToString();
                            }
                        }
                    }
                }
            }
            return(uuid);
        }
示例#2
0
        public static void OnTick(object source, System.Timers.ElapsedEventArgs e)
        {
            //时钟TICK到时间后被执行
            //Console.WriteLine("["+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"]Tick被执行");
            if (Profile.NeedPlayerBakcup)
            {
                if (!HavePlayer)            //如果没有玩家来过
                {
                    return;
                }

                //如果备份的时候没有玩家在线则将表示改为false
                string player = Mapi.getOnLinePlayers();
                if (string.IsNullOrEmpty(player))
                {
                    player = "[]";
                }

                /*
                 * // 没有玩家时输出空字符串,有玩家时输出JSON数组
                 * if (string.IsNullOrEmpty(player) || player.Trim() == "[]")
                 * {
                 *  HavePlayer = false;
                 *  //Console.WriteLine("DEBUG:当前服务器没有玩家");
                 * }
                 */
                if (Tools.Data.JSON.parse <List <dynamic> >(player).Count == 0)
                {
                    HavePlayer = false;
                }
            }

            StartBackup();
        }
示例#3
0
        public static void init(MCCSAPI api)
        {
            mcapi = api;
            Console.OutputEncoding = Encoding.UTF8;
            // 后台指令监听
            api.addBeforeActListener(EventKey.onServerCmd, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var se = BaseEvent.getFrom(x) as ServerCmdEvent;
                if (se != null)
                {
                    Console.WriteLine("后台指令={0}", se.cmd);
                }
                return(true);
            });
            // 后台指令输出监听
            api.addBeforeActListener(EventKey.onServerCmdOutput, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var se = BaseEvent.getFrom(x) as ServerCmdOutputEvent;
                if (se != null)
                {
                    Console.WriteLine("后台指令输出={0}", se.output);
                }
                return(true);
            });
            // 使用物品监听
            api.addAfterActListener(EventKey.onUseItem, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as UseItemEvent;
                if (ue != null && ue.RESULT)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处使用了 {5} 物品。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.itemname);
                }
                return(true);
            });
            // 放置方块监听
            api.addAfterActListener(EventKey.onPlacedBlock, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as PlacedBlockEvent;
                if (ue != null && ue.RESULT)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处放置了 {5} 方块。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 破坏方块监听
            api.addBeforeActListener(EventKey.onDestroyBlock, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as DestroyBlockEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 试图在 {1} 的 ({2}, {3}, {4})" +
                                      " 处破坏 {5} 方块。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 开箱监听
            api.addBeforeActListener(EventKey.onStartOpenChest, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StartOpenChestEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 试图在 {1} 的 ({2}, {3}, {4})" +
                                      " 处打开 {5} 箱子。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 开桶监听
            api.addBeforeActListener(EventKey.onStartOpenBarrel, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StartOpenBarrelEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 试图在 {1} 的 ({2}, {3}, {4})" +
                                      " 处打开 {5} 木桶。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 关箱监听
            api.addAfterActListener(EventKey.onStopOpenChest, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StopOpenChestEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处关闭 {5} 箱子。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 关桶监听
            api.addAfterActListener(EventKey.onStopOpenBarrel, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StopOpenBarrelEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处关闭 {5} 木桶。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 放入取出监听
            api.addAfterActListener(EventKey.onSetSlot, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as SetSlotEvent;
                if (e != null)
                {
                    if (e.itemcount > 0)
                    {
                        Console.WriteLine("玩家 {0} 在 {1} 槽放入了 {2} 个 {3} 物品。",
                                          e.playername, e.slot, e.itemcount, e.itemname);
                    }
                    else
                    {
                        Console.WriteLine("玩家 {0} 在 {1} 槽取出了物品。",
                                          e.playername, e.slot);
                    }
                }
                return(true);
            });
            // 切换维度监听
            api.addAfterActListener(EventKey.onChangeDimension, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as ChangeDimensionEvent;
                if (e != null && e.RESULT)
                {
                    Console.WriteLine("玩家 {0} {1} 切换维度至 {2} 的 ({3},{4},{5}) 处。",
                                      e.playername, e.isstand?"":"悬空地", e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z);
                }
                return(true);
            });
            // 生物死亡监听
            api.addAfterActListener(EventKey.onMobDie, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as MobDieEvent;
                if (e != null && !string.IsNullOrEmpty(e.mobname))
                {
                    Console.WriteLine(" {0} 在 {1} ({2:F2},{3:F2},{4:F2}) 处被 {5} 杀死了。",
                                      e.mobname, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z, e.srcname);
                }
                return(true);
            });
            // 生物伤害监听
            api.addBeforeActListener(EventKey.onMobHurt, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as MobHurtEvent;
                if (e != null && !string.IsNullOrEmpty(e.mobname))
                {
                    Console.WriteLine(" {0} 在 {1} ({2:F2},{3:F2},{4:F2}) 即将受到来自 {5} 的 {6} 点伤害,类型 {7}",
                                      e.mobname, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z, e.srcname, e.dmcount, e.dmtype);
                }
                return(true);
            });
            // 玩家重生监听
            api.addAfterActListener(EventKey.onRespawn, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as RespawnEvent;
                if (e != null && e.RESULT)
                {
                    Console.WriteLine("玩家 {0} 已于 {1} 的 ({2:F2},{3:F2},{4:F2}) 处重生。",
                                      e.playername, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z);
                }
                return(true);
            });
            // 聊天监听
            api.addAfterActListener(EventKey.onChat, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as ChatEvent;
                if (e != null)
                {
                    Console.WriteLine(" {0} {1} 说:{2}", e.playername,
                                      !string.IsNullOrEmpty(e.target) ? "悄悄地对 " + e.target : "", e.msg);
                }
                return(true);
            });
            // 输入文本监听
            api.addBeforeActListener(EventKey.onInputText, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as InputTextEvent;
                if (e != null)
                {
                    Console.WriteLine(" <{0}> {1}", e.playername, e.msg);
                }
                return(true);
            });
            // 更新命令方块监听
            api.addBeforeActListener(EventKey.onCommandBlockUpdate, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as CommandBlockUpdateEvent;
                if (e != null)
                {
                    Console.WriteLine(" {0} 试图修改位于 {1} ({2},{3},{4}) 的 {5} 的命令为 {6}",
                                      e.playername, e.dimension, e.position.x, e.position.y, e.position.z,
                                      e.isblock ? "命令块" : "命令矿车", e.cmd);
                }
                return(true);
            });
            // 输入指令监听
            api.addBeforeActListener(EventKey.onInputCommand, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as InputCommandEvent;
                if (e != null)
                {
                    Console.WriteLine(" <{0}> {1}", e.playername, e.cmd);
                }
                return(true);
            });
            // 命令块执行指令监听,拦截
            api.addBeforeActListener(EventKey.onBlockCmd, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as BlockCmdEvent;
                if (e != null)
                {
                    Console.WriteLine("位于 {0} ({1},{2},{3}) 的 {4} 试图执行指令 {5}",
                                      e.dimension, e.position.x, e.position.y, e.position.z, e.name, e.cmd);
                }
                return(false);
            });
            // NPC执行指令监听,拦截
            api.addBeforeActListener(EventKey.onNpcCmd, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as NpcCmdEvent;
                if (e != null)
                {
                    Console.WriteLine("位于 {0} ({1},{2},{3}) 的 {4} 试图执行第 {5} 条指令,指令集\n{6}",
                                      e.dimension, e.position.x, e.position.y, e.position.z, e.npcname, e.actionid, e.actions);
                }
                return(false);
            });
            // 世界范围爆炸监听,拦截
            api.addBeforeActListener(EventKey.onLevelExplode, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as LevelExplodeEvent;
                if (e != null)
                {
                    Console.WriteLine("位于 {0} ({1},{2},{3}) 的 {4} 试图发生强度 {5} 的爆炸。",
                                      e.dimension, e.position.x, e.position.y, e.position.z,
                                      string.IsNullOrEmpty(e.entity) ? e.blockname : e.entity, e.explodepower);
                }
                return(false);
            });

            /*
             * // 玩家移动监听
             * api.addAfterActListener(EventKey.onMove, x => {
             *      var e = BaseEvent.getFrom(x) as MoveEvent;
             *      if (e != null) {
             *              Console.WriteLine("玩家 {0} {1} 移动至 {2} ({3},{4},{5}) 处。",
             *                      e.playername, (e.isstand) ? "":"悬空地", e.dimension,
             *                      e.XYZ.x, e.XYZ.y, e.XYZ.z);
             *      }
             *      return false;
             * });
             */
            // 玩家加入游戏监听
            api.addAfterActListener(EventKey.onLoadName, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as LoadNameEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 加入了游戏,xuid={1}", ue.playername, ue.xuid);
                }
                return(true);
            });
            // 玩家离开游戏监听
            api.addAfterActListener(EventKey.onPlayerLeft, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as PlayerLeftEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 离开了游戏,xuid={1}", ue.playername, ue.xuid);
                }
                return(true);
            });

            // 攻击监听
            // API 方式注册监听器
            api.addAfterActListener(EventKey.onAttack, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                AttackEvent ae = BaseEvent.getFrom(x) as AttackEvent;
                if (ae != null)
                {
                    string str = "玩家 " + ae.playername + " 在 (" + ae.XYZ.x.ToString("F2") + "," +
                                 ae.XYZ.y.ToString("F2") + "," + ae.XYZ.z.ToString("F2") + ") 处攻击了 " + ae.actortype + " 。";
                    Console.WriteLine(str);
                    //Console.WriteLine("list={0}", api.getOnLinePlayers());
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    ArrayList al             = ser.Deserialize <ArrayList>(api.getOnLinePlayers());
                    object uuid = null;
                    foreach (Dictionary <string, object> p in al)
                    {
                        object name;
                        if (p.TryGetValue("playername", out name))
                        {
                            if ((string)name == ae.playername)
                            {
                                // 找到
                                p.TryGetValue("uuid", out uuid);
                                break;
                            }
                        }
                    }
                    if (uuid != null)
                    {
                        api.sendSimpleForm((string)uuid,
                                           "致命选项",
                                           "test choose:",
                                           "[\"生存\",\"死亡\",\"求助\"]");
                        //api.transferserver((string)uuid, "www.xiafox.com", 19132);
                    }
                }
                else
                {
                    Console.WriteLine("Event convent fail.");
                }
                return(true);
            });

            // Json 解析部分 使用JavaScriptSerializer序列化Dictionary或array即可

            //JavaScriptSerializer ser = new JavaScriptSerializer();
            //var data = ser.Deserialize<Dictionary<string, object>>("{\"x\":9}");
            //var ary = ser.Deserialize<ArrayList>("[\"x\",\"y\"]");
            //Console.WriteLine(data["x"]);
            //foreach(string v in ary) {
            //	Console.WriteLine(v);
            //}
            //data["y"] = 8;
            //string dstr = ser.Serialize(data);
            //Console.WriteLine(dstr);

            // 高级玩法,硬编码方式注册hook
            THook.init(api);
        }
示例#4
0
        public static void tpaa(MCCSAPI api)
        {
            api.setCommandDescribe("homegui", "打开homegui");
            api.setCommandDescribe("tpato", "传送到一个玩家");
            api.setCommandDescribe("tpac", "同游传送请求");
            api.setCommandDescribe("tpde", "拒绝传送请求");
            api.setCommandDescribe("tpapb", "改变tpa屏蔽状态");
            api.setCommandDescribe("tpagui", "打开tpagui");
            api.setCommandDescribe("homeadd", "添加一个私人传送点");
            api.setCommandDescribe("homedel", "删除一个私人传送点");
            api.setCommandDescribe("homego", "前往一个私人传送点");
            api.setCommandDescribe("back", "返回上一个死亡点");
            Dictionary <string, string> uuid     = new Dictionary <string, string>(); //uuid
            Dictionary <string, string> tpa_pb   = new Dictionary <string, string>(); //tpa屏蔽状态
            Dictionary <string, string> tpa_dx   = new Dictionary <string, string>(); //tpa对象
            Dictionary <string, string> tpa_ys   = new Dictionary <string, string>(); //tpa延时用
            Dictionary <string, string> tpa_gui  = new Dictionary <string, string>(); //记录guiid
            Dictionary <string, string> guils    = new Dictionary <string, string>(); //gui类型
            Dictionary <string, string> back_x   = new Dictionary <string, string>(); //backx
            Dictionary <string, string> back_y   = new Dictionary <string, string>(); //backy
            Dictionary <string, string> back_z   = new Dictionary <string, string>(); //backz
            Dictionary <string, int>    back_did = new Dictionary <string, int>();    //back维度
            ArrayList onlineplayer = new ArrayList();                                 //在线玩家
            int       tpa_yx       = 30000;
            string    __back       = "true";
            string    home_max     = "5";

            if (File.Exists("./config/tpa.txt"))
            {
                try
                {
                    string[] config = File.ReadAllLines("./config/tpa.txt", System.Text.Encoding.Default);
                    tpa_yx   = int.Parse(config[0].Substring(12));
                    __back   = config[1].Substring(12);
                    home_max = config[2].Substring(14);
                    Console.WriteLine("[TPA]配置文件读取成功!");
                }
                catch { Console.WriteLine("[TPA]配置文件读取失败!"); }
            }
            else
            {
                Directory.CreateDirectory("config/");
                File.AppendAllText("./config/tpa.txt", "玩家tpa请求有效时间:30000\n是否开启/back功能:true\n玩家设置home的最大数量:5", System.Text.Encoding.Default);
                Console.WriteLine("[TPA]未检查到配置文件!将自动创建!");
            }
            api.addAfterActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                guils.Add(a.playername, "other");
                onlineplayer.Add(a.playername);
                if (tpa_pb.ContainsKey(a.playername) == false)
                {
                    tpa_pb.Add(a.playername, "no");
                }
                try
                {
                    tpa_dx.Add(a.playername, "cxk");
                    tpa_gui.Add(a.playername, "a");
                    tpa_ys.Add(a.playername, "0");
                    back_x.Add(a.playername, string.Empty);
                    back_y.Add(a.playername, string.Empty);
                    back_z.Add(a.playername, string.Empty);
                    back_did.Add(a.playername, 0);
                }
                catch { Console.WriteLine("warn!!!!"); }
                return(true);
            });
            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                bool re = true;
                var a   = BaseEvent.getFrom(x) as InputCommandEvent;
                if (a.cmd.StartsWith("/tpato"))
                {
                    string tpatoplayername = string.Empty;
                    re = false;
                    try
                    {
                        if (tpa_ys[a.playername] == "0")
                        {
                            tpatoplayername = a.cmd.Substring(7);
                            if (api.getOnLinePlayers().IndexOf(tpatoplayername) != -1 || tpatoplayername.Length > 5)
                            {
                                if (tpa_pb[tpatoplayername] == "no")
                                {
                                    api.runcmd("tellraw \"" + tpatoplayername + "\" {\"rawtext\":[{\"text\":\"玩家" + a.playername + "向您发送了一个传送请求,/tpac接受,/tpde拒绝\"}]}");
                                    tpa_ys[a.playername]     = "1";
                                    tpa_dx[tpatoplayername]  = a.playername;
                                    tpa_gui[tpatoplayername] = api.sendModalForm(uuid[tpatoplayername], "TPA请求", "玩家" + a.playername + "向您发送了一个传送请求", "同意", "拒绝").ToString();
                                    Task taskkk = Task.Run(async() =>
                                    {
                                        await Task.Delay(30000);
                                        if (tpa_ys[a.playername] == "1")
                                        {
                                            tpa_ys[a.playername] = "0";
                                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"tpa请求超时\"}]}");
                                            tpa_dx[tpatoplayername] = "cxk";
                                        }
                                    });
                                }
                                else
                                {
                                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"对方屏蔽了tpa请求\"}]}");
                                }
                            }
                            else
                            {
                                api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"tpa请求发送失败,请检查您输入的指令\"}]}");
                            }
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"您有另一个tpa正在进行中!\"}]}");
                        }
                    }

                    catch
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"tpa请求发送失败,请检查您输入的指令\"}]}");
                        Console.WriteLine("warn!");
                    }
                }
                if (a.cmd.StartsWith("/tpapb"))
                {
                    re = false;
                    if (tpa_pb[a.playername] == "yes")
                    {
                        tpa_pb[a.playername] = "no";
                    }
                    else
                    {
                        tpa_pb[a.playername] = "yes";
                    }
                }
                if (a.cmd.StartsWith("/tpac"))
                {
                    re = false;
                    if (tpa_dx[a.playername] != "cxk")
                    {
                        api.runcmd("tp \"" + a.playername + "\" " + tpa_dx[a.playername]);
                        tpa_ys[tpa_dx[a.playername]] = "0";
                        tpa_dx[a.playername]         = "cxk";
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"没有人向你发送传送请求!\"}]}");
                    }
                }
                if (a.cmd.StartsWith("/tpde"))
                {
                    re = false;
                    if (tpa_dx[a.playername] != "cxk")
                    {
                        api.runcmd("tellraw \"" + tpa_dx[a.playername] + "\" {\"rawtext\":[{\"text\":\"对方拒绝了您的传送请求\"}]}");
                        tpa_ys[tpa_dx[a.playername]] = "0";
                        tpa_dx[a.playername]         = "cxk";
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"没有人向你发送传送请求!\"}]}");
                    }
                }
                if (a.cmd.StartsWith("/tpagui"))
                {
                    re            = false;
                    string online = "[\"";
                    foreach (string p in onlineplayer)
                    {
                        online = online + "\",\"" + p;
                    }
                    online = online + "\"]";
                    online = "[" + online.Substring(4);
                    api.sendCustomForm(uuid[a.playername], "{\"content\":[{\"type\":\"label\",\"text\":\"这个一个TPAGUI喵\"},{\"default\":0,\"options\":" + online + ",\"type\":\"dropdown\",\"text\":\"请选择一个玩家\"}], \"type\":\"custom_form\",\"title\":\"TPAGUI\"}").ToString();
                    guils[a.playername] = "fz";
                }
                if (__back == "true")
                {
                    if (a.cmd.StartsWith("/back") && a.cmd.EndsWith("/back"))
                    {
                        re = false;
                        if (back_x[a.playername] != string.Empty)
                        {
                            api.teleport(uuid[a.playername], Convert.ToSingle(back_x[a.playername]), Convert.ToSingle(back_y[a.playername]), Convert.ToSingle(back_z[a.playername]), back_did[a.playername]);
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"命令已执行\"}]}");
                            back_x[a.playername] = string.Empty;
                            back_y[a.playername] = string.Empty;
                            back_z[a.playername] = string.Empty;
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"未找到死亡点!\"}]}");
                        }
                    }
                }
                if (a.cmd.StartsWith("/homeadd "))
                {
                    re = false;
                    if (File.Exists("./data/tpa/" + a.playername + ".txt"))
                    {
                        if (File.ReadAllLines("./data/tpa/" + a.playername + ".txt").Length < int.Parse(home_max))
                        {
                            File.AppendAllText("./data/tpa/" + a.playername + ".txt", a.cmd.Substring(9) + "-" + a.XYZ.x + " " + a.XYZ.y + " " + a.XYZ.z + "\n");
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"您设置的home数量已达到上限!\"}]}");
                        }
                    }
                    else
                    {
                        Directory.CreateDirectory("./data/tpa");
                        File.AppendAllText("./data/tpa/" + a.playername + ".txt", a.cmd.Substring(9) + "-" + a.XYZ.x + " " + a.XYZ.y + " " + a.XYZ.z + "\n");
                    }
                }
                if (a.cmd == "/homegui")
                {
                    re = false;
                    if (File.Exists("./data/tpa/" + a.playername + ".txt"))
                    {
                        string[] lines = File.ReadAllLines("./data/tpa/" + a.playername + ".txt");
                        if (lines.Length != 0)
                        {
                            string homes = "[";
                            foreach (string line in lines)
                            {
                                Console.WriteLine(line);
                                homes = homes + "\"" + line.Substring(0, line.IndexOf("-")) + "\"" + ",";
                            }
                            homes = homes.Substring(0, homes.Length - 1) + "]";
                            api.sendCustomForm(uuid[a.playername], "{\"content\":[{\"type\":\"label\",\"text\":\"这个一个Thomegui\"},{\"default\":0,\"options\":" + homes + ",\"type\":\"dropdown\",\"text\":\"请选择一个家\"}], \"type\":\"custom_form\",\"title\":\"HOMEGUI\"}").ToString();
                            guils[a.playername] = "homegui";
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"您还没有任何家!\"}]}");
                        }
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"您还没有任何家!\"}]}");
                    }
                }
                if (a.cmd.StartsWith("/homego "))
                {
                    re        = false;
                    string tz = a.cmd.Substring(8);
                    if (File.Exists("./data/tpa/" + a.playername + ".txt"))
                    {
                        byte bbb = 1;
                        foreach (string line in File.ReadAllLines("./data/tpa/" + a.playername + ".txt"))
                        {
                            if (line.StartsWith(tz))
                            {
                                bbb = 0;
                                api.runcmd("tp \"" + a.playername + "\" " + line.Substring(tz.Length + 1));
                                break;
                            }
                        }
                        if (bbb == 1)
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"未找到该名称的home点!\"}]}");
                        }
                    }
                }
                if (a.cmd.StartsWith("/homedel "))
                {
                    re = false;
                    if (File.Exists("./data/tpa/" + a.playername + ".txt"))
                    {
                        string[] lines = File.ReadAllLines("./data/tpa/" + a.playername + ".txt", System.Text.Encoding.Default);
                        if (lines.Length != 0)
                        {
                            ArrayList ol = new ArrayList();
                            foreach (string line in lines)
                            {
                                ol.Add(line);
                                if (line.StartsWith(a.cmd.Substring(9)))
                                {
                                    ol.Remove(line);
                                }
                            }
                            if (ol.Count == lines.Length)
                            {
                                api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"未找到该名字的home点\"}]}");
                            }
                            else
                            {
                                File.Delete("./data/tpa/" + a.playername + ".txt");
                                File.AppendAllLines("./data/tpa/" + a.playername + ".txt", (string[])ol.ToArray(typeof(string)));
                                api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"该home点已删除!\"}]}");
                            }
                        }
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"您还没有任何home点\"}]}");
                    }
                }
                return(re);
            });
            api.addAfterActListener(EventKey.onMobDie, x =>
            {
                var a = BaseEvent.getFrom(x) as MobDieEvent;
                if (a.mobtype == "entity.player.name")
                {
                    try
                    {
                        back_x[a.playername]   = a.XYZ.x.ToString();
                        back_y[a.playername]   = a.XYZ.y.ToString();
                        back_z[a.playername]   = a.XYZ.z.ToString();
                        back_did[a.playername] = a.dimensionid;
                    }
                    catch { }
                }
                return(true);
            });
            api.addAfterActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playername);
                guils.Remove(a.playername);
                onlineplayer.Remove(a.playername);
                tpa_dx.Remove(a.playername);
                tpa_gui.Remove(a.playername);
                tpa_ys.Remove(a.playername);
                back_x.Remove(a.playername);
                back_y.Remove(a.playername);
                back_z.Remove(a.playername);
                return(true);
            });
            api.addAfterActListener(EventKey.onFormSelect, x =>
            {
                var a = BaseEvent.getFrom(x) as FormSelectEvent;
                if (guils[a.playername] == "homegui")
                {
                    int ssss       = Convert.ToInt32(a.selected.Substring(6, a.selected.Length - 7));
                    string[] lines = File.ReadAllLines("./data/tpa/" + a.playername + ".txt");
                    api.runcmd("tp " + a.playername + " " + lines[ssss].Substring(lines[ssss].IndexOf("-") + 1));
                }
                if (guils[a.playername] == "fz")
                {
                    if (tpa_ys[a.playername] == "0")
                    {
                        String tpatoplayername;
                        tpatoplayername = onlineplayer[int.Parse(a.selected.Substring(6, 1))].ToString();
                        if (api.getOnLinePlayers().IndexOf(tpatoplayername) != -1 && tpatoplayername.Length > 5)
                        {
                            if (tpa_pb[tpatoplayername] == "no")
                            {
                                api.runcmd("tellraw \"" + tpatoplayername + "\" {\"rawtext\":[{\"text\":\"玩家" + a.playername + "向您发送了一个传送请求,/tpac接受,/tpde拒绝\"}]}");
                                tpa_ys[a.playername]     = "1";
                                tpa_dx[tpatoplayername]  = a.playername;
                                tpa_gui[tpatoplayername] = api.sendModalForm(uuid[tpatoplayername], "TPA请求", "玩家" + a.playername + "向您发送了一个传送请求", "同意", "拒绝").ToString();
                                guils[a.playername]      = "jd";
                                Task taskkk = Task.Run(async() =>
                                {
                                    await Task.Delay(tpa_yx);
                                    if (tpa_ys[a.playername] == "1")
                                    {
                                        tpa_ys[a.playername] = "0";
                                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"tpa请求超时\"}]}");
                                        tpa_dx[tpatoplayername] = "cxk";
                                    }
                                });
                            }
                            else
                            {
                                api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"对方屏蔽了tpa请求\"}]}");
                            }
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"tpa请求发送失败,请检查您输入的指令\"}]}");
                        }
                    }
                }
                if (guils[a.playername] == "jd")
                {
                    if (a.selected == "true")
                    {
                        if (tpa_dx[a.playername] != "cxk")
                        {
                            if (tpa_dx[a.playername] != "cxk")
                            {
                                api.runcmd("tp \"" + a.playername + "\" " + tpa_dx[a.playername]);
                                tpa_ys[tpa_dx[a.playername]] = "0";
                                tpa_dx[a.playername]         = "cxk";
                            }
                        }
                    }
                    if (a.selected == "false")
                    {
                        api.runcmd("tellraw \"" + tpa_dx[a.playername] + "\" {\"rawtext\":[{\"text\":\"对方拒绝了您的传送请求\"}]}");
                        tpa_ys[tpa_dx[a.playername]] = "0";
                        tpa_dx[a.playername]         = "cxk";
                    }
                }
                return(true);
            });
        }
示例#5
0
        public static void init(MCCSAPI api)
        {
            mcapi = api;
            Console.OutputEncoding = Encoding.UTF8;
            // 后台指令监听
            api.addBeforeActListener(EventKey.onServerCmd, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var se = BaseEvent.getFrom(x) as ServerCmdEvent;
                if (se != null)
                {
                    Console.WriteLine("后台指令={0}", se.cmd);
                }
                return(true);
            });
            // 后台指令输出监听
            api.addBeforeActListener(EventKey.onServerCmdOutput, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var se = BaseEvent.getFrom(x) as ServerCmdOutputEvent;
                if (se != null)
                {
                    Console.WriteLine("后台指令输出={0}", se.output);
                }
                return(true);
            });
            // 表单选择监听
            api.addAfterActListener(EventKey.onFormSelect, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var fe = BaseEvent.getFrom(x) as FormSelectEvent;
                if (fe == null)
                {
                    return(true);
                }
                if (fe.formid != tformid)
                {
                    return(true);
                }
                if (fe.selected != "null")
                {
                    Console.WriteLine("玩家 {0} 选择了表单 id={1} ,selected={2}", fe.playername, fe.formid, fe.selected);
                    CsPlayer pl = new CsPlayer(api, fe.playerPtr);
                    if (fe.selected == "0")
                    {
                        ulong bkid = pl.UniqueId;
                        // 根据流水号反查,可能是实体,也可能是玩家
                        var d = CsActor.getFromUniqueId(api, bkid) as CsPlayer;
                        if (d != null)
                        {
                            Console.WriteLine("UniqueId反查成功。");
                            pl = d;
                        }
                        // 常规组件测试
                        Console.WriteLine("玩家攻击力组件:{0},玩家碰撞箱组件:{1},玩家生命值组件:{2},玩家位置组件:{3},玩家转角组件:{4}" +
                                          ",玩家所处维度:{5},玩家实体类型:{6},玩家查询流水号:{7},玩家UUID:{8},玩家名字:{9}",
                                          pl.Attack, pl.CollisionBox, pl.Health, pl.Position, pl.Rotation, pl.DimensionId, pl.TypeId, pl.UniqueId, pl.Uuid, pl.getName());
                    }
                    else if (fe.selected == "1")
                    {
                        // 物品栏测试
                        Console.WriteLine("实体装备栏:{0},实体主副手栏:{1},实体背包栏:{2},实体热键栏:{3}",
                                          pl.ArmorContainer, pl.HandContainer, pl.InventoryContainer, pl.HotbarContainer);
                    }
                    else if (fe.selected == "2")
                    {
                        // 组件设置测试
                        JavaScriptSerializer ser = new JavaScriptSerializer();
                        var atta          = ser.Deserialize <Dictionary <string, object> >(pl.Attack);
                        atta["range_min"] = Convert.ToSingle(atta["range_min"]) + 4;
                        atta["range_max"] = Convert.ToSingle(atta["range_max"]) + 4;
                        pl.Attack         = ser.Serialize(atta);
                        Console.WriteLine("玩家攻击力将+4");
                        var acb       = ser.Deserialize <Dictionary <string, object> >(pl.CollisionBox);
                        acb["width"]  = Convert.ToSingle(acb["width"]) + 1;
                        acb["height"] = Convert.ToSingle(acb["height"]) + 1;
                        //pl.CollisionBox = ser.Serialize(acb);
                        //Console.WriteLine("玩家碰撞箱宽和高的值将+1格");
                        var ahe      = ser.Deserialize <Dictionary <string, object> >(pl.Health);
                        ahe["max"]   = Convert.ToSingle(ahe["max"]) + 10;
                        ahe["value"] = Convert.ToSingle(ahe["value"]) + 10;
                        pl.Health    = ser.Serialize(ahe);
                        Console.WriteLine("玩家当前和最大生命值将+10点");
                        var prex        = "[前缀]";
                        var pname       = pl.getName();
                        bool alwaysshow = false;
                        if (pname.IndexOf(prex) == 0)
                        {
                            pname      = pname.Substring(prex.Length);
                            alwaysshow = true;
                        }
                        else
                        {
                            pname      = prex + pname;
                            alwaysshow = false;
                        }
                        pl.setName(pname, alwaysshow);
                        Console.WriteLine("玩家名字将添加/删除前缀,去掉/恢复常显");
                        var apos  = ser.Deserialize <Dictionary <string, object> >(pl.Position);
                        apos["x"] = Convert.ToSingle(apos["x"]) + 16;
                        apos["y"] = Convert.ToSingle(apos["y"]) + 10;
                        apos["z"] = Convert.ToSingle(apos["z"]) + 16;
                        //pl.Position = ser.Serialize(apos);
                        //Console.WriteLine("玩家将位移至当前位置的(+16,+10,+16)上。");
                        var arot    = ser.Deserialize <Dictionary <string, object> >(pl.Rotation);
                        arot["x"]   = Convert.ToSingle(arot["x"]) + 16;
                        arot["y"]   = Convert.ToSingle(arot["y"]) + 16;
                        pl.Rotation = ser.Serialize(arot);
                        Console.WriteLine("玩家俯角+16,转角+16");
                    }
                    else if (fe.selected == "3")
                    {
                        var el = CsActor.getsFromAABB(api, fe.dimensionid, fe.XYZ.x - 16, fe.XYZ.y - 16, fe.XYZ.z - 16,
                                                      fe.XYZ.x + 16, fe.XYZ.y + 16, fe.XYZ.z + 16);
                        if (el != null && el.Count > 0)
                        {
                            Console.WriteLine("查询并移除玩家附近16格内所有实体:");
                            foreach (IntPtr eptr in el)
                            {
                                var cse = new CsActor(api, eptr);
                                Console.WriteLine("TypeId={0},UniqueId={1},name={2}", cse.TypeId, cse.UniqueId, cse.getName());
                                cse.remove();
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("玩家 {0} 取消了表单 id={1}", fe.playername, fe.formid);
                }
                return(false);
            });
            // 使用物品监听
            api.addAfterActListener(EventKey.onUseItem, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as UseItemEvent;
                if (ue != null && ue.RESULT)
                {
                    Console.WriteLine("玩家 {0} 对 {1} 的 ({2}, {3}, {4}) 处的 {5} 方块" +
                                      "操作了 {6} 物品。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname, ue.itemname);
                }
                return(true);
            });
            // 放置方块监听
            api.addAfterActListener(EventKey.onPlacedBlock, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as PlacedBlockEvent;
                if (ue != null && ue.RESULT)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处放置了 {5} 方块。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 破坏方块监听
            api.addBeforeActListener(EventKey.onDestroyBlock, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as DestroyBlockEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 试图在 {1} 的 ({2}, {3}, {4})" +
                                      " 处破坏 {5} 方块。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 开箱监听
            api.addBeforeActListener(EventKey.onStartOpenChest, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StartOpenChestEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 试图在 {1} 的 ({2}, {3}, {4})" +
                                      " 处打开 {5} 箱子。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 开桶监听
            api.addBeforeActListener(EventKey.onStartOpenBarrel, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StartOpenBarrelEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 试图在 {1} 的 ({2}, {3}, {4})" +
                                      " 处打开 {5} 木桶。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 关箱监听
            api.addAfterActListener(EventKey.onStopOpenChest, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StopOpenChestEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处关闭 {5} 箱子。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 关桶监听
            api.addAfterActListener(EventKey.onStopOpenBarrel, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as StopOpenBarrelEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}, {3}, {4})" +
                                      " 处关闭 {5} 木桶。", ue.playername, ue.dimension, ue.position.x, ue.position.y, ue.position.z, ue.blockname);
                }
                return(true);
            });
            // 放入取出监听
            api.addAfterActListener(EventKey.onSetSlot, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as SetSlotEvent;
                if (e != null)
                {
                    if (e.itemcount > 0)
                    {
                        Console.WriteLine("玩家 {0} 在 {1} 槽放入了 {2} 个 {3} 物品。",
                                          e.playername, e.slot, e.itemcount, e.itemname);
                    }
                    else
                    {
                        Console.WriteLine("玩家 {0} 在 {1} 槽取出了物品。",
                                          e.playername, e.slot);
                    }
                }
                return(true);
            });
            // 切换维度监听
            api.addAfterActListener(EventKey.onChangeDimension, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as ChangeDimensionEvent;
                if (e != null && e.RESULT)
                {
                    Console.WriteLine("玩家 {0} {1} 切换维度至 {2} 的 ({3},{4},{5}) 处。",
                                      e.playername, e.isstand?"":"悬空地", e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z);
                }
                return(true);
            });
            // 生物死亡监听
            api.addAfterActListener(EventKey.onMobDie, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as MobDieEvent;
                if (e != null && !string.IsNullOrEmpty(e.mobname))
                {
                    Console.WriteLine(" {0} 在 {1} ({2:F2},{3:F2},{4:F2}) 处被 {5} 杀死了。",
                                      e.mobname, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z, e.srcname);
                }
                return(true);
            });
            // 玩家重生监听
            api.addAfterActListener(EventKey.onRespawn, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as RespawnEvent;
                if (e != null && e.RESULT)
                {
                    Console.WriteLine("玩家 {0} 已于 {1} 的 ({2:F2},{3:F2},{4:F2}) 处重生。",
                                      e.playername, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z);
                }
                return(true);
            });
            // 聊天监听
            api.addAfterActListener(EventKey.onChat, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as ChatEvent;
                if (e != null)
                {
                    Console.WriteLine(" {0} {1} 说:{2}", e.playername,
                                      !string.IsNullOrEmpty(e.target) ? "悄悄地对 " + e.target : "", e.msg);
                }
                return(true);
            });
            // 输入文本监听
            api.addBeforeActListener(EventKey.onInputText, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as InputTextEvent;
                if (e != null)
                {
                    Console.WriteLine(" <{0}> {1}", e.playername, e.msg);
                }
                return(true);
            });
            // 输入指令监听
            api.addBeforeActListener(EventKey.onInputCommand, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as InputCommandEvent;
                if (e != null)
                {
                    Console.WriteLine(" <{0}> {1}", e.playername, e.cmd);
                }
                return(true);
            });

            // 世界范围爆炸监听,拦截
            api.addBeforeActListener(EventKey.onLevelExplode, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as LevelExplodeEvent;
                if (e != null)
                {
                    Console.WriteLine("位于 {0} ({1},{2},{3}) 的 {4} 试图发生强度 {5} 的爆炸。",
                                      e.dimension, e.position.x, e.position.y, e.position.z,
                                      string.IsNullOrEmpty(e.entity) ? e.blockname : e.entity, e.explodepower);
                }
                return(false);
            });
            // 玩家切换装备监听
            api.addAfterActListener(EventKey.onEquippedArmor, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as EquippedArmorEvent;
                if (e != null)
                {
                    Console.WriteLine("玩家 {0} 已于 {1} 的 ({2:F2},{3:F2},{4:F2}) 处切换第 {5} 格的装备为 {6} 。",
                                      e.playername, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z,
                                      e.slot, e.itemname);
                }
                return(true);
            });
            // 玩家升级监听
            api.addAfterActListener(EventKey.onLevelUp, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as LevelUpEvent;
                if (e != null)
                {
                    Console.WriteLine("玩家 {0} 已于 {1} 的 ({2:F2},{3:F2},{4:F2}) 处等级提升了 {5} 级。",
                                      e.playername, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z,
                                      e.lv);
                }
                return(true);
            });

            /*
             * // 玩家移动监听
             * api.addAfterActListener(EventKey.onMove, x => {
             *      var e = BaseEvent.getFrom(x) as MoveEvent;
             *      if (e != null) {
             *              Console.WriteLine("玩家 {0} {1} 移动至 {2} ({3},{4},{5}) 处。",
             *                      e.playername, (e.isstand) ? "":"悬空地", e.dimension,
             *                      e.XYZ.x, e.XYZ.y, e.XYZ.z);
             *      }
             *      return false;
             * });
             */
            // 玩家加入游戏监听
            api.addAfterActListener(EventKey.onLoadName, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as LoadNameEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 加入了游戏,xuid={1}", ue.playername, ue.xuid);
                }
                return(true);
            });
            // 玩家离开游戏监听
            api.addAfterActListener(EventKey.onPlayerLeft, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var ue = BaseEvent.getFrom(x) as PlayerLeftEvent;
                if (ue != null)
                {
                    Console.WriteLine("玩家 {0} 离开了游戏,xuid={1}", ue.playername, ue.xuid);
                }
                return(true);
            });

            // 攻击监听
            // API 方式注册监听器
            api.addAfterActListener(EventKey.onAttack, x => {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                AttackEvent ae = BaseEvent.getFrom(x) as AttackEvent;
                if (ae != null)
                {
                    string str = "玩家 " + ae.playername + " 在 (" + ae.XYZ.x.ToString("F2") + "," +
                                 ae.XYZ.y.ToString("F2") + "," + ae.XYZ.z.ToString("F2") + ") 处攻击了 " + ae.actortype + " 。";
                    Console.WriteLine(str);
                    //Console.WriteLine("list={0}", api.getOnLinePlayers());
                    string ols = api.getOnLinePlayers();
                    if (!string.IsNullOrEmpty(ols))
                    {
                        JavaScriptSerializer ser = new JavaScriptSerializer();
                        ArrayList al             = ser.Deserialize <ArrayList>(ols);
                        object uuid = null;
                        foreach (Dictionary <string, object> p in al)
                        {
                            object name;
                            if (p.TryGetValue("playername", out name))
                            {
                                if ((string)name == ae.playername)
                                {
                                    // 找到
                                    p.TryGetValue("uuid", out uuid);
                                    break;
                                }
                            }
                        }
                        if (uuid != null)
                        {
                            tformid = api.sendSimpleForm((string)uuid,
                                                         "测试选项",
                                                         "test choose:",
                                                         "[\"基本组件\",\"物品栏组件\",\"组件设置\", \"范围检测并清理\"]");
                            Console.WriteLine("创建需自行保管的表单,id={0}", tformid);
                            //api.transferserver((string)uuid, "www.xiafox.com", 19132);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Event convent fail.");
                }
                return(true);
            });
            #region 非社区部分内容
            if (api.COMMERCIAL)
            {
                // 生物伤害监听
                api.addBeforeActListener(EventKey.onMobHurt, x => {
                    Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                    var e = BaseEvent.getFrom(x) as MobHurtEvent;
                    if (e != null && !string.IsNullOrEmpty(e.mobname))
                    {
                        Console.WriteLine(" {0} 在 {1} ({2:F2},{3:F2},{4:F2}) 即将受到来自 {5} 的 {6} 点伤害,类型 {7}",
                                          e.mobname, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z, e.srcname, e.dmcount, e.dmtype);
                    }
                    return(true);
                });
                // 命令块执行指令监听,拦截
                api.addBeforeActListener(EventKey.onBlockCmd, x => {
                    Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                    var e = BaseEvent.getFrom(x) as BlockCmdEvent;
                    if (e != null)
                    {
                        Console.WriteLine("位于 {0} ({1},{2},{3}) 的 {4} 试图执行指令 {5}",
                                          e.dimension, e.position.x, e.position.y, e.position.z, e.name, e.cmd);
                    }
                    return(false);
                });
                // NPC执行指令监听,拦截
                api.addBeforeActListener(EventKey.onNpcCmd, x => {
                    Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                    var e = BaseEvent.getFrom(x) as NpcCmdEvent;
                    if (e != null)
                    {
                        Console.WriteLine("位于 {0} ({1},{2},{3}) 的 {4} 试图执行第 {5} 条指令,指令集\n{6}",
                                          e.dimension, e.position.x, e.position.y, e.position.z, e.npcname, e.actionid, e.actions);
                    }
                    return(false);
                });
                // 更新命令方块监听
                api.addBeforeActListener(EventKey.onCommandBlockUpdate, x => {
                    Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                    var e = BaseEvent.getFrom(x) as CommandBlockUpdateEvent;
                    if (e != null)
                    {
                        Console.WriteLine(" {0} 试图修改位于 {1} ({2},{3},{4}) 的 {5} 的命令为 {6}",
                                          e.playername, e.dimension, e.position.x, e.position.y, e.position.z,
                                          e.isblock ? "命令块" : "命令矿车", e.cmd);
                    }
                    return(true);
                });
            }
            #endregion


            // Json 解析部分 使用JavaScriptSerializer序列化Dictionary或array即可

            //JavaScriptSerializer ser = new JavaScriptSerializer();
            //var data = ser.Deserialize<Dictionary<string, object>>("{\"x\":9}");
            //var ary = ser.Deserialize<ArrayList>("[\"x\",\"y\"]");
            //Console.WriteLine(data["x"]);
            //foreach(string v in ary) {
            //	Console.WriteLine(v);
            //}
            //data["y"] = 8;
            //string dstr = ser.Serialize(data);
            //Console.WriteLine(dstr);

            // 高级玩法,硬编码方式注册hook
            THook.init(api);
        }