public static void aaascr(MCCSAPI api)
        {
            Dictionary <string, string> uuid = new Dictionary <string, string>();

            api.addAfterActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playername);
                return(true);
            });
            api.addBeforeActListener(EventKey.onUseItem, x =>
            {
                var a           = BaseEvent.getFrom(x) as UseItemEvent;
                string obsidian = "minecraft:obsidian";
                string Bucket   = "Bucket";
                //Console.WriteLine("{0} {1}", a.blockname, a.itemname);
                if (a.blockname == obsidian & a.itemname == Bucket & a.dimensionid == 0)
                {
                    api.runcmd("setblock " + a.position.x + " " + a.position.y + " " + a.position.z + " flowing_lava");
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3[射爆庚子]§c已帮亲亲恢复岩浆了哦!\"}]}");
                }
                return(true);
            });
        }
示例#2
0
        public static void init(MCCSAPI api)
        {
            bool f = true;

            api.addBeforeActListener(EventKey.onServerCmdOutput, x =>
            {
                var b = BaseEvent.getFrom(x) as ServerCmdOutputEvent;
                if (f && b.output == "No targets matched selector")
                {
                    return(false);
                }
                //Console.WriteLine("OUTPUT:{0}",b.output);
                return(true);
            });
            api.addBeforeActListener(EventKey.onServerCmd, x =>
            {
                var a = BaseEvent.getFrom(x) as ServerCmdEvent;
                if (a.cmd == "cleaner")
                {
                    if (f == true)
                    {
                        f = false;
                        Console.WriteLine("[Cleaner]自动清理功能关闭");
                        return(false);
                    }
                    else
                    {
                        f = true; Console.WriteLine("[Cleaner]自动清理功能开启");
                    }
                    return(false);
                }
                return(true);
            });

            Task t = new Task(() =>
            {
                while (f)
                {
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§b[§e扫地姬§b]§a掉落物将在§c60§a秒后清除!\"}]}");
                    Thread.Sleep(30000);
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§b[§e扫地姬§b]§a掉落物将在§c30§a秒后清除!\"}]}");
                    Thread.Sleep(20000);
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§b[§e扫地姬§b]§a掉落物将在§c10§a秒后清除!\"}]}");
                    Thread.Sleep(5000);
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§b[§e扫地姬§b]§a马上你的掉落物就没了,还不捡起来!\"}]}");
                    Thread.Sleep(5000);
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§b[§e扫地姬§b]§a掉落物清除完毕!\"}]}");
                    api.runcmd("kill @e[type=item]");
                    Thread.Sleep(1200000);
                }
            });

            t.Start();
        }
示例#3
0
文件: Land.cs 项目: SnowPea8072/Land
        /// <summary>
        /// 初始化插件
        /// </summary>
        /// <param name="api">MC相关API方法</param>
        public static void init(MCCSAPI api)
        {
            mcapi = api;

            initPlugin();

            #region 注册命令

            mcapi.setCommandDescribe("land", "打开领地菜单");

            #endregion

            #region 设置事件监听器

            api.addAfterActListener(EventKey.onLoadName, PlayerJoin);
            api.addBeforeActListener(EventKey.onAttack, Attack);
            api.addBeforeActListener(EventKey.onUseItem, UseItem);
            api.addBeforeActListener(EventKey.onServerCmd, ServerCmd);
            api.addBeforeActListener(EventKey.onPlacedBlock, PlacedBlock);
            api.addBeforeActListener(EventKey.onInputCommand, InputCommand);
            api.addBeforeActListener(EventKey.onDestroyBlock, DestroyBlock);
            api.addBeforeActListener(EventKey.onLevelExplode, LevelExplode);
            api.addBeforeActListener(EventKey.onStartOpenChest, StartOpenChest);
            // api.addBeforeActListener(EventKey.onStartOpenBarrel, StartOpenBarrel);

            #endregion
        }
示例#4
0
        /// <summary>
        /// 发送一个简易表单
        /// </summary>
        /// <param name="tout">超时时间</param>
        /// <param name="func">主选择处理函数</param>
        /// <param name="tofunc">超时处理函数</param>
        /// <returns></returns>
        public bool send(int tout, ONSELECT func, ONTIMEOUT tofunc)
        {
            timeout    = tout;
            onselected = func;
            ontimeout  = tofunc;
            fmcb       = (x) => {
                var e = BaseEvent.getFrom(x) as FormSelectEvent;
                if (e.formid == id)                     // 确定是当前表单
                {
                    mapi.removeBeforeActListener(EventKey.onFormSelect, fmcb);
                    cancelTimeout();
                    onselected(e.selected);
                }
                return(true);
            };
            mapi.addBeforeActListener(EventKey.onFormSelect, fmcb);
            string bts = "[]";

            if (buttons != null && buttons.Count > 0)
            {
                var ser = new JavaScriptSerializer();
                bts = ser.Serialize(buttons);
            }
            id = mapi.sendSimpleForm(uuid, title, content, bts);
            bool ret = (id != 0);

            if (timeout > 0)
            {
                startTimeout();
            }
            return(ret);
        }
示例#5
0
        /// <summary>
        /// 初始化插件
        /// </summary>
        /// <param name="api">MC相关API方法</param>
        internal static void init(MCCSAPI api)
        {
            mcapi = api;

            initPlugin();

            #region 设置事件监听器

            api.addAfterActListener(EventKey.onUseItem, UseItem);
            api.addAfterActListener(EventKey.onLoadName, PlayerJoin);
            api.addAfterActListener(EventKey.onPlayerLeft, PlayerLeft);
            api.addAfterActListener(EventKey.onFormSelect, FormSelect);
            api.addBeforeActListener(EventKey.onServerCmd, ServerCmd);
            api.addBeforeActListener(EventKey.onInputCommand, InputCommand);

            #endregion
        }
示例#6
0
        public static void c(MCCSAPI api)
        {
            Dictionary <string, string> uuid = new Dictionary <string, string>();
            Dictionary <string, int>    xx   = new Dictionary <string, int>();
            Dictionary <string, int>    yy   = new Dictionary <string, int>();
            Dictionary <string, int>    zz   = new Dictionary <string, int>();

            _ = api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var a   = BaseEvent.getFrom(x) as InputCommandEvent;
                bool re = true;
                if (a.cmd.StartsWith("/is "))
                {
                    string sx = a.cmd.Substring(4);
                    switch (sx)
                    {
                    case "seta":
                        var b = Tools.Player.getPlayerPermissionAndGametype(api, uuid[a.playername]);
                        if (Int32.Parse(b.oplevel) >= 2)
                        {
                            if (xx.ContainsKey(a.playername) != true)
                            {
                                xx.Add(a.playername, (int)a.XYZ.x);
                                yy.Add(a.playername, (int)a.XYZ.y);
                                zz.Add(a.playername, (int)a.XYZ.z);
                            }
                        }
                        break;

                    case "setb":
                        var c = Tools.Player.getPlayerPermissionAndGametype(api, uuid[a.playername]);
                        if (Int32.Parse(c.oplevel) >= 2)
                        {
                            if (xx.ContainsKey(a.playername))
                            {
                                string stru = api.getStructure(a.dimensionid, "{\"x\":" + xx[a.playername] + ",\"y\":" + yy[a.playername] + ",\"z\":" + zz[a.playername] + "}", "{\"x\":" + (int)a.XYZ.x + ",\"y\":" + (int)a.XYZ.y + ",\"z\":" + (int)a.XYZ.z + "}", true, true);
                                int temp    = 0;
                                while (true)
                                {
                                    if (File.Exists("./data/skyblock" + temp.ToString() + ".txt"))
                                    {
                                        temp++;
                                    }
                                    else
                                    {
                                        temp++;
                                        File.AppendAllText("./data/skyblock" + temp.ToString() + ".txt", stru);
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                return(re);
            });
        }
示例#7
0
        /*
         * /// <summary>
         * /// 设置玩家命令监听
         * /// </summary>
         * private static bool InputCommand(Events x)
         * {
         *  var json = BaseEvent.getFrom(x) as InputCommandEvent;
         *  var config = JObject.Parse(File.ReadAllText(configFile));
         *  if (json.cmd == "/tpa" && (bool)config["tpa"])
         *  {
         *      Tpa.Choose(json.playername, api);
         *      return false;
         *  }
         *  else if (json.cmd == "/tpr" && (bool)config["tpr"])
         *  {
         *      Tpr.Do(json.playername, api);
         *      return false;
         *  }
         *  else if (json.cmd == "/back" && (bool)config["back"])
         *  {
         *      Back.Do(json.playername, api);
         *      return false;
         *  }
         *  else if (json.cmd == "/home" && (bool)config["home"])
         *  {
         *      Home.Choose(json.playername, api);
         *      return false;
         *  }
         *  else if (json.cmd == "/homet" && (bool)config["home"])
         *  {
         *      HomeT.Do(json.playername, api);
         *      return false;
         *  }
         *  else if (json.cmd == "/money")
         *  {
         *      Economic.Choose(json.playername);
         *      return false;
         *  }
         *  else if (json.cmd == "/ban" && (bool)config["blacklist"])
         *  {
         *      BlackList.Choose(json.playername, api);
         *      return false;
         *  }
         *  return true;
         * } */

        #endregion

        /// <summary>
        /// 初始化插件
        /// </summary>
        /// <param name="api">MC相关API方法</param>
        public static void init(MCCSAPI api)
        {
            mcapi = api;

            initPlugin();

            #region 设置事件监听器

            api.addAfterActListener(EventKey.onLoadName, PlayerJoin);
            // api.addAfterActListener(EventKey.onFormSelect, FormSelect);
            api.addBeforeActListener(EventKey.onServerCmd, ServerCmd);
            // api.addBeforeActListener(EventKey.onInputCommand, InputCommand);

            var Clean = new Thread(new ThreadStart(CleanRobot.Clean));
            Clean.Name = "扫地机器人";
            Clean.Start();

            #endregion
        }
示例#8
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);
        }
示例#9
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);
            });
        }
示例#10
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},玩家计分板ID:{10}",
                                          pl.Attack, pl.CollisionBox, pl.Health, pl.Position, pl.Rotation, pl.DimensionId, pl.TypeId, pl.UniqueId, pl.Uuid, pl.getName(),
                                          pl.getScoreboardId() /* , pl.createScoreboardId() */);
                    }
                    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 if (fe.selected == "4")
                    {
                        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);
                        var plst = CsPlayer.getplFromAABB(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);
                        el   = el == null ? new ArrayList() : el;
                        plst = plst == null ? new ArrayList() : plst;
                        el.AddRange(plst);
                        if (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());
                                // 测试实体模拟受攻击伤害,伤害值为10
                                cse.hurt(fe.playerPtr /*IntPtr.Zero*/, ActorDamageCause.EntityAttack, 10, false, false);
                            }
                        }
                    }
                    else if (fe.selected == "5")
                    {
                        pl.addLevel(3);
                    }
                    else if (fe.selected == "6")
                    {
                        pl.teleport(100, 100, 100);
                    }
                    else if (fe.selected == "7")
                    {
                        api.setSideBar(pl.Uuid, "这就是内容不能换行");
                    }
                }
                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} 格的装备为 {7} 。",
                                      e.playername, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z,
                                      e.slottype == 0 ? "身体装备的" : "主副手的", 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.addBeforeActListener(EventKey.onPistonPush, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as PistonPushEvent;
                if (e != null)
                {
                    Console.WriteLine("活塞 {0} 于 {1} 的({2}, {3}, {4})处试图向 {5} 号方向推拽({6}, {7}, {8})处的 {9} 方块。",
                                      e.blockname, e.dimension, e.position.x, e.position.y, e.position.z,
                                      e.direction, e.targetposition.x, e.targetposition.y, e.position.z, e.targetblockname);
                    return(true);
                }
                return(true);
            });
            // 箱子合并监听
            api.addAfterActListener(EventKey.onChestPair, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as ChestPairEvent;
                if (e != null)
                {
                    Console.WriteLine("箱子 {0} 于 {1} 的({2}, {3}, {4})处试图合并向({5}, {6}, {7})处的 {8} 箱子。",
                                      e.blockname, e.dimension, e.position.x, e.position.y, e.position.z, e.targetposition.x, e.targetposition.y,
                                      e.position.z, e.targetblockname);
                    return(true);
                }
                return(true);
            });

            /*
             *          api.addBeforeActListener(EventKey.onMobSpawnCheck, x =>
             *          {
             *                  Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
             *                  var e = BaseEvent.getFrom(x) as MobSpawnCheckEvent;
             *                  if (e != null)
             *                  {
             *                          Console.WriteLine("生物 {0} 于 {1} 的({2}, {3}, {4})处试图检查生成规则。",
             *                                  e.mobtype, e.dimension, e.XYZ.x, e.XYZ.y, e.XYZ.z);
             *                          return true;
             *                  }
             *                  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)
                {
                    CsPlayer p = new CsPlayer(api, ue.playerPtr);
                    Console.WriteLine("玩家 {0} 加入了游戏,xuid={1}, IP={2}", ue.playername, ue.xuid, p.IpPort);
                }
                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);
                    // 社区api测试
                    api.setServerMotd(ae.playername + "发动了攻击", true);
                    //Console.WriteLine("list={0}", api.getOnLinePlayers())
                    CsPlayer p = new CsPlayer(api, ae.playerPtr);
                    var uuid   = p.Uuid;
                    if (uuid != null)
                    {
                        tformid = api.sendSimpleForm((string)uuid,
                                                     "测试选项",
                                                     "test choose:",
                                                     "[\"基本组件\",\"物品栏组件\",\"组件设置\", \"范围检测并清理\",\"范围检测并攻击\"," +
                                                     "\"玩家等级+3\",\"测试传送\",\"积分版测试\" ]");
                        Console.WriteLine("创建需自行保管的表单,id={0}", tformid);
                        // 非社区内容测试
                        if (api.COMMERCIAL)
                        {
                            CsActor ac = new CsActor(api, ae.attackedentityPtr);
                            Console.WriteLine("目标实体的能力值:" + ac.Abilities + "\n目标实体的属性列表:" + ac.Attributes
                                              + "\n目标实体的最大属性列表:" + ac.MaxAttributes + "\n目标实体的所有状态效果列表:" + ac.Effects);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Event convent fail.");
                }
                return(true);
            });

            //玩家捡物品事件 - 可拦截
            api.addBeforeActListener(EventKey.onPickUpItem, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                PickUpItemEvent ae = BaseEvent.getFrom(x) as PickUpItemEvent;
                if (ae != null)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}) 捡起了 {3} 物品。", ae.playername, ae.dimension, ae.XYZ.x.ToString("F2") + "," +
                                      ae.XYZ.y.ToString("F2") + "," + ae.XYZ.z.ToString("F2"), ae.itemname);
                }
                return(true);
            });

            //玩家丢物品事件 - 可拦截
            api.addBeforeActListener(EventKey.onDropItem, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                DropItemEvent ae = BaseEvent.getFrom(x) as DropItemEvent;
                if (ae != null)
                {
                    Console.WriteLine("玩家 {0} 在 {1} 的 ({2}) 丢下了 {3} 物品。", ae.playername, ae.dimension, ae.XYZ.x.ToString("F2") + "," +
                                      ae.XYZ.y.ToString("F2") + "," + ae.XYZ.z.ToString("F2"), ae.itemname);
                }
                return(true);
            });
            // 计分板数值改变事件
            api.addAfterActListener(EventKey.onScoreChanged, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                ScoreChangedEvent ae = BaseEvent.getFrom(x) as ScoreChangedEvent;
                if (ae != null)
                {
                    Console.WriteLine("计分板 {0} (显示名称:{1},id:{2})分数改变为 {3}",
                                      ae.objectivename, ae.displayname, ae.scoreboardid, ae.score);
                    // 追加改变,由于会重复触发改变事件,故设定停止上限
                    //if (ae.score < 100)
                    //{
                    //	Console.WriteLine("启动30秒后增加分数任务,请耐心等待测试反馈..");
                    //	// 多线程情况下测试离线计分板id是否有效,等待三十秒
                    //	new Thread(() =>
                    //	{
                    //		Thread.Sleep(30000);
                    //		Console.WriteLine("追加改变增加100,数值变为:" + api.setscoreById(ae.scoreboardid, ae.objectivename, ae.score + 100));
                    //		Console.WriteLine("改变后的分数为:" + api.getscoreById(ae.scoreboardid, ae.objectivename));
                    //	}).Start();
                    //}
                }
                return(true);
            });
            // 官方脚本引擎初始化监听
            api.addAfterActListener(EventKey.onScriptEngineInit, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                ScriptEngineInitEvent ae = BaseEvent.getFrom(x) as ScriptEngineInitEvent;
                if (ae != null && ae.RESULT)
                {
                    Console.WriteLine("脚本引擎已初始化成功,addr={0}",
                                      ae.jseptr);
                    // 延时1s载入外置行为包脚本;延时3s发送一个自定义事件;延时1s载入一段临时脚本
                    new Thread(() =>
                    {
                        Thread.Sleep(1000);
                        try
                        {       // 测试临时行为包脚本注意事项:runScript情况下不会经过 initialize 调用,需主动设置初始化
                            string js = File.ReadAllText("test.js");
                            api.JSErunScript(js, (r) =>
                            {
                                if (r)
                                {
                                    Console.WriteLine("外置测试行为包脚本载入成功。");
                                }
                            });
                        }
                        catch { }
                        Thread.Sleep(3000);
                        string jdata = new JavaScriptSerializer().Serialize(new { text = "这是一个自定义测试消息", num = 2021 });
                        api.JSEfireCustomEvent("mytest:testevent", jdata, (r) =>
                        {
                            if (r)
                            {
                                Console.WriteLine("自定义事件广播发送成功。");
                            }
                        });
                        Thread.Sleep(1000);
                        api.JSErunScript("var d = 100;\n console.log('这是一个临时测试脚本')", (r) =>
                        {
                            if (r)
                            {
                                Console.WriteLine("测试临时脚本执行成功。");
                            }
                        });
                    }).Start();
                }
                return(true);
            });
            // 官方脚本引擎接收日志输出信息监听,拦截
            api.addBeforeActListener(EventKey.onScriptEngineLog, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                ScriptEngineLogEvent ae = BaseEvent.getFrom(x) as ScriptEngineLogEvent;
                if (ae != null)
                {
                    Console.WriteLine("[来自脚本的LOG输出] {0}",
                                      ae.log);
                }
                return(false);
            });
            // 官方脚本引擎执行指令,或可拦截
            api.addBeforeActListener(EventKey.onScriptEngineCmd, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                ScriptEngineCmdEvent ae = BaseEvent.getFrom(x) as ScriptEngineCmdEvent;
                if (ae != null)
                {
                    Console.WriteLine("[脚本引擎试图执行指令] {0}",
                                      ae.cmd);
                }
                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.onScoreboardInit, x =>
            {
                Console.WriteLine("[CS] type = {0}, mode = {1}, result= {2}", x.type, x.mode, x.result);
                var e = BaseEvent.getFrom(x) as ScoreboardInitEvent;
                if (e != null)
                {
                    Console.WriteLine("系统计分板已初始化成功,addr={0}",
                                      e.scptr);
                    //api.postTick(() => {
                    //	api.runcmd("list");
                    //});
                    //if (api.COMMERCIAL){   // 测试计分板读取和写入任务
                    //	string asc = api.getAllScore();
                    //	Console.WriteLine("[TEST]scoreboard={0}", asc);
                    //	if (!string.IsNullOrEmpty(asc)){
                    //		Console.WriteLine("启动一个延时30秒重置计分板的任务,请耐心等待信息反馈..");
                    //		new Thread(() =>{
                    //			Thread.Sleep(30000);
                    //			if (api.setAllScore(asc)){
                    //				Console.WriteLine("重置任务已发送。");
                    //			}
                    //		}).Start();
                    //	}
                    //}
                }
                return(true);
            });
            #region 非社区部分内容
            if (api.COMMERCIAL)
            {
                // 命令块执行指令监听,拦截
                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);
        }
示例#11
0
        public static void aaascr(MCCSAPI api)

        {
            api.setCommandDescribe("is creative", "创建一个空岛");
            api.setCommandDescribe("is goreset", "重置空岛传送点");
            api.setCommandDescribe("is go", "保存或传送到空岛传送点");
            api.setCommandDescribe("is sign", "签到");
            api.setCommandDescribe("is clear", "清理掉落物品");
            string qdpath           = "./skyblockX/sign/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.DayOfYear.ToString();
            string qdjlpath         = "./skyblockX/sign/签到奖励.txt";
            string _ifobsition      = "true";
            string _ifrespawnpunish = "false";
            string eula             = "false";
            string _ifautoclear     = "false";
            string qdjl             = "give @s apple";
            int    cleartime        = 10;
            int    start_x          = 0;
            int    start_y          = 0;
            int    start_z          = 0;
            int    end_x            = 0;
            int    end_y            = 0;
            int    end_z            = 0;
            int    x_max            = 5000;
            int    z_max            = 5000;

            if (File.Exists("./skyblockX/skyblockX.txt"))
            {
                try
                {
                    string[] config = File.ReadAllLines("./skyblockX/skyblockX.txt", System.Text.Encoding.Default);
                    _ifobsition             = config[0].Substring(14);
                    _ifrespawnpunish        = config[1].Substring(9);
                    _ifautoclear            = config[2].Substring(7);
                    cleartime               = int.Parse(config[3].Substring(7));
                    start_x                 = int.Parse(config[4].Substring(8));
                    start_y                 = int.Parse(config[5].Substring(8));
                    start_z                 = int.Parse(config[6].Substring(8));
                    end_x                   = int.Parse(config[7].Substring(6));
                    end_y                   = int.Parse(config[8].Substring(6));
                    end_z                   = int.Parse(config[9].Substring(6));
                    x_max                   = int.Parse(config[10].Substring(6));
                    z_max                   = int.Parse(config[11].Substring(6));
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("[SkyBlockX]配置文件读取成功!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]配置文件读取失败!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            else
            {
                Directory.CreateDirectory("./skyblockX");
                File.AppendAllText("./skyblockX/skyblockX.txt", "是否允许桶点黑曜石变为岩浆:true\n是否开启重生惩罚:false\n是否自动清理:false\n自动清理间隔:10\nstart_x:0\nstart_y:0\nstart_z:0\nend_x:0\nend_y:0\nend_z:0\nx_max:5000\nz_max:5000", System.Text.Encoding.Default);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[SkyBlockX]未检查到配置文件!将自动创建!");
                Console.ForegroundColor = ConsoleColor.White;
            }
            int ktime = 60000 * cleartime;

            if (File.Exists("./skyblockX/islands"))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("[SkyBlockX]数据读取成功成功!");
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                try
                {
                    System.IO.Directory.CreateDirectory("./skyblockX/islands");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("[SkyBlockX]文件夹创建成功!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]文件夹创建失败!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            if (File.Exists("./skyblockX/spawns"))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("[SkyBlockX]数据读取成功成功!");
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                try
                {
                    System.IO.Directory.CreateDirectory("./skyblockX/spawns");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("[SkyBlockX]文件夹创建成功!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]文件夹创建失败!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            if (File.Exists(qdpath))
            {
            }
            else
            {
                try
                {
                    System.IO.Directory.CreateDirectory(qdpath);
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("[SkyBlockX]文件夹创建成功!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]文件夹创建失败!");
                    Console.ForegroundColor = ConsoleColor.White;
                    Directory.CreateDirectory(qdpath);
                }
            }
            if (File.Exists("./SkyBlockXeula.txt"))
            {
                try
                {
                    string[] config = File.ReadAllLines("./SkyBlockXeula.txt", System.Text.Encoding.Default);
                    eula = config[0].Substring(5);
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("[SkyBlockX]eula协议读取成功!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]eula协议读取失败!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            else
            {
                File.AppendAllText("./SkyBlockXeula.txt", "eula=false\nAugust 2020 SkyBlockX Release.\nThanks for using SkyBlockX.\n一条重要规定是除非Sbaoor明确同意,\n否则您不得分发使用SkyBlockX创建的任何内容。\n\"分发使用SkyBlockX创建的任何内容\"是指:\n1.向任何其他人提供使用SkyBlockX的服务端整合包;\n2.将SkyBlockX用于商业用途;\n3.试图通过SkyBlockX创建的任何内容赚钱;\n如果您同意了eula协定,\n这代表您已被授予使用的许可,\n因此您可以在自己的服务端上使用它。\n", System.Text.Encoding.Default);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[SkyBlockX]未检查到eula文件!将自动创建!");
                Console.ForegroundColor = ConsoleColor.White;
            }
            if (eula != "true")
            {
                while (true)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyblockX]请同意用户协议");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadKey();
                }
            }
            Dictionary <string, string> uuid = new Dictionary <string, string>();

            api.addAfterActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playername);
                return(true);
            });
            api.addBeforeActListener(EventKey.onUseItem, x =>
            {
                var a           = BaseEvent.getFrom(x) as UseItemEvent;
                string obsidian = "minecraft:obsidian";
                string Bucket   = "Bucket";
                //Console.WriteLine("{0} {1}", a.blockname, a.itemname);
                if (a.blockname == obsidian & a.itemname == Bucket & a.dimensionid == 0 & _ifobsition == "true")
                {
                    api.runcmd("setblock " + a.position.x + " " + a.position.y + " " + a.position.z + " flowing_lava");
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3已帮你恢复岩浆!\"}]}");
                }
                if (a.blockname == obsidian & a.itemname == Bucket & a.dimensionid == 0 & _ifobsition == "false")
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3岩浆还原已被禁用!\"}]}");
                }
                if (a.blockname == obsidian & a.itemname == Bucket & a.dimensionid == 0 & _ifobsition != "false" & _ifobsition != "true")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]配置文件填写错误!请检查是否允许岩浆还原项!");
                    Console.ForegroundColor = ConsoleColor.White;
                }

                return(true);
            });
            api.addBeforeActListener(EventKey.onRespawn, x =>
            {
                var a = BaseEvent.getFrom(x) as RespawnEvent;
                if (_ifrespawnpunish == "true")
                {
                    api.runcmd("effect " + a.playername + " hunger 4 225 true");
                }
                if (_ifrespawnpunish == "false")
                {
                }
                if (_ifrespawnpunish != "false" & _ifrespawnpunish != "true")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[SkyBlockX]配置文件填写错误!请检查是否重生惩罚项!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var a         = BaseEvent.getFrom(x) as InputCommandEvent;
                string ispath = "./skyblockx/islands/" + a.playername + ".txt";
                string sppath = "./skyblockX/spawns/" + a.playername + ".txt";
                if (a.cmd.StartsWith("/is"))
                {
                    string iscommand = string.Empty;
                    iscommand        = a.cmd.Substring(4);
                    if (iscommand == "creative")
                    {
                        if (File.Exists(ispath))
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3你已经创建过了!!\"}]}");
                            return(false);
                        }
                        else
                        {
                            Random ran = new Random();
                            int n      = ran.Next(0, x_max);
                            int z      = ran.Next(0, z_max);
                            api.runcmd("tp \"" + a.playername + "\" " + n + " 100 " + z);
                            api.runcmd("effect \"" + a.playername + "\" slow_falling 10 5 true");
                            StreamWriter writer = new StreamWriter(ispath);
                            writer.Write(string.Concat("坐标:" + n + " 70 " + z, Environment.NewLine));
                            writer.Close();
                            //Thread.Sleep(5000);
                            var t = Task.Run(async delegate
                            {
                                await Task.Delay(3000);
                                api.runcmd("clone " + start_x + " " + start_y + " " + start_z + " " + end_x + " " + end_y + " " + end_z + " " + n + " 50 " + z);
                                return(42);
                            });
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3创建成功!\"}]}");
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3请用/is go来保存你的传送点!\"}]}");
                            return(false);
                        }
                    }
                    if (iscommand == "go")
                    {
                        if (File.Exists(sppath))
                        {
                            string[] config = File.ReadAllLines(sppath, System.Text.Encoding.Default);
                            int sp_x        = int.Parse(config[0].Substring(2));
                            int sp_y        = int.Parse(config[1].Substring(2));
                            int sp_z        = int.Parse(config[2].Substring(2));
                            api.teleport(uuid[a.playername], sp_x, sp_y, sp_z, 0);
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3传送成功!\"}]}");
                            return(false);
                        }
                        else
                        {
                            StreamWriter writer = new StreamWriter(sppath);
                            int intx            = Convert.ToInt32(a.XYZ.x);
                            int inty            = Convert.ToInt32(a.XYZ.y);
                            int intz            = Convert.ToInt32(a.XYZ.z);
                            writer.Write(string.Concat("x:" + intx, Environment.NewLine));
                            writer.Write(string.Concat("y:" + inty, Environment.NewLine));
                            writer.Write(string.Concat("z:" + intz, Environment.NewLine));
                            writer.Close();
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3已保存空岛传送点!\"}]}");
                            return(false);
                        }
                    }
                    if (iscommand == "goreset")
                    {
                        StreamWriter writer = new StreamWriter(sppath);
                        int intx            = Convert.ToInt32(a.XYZ.x);
                        int inty            = Convert.ToInt32(a.XYZ.y);
                        int intz            = Convert.ToInt32(a.XYZ.z);
                        writer.Write(string.Concat("x:" + intx, Environment.NewLine));
                        writer.Write(string.Concat("y:" + inty, Environment.NewLine));
                        writer.Write(string.Concat("z:" + intz, Environment.NewLine));
                        writer.Close();
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3已重置空岛传送点!\"}]}");
                        return(false);
                    }
                    if (iscommand == "clear")
                    {
                        var b = Tools.Player.getPlayerAbilities(api, uuid[a.playername]);
                        if (b.op == "true")
                        {
                            var t = Task.Run(async delegate
                            {
                                api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3还有10秒就要清理掉落物品了!\"}]}");
                                await Task.Delay(10000);
                                api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3清理完毕!\"}]}");
                                api.runcmd("kill @e[type=item]");
                                return(42);
                            });
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3权限不足!\"}]}");
                        }
                        return(false);
                    }
                    if (iscommand == "sign")
                    {
                        string grqdpath = "./skyblockX/sign/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.DayOfYear.ToString() + "/" + a.playername + ".txt";
                        if (File.Exists(qdjlpath))
                        {
                            if (File.Exists(grqdpath))
                            {
                                api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3你签到过了!\"}]}");
                                return(false);
                            }
                            else
                            {
                                if (File.Exists(qdpath))
                                {
                                    string[] config = File.ReadAllLines(qdjlpath, System.Text.Encoding.Default);
                                    qdjl            = config[0].Substring(5);
                                    if (qdjl != null)
                                    {
                                        api.runcmd("execute \"" + a.playername + "\" ~~~ " + qdjl);
                                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3签到成功!\"}]}");
                                        StreamWriter writer = new StreamWriter(grqdpath);
                                        writer.Write(string.Concat(DateTime.Now.ToString("hh:mm:ss"), Environment.NewLine));
                                        writer.Close();
                                        return(false);
                                    }
                                    else
                                    {
                                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3你的服主还没设置签到奖励!\"}]}");
                                        return(false);
                                    }
                                }
                                else
                                {
                                    Directory.CreateDirectory("./skyblockX/sign/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.DayOfYear.ToString());
                                    string[] config = File.ReadAllLines(qdjlpath, System.Text.Encoding.Default);
                                    qdjl            = config[0].Substring(5);
                                    if (qdjl != null)
                                    {
                                        api.runcmd("execute \"" + a.playername + "\" ~~~ " + qdjl);
                                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3签到成功!\"}]}");
                                        StreamWriter writer = new StreamWriter(grqdpath);
                                        writer.Write(string.Concat(DateTime.Now.ToString("hh:mm:ss"), Environment.NewLine));
                                        writer.Close();
                                        return(false);
                                    }
                                    else
                                    {
                                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3你的服主还没设置签到奖励!\"}]}");
                                        return(false);
                                    }
                                }
                            }
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3你的服主还没设置签到奖励!\"}]}");
                            Directory.CreateDirectory("/skyblockX/sign");
                            File.AppendAllText(qdjlpath, "签到奖励:", System.Text.Encoding.Default);
                            return(false);
                        }
                    }
                }

                return(true);
            });
            if (_ifautoclear == "true")
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        Thread.Sleep(ktime);
                        api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3还有10秒就要清理掉落物品了!\"}]}");
                        Thread.Sleep(10000);
                        api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3清理完毕!\"}]}");
                        api.runcmd("kill @e[type=item]");
                    }
                });
            }
            api.addBeforeActListener(EventKey.onServerCmd, x =>
            {
                var commandinput = BaseEvent.getFrom(x) as ServerCmdEvent;
                if (commandinput.cmd == "skyreload")
                {
                    try
                    {
                        string[] config         = File.ReadAllLines("./skyblockX/skyblockX.txt", System.Text.Encoding.Default);
                        _ifobsition             = config[0].Substring(14);
                        _ifrespawnpunish        = config[1].Substring(9);
                        _ifautoclear            = config[2].Substring(7);
                        cleartime               = int.Parse(config[3].Substring(7));
                        start_x                 = int.Parse(config[4].Substring(8));
                        start_y                 = int.Parse(config[5].Substring(8));
                        start_z                 = int.Parse(config[6].Substring(8));
                        end_x                   = int.Parse(config[7].Substring(6));
                        end_y                   = int.Parse(config[8].Substring(6));
                        end_z                   = int.Parse(config[9].Substring(6));
                        x_max                   = int.Parse(config[10].Substring(6));
                        z_max                   = int.Parse(config[11].Substring(6));
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("[SkyBlockX]配置文件读取成功!");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    catch
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[SkyBlockX]配置文件读取失败!");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    return(false);
                }
                if (commandinput.cmd == "stop")
                {
                    Task.Run(() =>
                    {
                        while (true)
                        {
                            api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3还有30秒就要关服了!\"}]}");
                            Thread.Sleep(10000);
                            api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3还有20秒就要关服了!\"}]}");
                            Thread.Sleep(10000);
                            api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"§3还有10秒就要关服了!\"}]}");
                            Thread.Sleep(10000);
                            api.runcmd("stop");
                        }
                    });
                    return(false);
                }
                return(true);
            });
        }
示例#12
0
        // 主入口实现
        public static void init(MCCSAPI api)
        {
            mapi = api;

            // 监听后台指令
            api.addBeforeActListener(EventKey.onServerCmd, x => {
                var e       = BaseEvent.getFrom(x) as ServerCmdEvent;
                string scmd = e.cmd.Trim();
                if (scmd.ToLower().IndexOf("visitor") == 0)                     // 可能找到
                {
                    string[] cmds = scmd.Split(' ');
                    if (cmds[0].ToLower() == "visitor")                         // 找到
                    {
                        if (cmds.Length > 1)
                        {
                            string pname = scmd.Substring(7).Trim().Trim('"');
                            string xuid  = null;
                            if (!string.IsNullOrEmpty(xuid = getXUID(pname)))
                            {
                                // 在线降权
                                if (visitorPlayer(xuid))
                                {
                                    tellraw(pname, "您已被降级权限为访客。");
                                    api.logout("Visited : " + pname);
                                    return(false);
                                }
                            }
                            else if (!string.IsNullOrEmpty(xuid = getLeftXUID(pname)))
                            {
                                // 离线降权
                                if (visitorPlayer(xuid))
                                {
                                    api.logout("玩家 " + pname + " 已被降级权限为访客。");
                                    return(false);
                                }
                            }
                            else
                            {
                                api.logout("未能找到对应玩家。");
                            }
                        }
                        else
                        {
                            api.logout("[vistor] 参数过少。用法:visitor [playername]");
                        }
                        return(false);
                    }
                }
                return(true);
            });

            // 离开监听
            api.addAfterActListener(EventKey.onPlayerLeft, x => {
                var e = BaseEvent.getFrom(x) as PlayerLeftEvent;
                string uuid, xuid;
                if (nameuuids.TryGetValue(e.playername, out uuid))
                {
                    nameuuids.Remove(e.playername);
                }
                if (namexuids.TryGetValue(e.playername, out xuid))
                {
                    namexuids.Remove(e.playername);
                }
                return(true);
            });
        }
示例#13
0
        //主入口
        public static void init(MCCSAPI api)
        {
            mapi = api;
            api.setCommandDescribeEx("tr", "跨服面板", MCCSAPI.CommandPermissionLevel.GameMasters, (byte)MCCSAPI.CommandCheatFlag.NotCheat, 0);
            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var e = BaseEvent.getFrom(x) as InputCommandEvent;
                if (e.cmd.Trim() == "/tr")
                {
                    string s   = File.ReadAllText(@"plugins\Transfer\transfer.json");
                    var uuid   = getUUUD(e.playername);
                    var formid = api.sendCustomForm(uuid, s);
                    mapi.addBeforeActListener(EventKey.onFormSelect, x1 =>
                    {
                        var je = BaseEvent.getFrom(x1) as FormSelectEvent;
                        if (je.formid == formid)
                        {
                            mapi.removeBeforeActListener(EventKey.onFormSelect, c => { return(true); });
                            if (je.selected != "[\"\",\"\"]" && je.selected != null)
                            {
                                if (je.selected != "null")
                                {
                                    string dt = File.ReadAllText(@"plugins\Transfer\transfer_cmd.json");
                                    var json  = DynamicJson.Parse(dt);
                                    int age   = Convert.ToInt32(je.selected);
                                    if (json[age]["method"] == "cmd")
                                    {
                                        if (json[age]["cata"] != "端口" && json[age]["cata"] != "" && json[age]["cata"] != " " && json[age]["cata"] != null)
                                        {
                                            string ip = json[age]["data"];
                                            int dk    = Convert.ToInt32(json[age]["cata"]);
                                            api.transferserver(uuid, ip, dk);
                                        }
                                        else
                                        {
                                            api.sendText(uuid, "§l§4<----[Transfer]---->\n§l§4请修改配置文件!");
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    });
                    return(false);
                }
                return(true);
            });
            //聊天监听,处理命令方块;
            api.addAfterActListener(EventKey.onChat, e =>
            {
                var je = BaseEvent.getFrom(e) as ChatEvent;
                if (je.chatstyle == "title")
                {
                    if (je.msg != "" && je.msg != " ")
                    {
                        var uuid    = getUUUD(je.playername);
                        string[] ss = je.msg.Split(' ');
                        if (ss[0] == "tr")
                        {
                            string ip = ss[1];
                            int dk    = Convert.ToInt32(ss[2]);
                            api.transferserver(uuid, ip, dk);
                        }
                    }
                }
                return(true);
            });

            aicQ();
        }
示例#14
0
        public static void RunCSharpLua(MCCSAPI api)
        {
            List <IntPtr> uuid = new List <IntPtr>();
            const String  path = "./cslr";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                Console.WriteLine("[INFO] [CSLR] 已创建文件夹");
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("[INFO] [CSLR] CSharpLuaRunner加载中");
            if (!File.Exists("./KeraLua.dll"))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[IPYR] 无法找到依赖库 请将KeraLua.dll与Lua54.dll放到BDS根目录");
                Console.ForegroundColor = ConsoleColor.White;
            }
            var           LuaFun    = new List <dynamic>();
            DirectoryInfo Allfolder = new DirectoryInfo(path);
            var           mc        = new MCLUAAPI(api);

            GC.KeepAlive(mc);
            foreach (FileInfo file in Allfolder.GetFiles("*.cs.lua"))
            {
                try
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("[INFO] [CSLR] 正在加载" + file.Name);
                    Lua lua = new Lua();
                    lua.DoFile(file.FullName);
                    Console.WriteLine("[INFO] [CSLR] " + file.Name + "加载成功");
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ERROR] [CSLR] " + e.Message);
                    Console.WriteLine("[ERROR] [CSLR] 加载" + file.Name + "失败");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }

            api.addBeforeActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playerPtr);
                ptr.Add(a.uuid, a.playerPtr);
                CallLuaFunc(LuaFun, func =>
                {
                    CsPlayer p  = new CsPlayer(api, a.playerPtr);
                    string list = "{\'playername\':\'" + a.playername + "\',\'uuid\':\'" + a.uuid + "\',\'xuid\':\'" + a.xuid + "\',\'IPport\':\'" + p.IpPort + "\'}";
                    var re      = func.load_name(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playerPtr);
                ptr.Remove(a.uuid);
                CallLuaFunc(LuaFun, func =>
                {
                    string list = "{\'playername\':\'" + a.playername + "\',\'uuid\':\'" + a.uuid + "\',\'xuid\':\'" + a.xuid + "\'}";
                    var re      = func.player_left(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onServerCmd, x =>
            {
                var a = BaseEvent.getFrom(x) as ServerCmdEvent;

                if (a.cmd.StartsWith("cslr "))
                {
                    string[] sArray = a.cmd.Split(new char[2] {
                        ' ', ' '
                    });

                    if (sArray[1] == "help")
                    {
                        Console.WriteLine("[INFO] [CSLR] help   使用帮助\n[INFO] [CSLR] info    CSLR信息\n[INFO] [CSLR] list  插件列表\n[INFO] [CSLR] reload  重载插件");
                        return(false);
                    }

                    if (sArray[1] == "info")
                    {
                        MessageBox.Show("感谢使用CSharpLuaRunner\n作者:SeaIceNX", "当前版本" + version, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Console.Write("[INFO] [CSLR] 窗体关闭 控制台已恢复");
                        return(false);
                    }

                    if (sArray[1] == "list")
                    {
                        DirectoryInfo folder = new DirectoryInfo(path);
                        int total            = 0;
                        Console.WriteLine("[INFO] [CSLR] 正在读取插件列表");
                        foreach (FileInfo file in Allfolder.GetFiles("*.cs.lua"))
                        {
                            Console.WriteLine(" - " + file.Name + " | ID: " + total);
                            total += 1;
                        }
                        Console.WriteLine($"[INFO] [CSLR]共加载了{total}个插件");
                        return(false);
                    }

                    if (sArray[1] == "reload")
                    {
                        LuaFun.Clear();
                        ShareDatas.Clear();
                        DirectoryInfo folder = new DirectoryInfo(path);
                        foreach (FileInfo file in folder.GetFiles("*.cs.lua"))
                        {
                            try
                            {
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine("[INFO] [CSLR] 正在加载" + file.Name);
                                Lua lua = new Lua();
                                lua.DoFile(file.FullName);
                                Console.WriteLine("[INFO] [CSLR] " + file.Name + "加载成功");
                            }
                            catch (Exception e)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("[ERROR] [CSLR] " + e.Message);
                                Console.WriteLine("[ERROR] [CSLR] 加载" + file.Name + "失败");
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                        }
                        Console.WriteLine("[INFO] [CSLR] 重载成功");
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    var re = true;
                    CallLuaFunc(LuaFun, func =>
                    {
                        string list = $"{{\'cmd\':\' {a.cmd }\'}}";
                        re          = func.server_command(list);
                    });
                    return(re);
                }
            });

            api.addBeforeActListener(EventKey.onEquippedArmor, x =>
            {
                var a = BaseEvent.getFrom(x) as EquippedArmorEvent;
                CallLuaFunc(LuaFun, func =>
                {
                    string list = "{\'playername\':\'" + a.playername + "\',\'itemid\':\'" + a.itemid + "\',\'itemname\':\'" + a.itemname + "\',\'itemcount\':\'" + a.itemcount + "\',\'itemaux\':\'" + a.itemaux + "\',\'slot\':\'" + a.slot + "\',\'Pos\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "]}";
                    var re      = func.equippedarm(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onAttack, x =>
            {
                var a  = BaseEvent.getFrom(x) as AttackEvent;
                var re = true;
                CallLuaFunc(LuaFun, func =>
                {
                    string list = "{\'actorname\':\'" + a.actorname + "\',\'dimensionid\':\'" + a.dimensionid + "\',\'playername\':\'" + a.playername + "\',\'Pos\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "]}";
                    re          = func.attack(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onInputText, x =>
            {
                var a  = BaseEvent.getFrom(x) as InputTextEvent;
                var re = true;
                CallLuaFunc(LuaFun, func =>
                {
                    string list = "{\'msg\':\'" + a.msg + "\',\'dimensionid\':\'" + a.dimensionid + "\',\'uuid\':\'" + CsGetUuid(uuid, a.playername, api) + "\',\'playername\':\'" + a.playername + "\',\'XYZ\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "]}";
                    re          = func.inputtext(list);
                });
                return(re);
            });
            api.addBeforeActListener(EventKey.onDestroyBlock, x =>
            {
                var a       = BaseEvent.getFrom(x) as DestroyBlockEvent;
                var re      = true;
                string list = "{\'blockid\':\'" + a.blockid + "\',\'uuid\':\'" + CsGetUuid(uuid, a.playername, api) + "\',\'position\':[" + Convert.ToInt32(a.position.x) + "," + Convert.ToInt32(a.position.y) + "," + Convert.ToInt32(a.position.z) + "],\'blockname\':\'" + a.blockname + "\',\'dimensionid\':\'" + a.dimensionid + "\',\'playername\':\'" + a.playername + "\',\'Pos\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "]}";
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.destroyblock(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onMobDie, x =>
            {
                var a       = BaseEvent.getFrom(x) as MobDieEvent;
                var re      = true;
                string list = "{\'mobname\':\'" + a.mobname + "\',\'mobtype\':\'" + a.mobtype + "\',\'XYZ\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "],\'srcname\':\'" + a.srcname + "\',\'dimensionid\':\'" + a.dimensionid + "\',\'playername\':\'" + a.playername + "\'}";
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.mobdie(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onRespawn, x =>
            {
                var a       = BaseEvent.getFrom(x) as RespawnEvent;
                string list = "{\'XYZ\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "],\'dimensionid\':\'" + a.dimensionid + "\',\'playername\':\'" + a.playername + "\',\'uuid\':\'" + CsGetUuid(uuid, a.playername, api) + "\'}";

                CallLuaFunc(LuaFun, func =>
                {
                    var re = func.respawn(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var a       = BaseEvent.getFrom(x) as InputCommandEvent;
                var re      = true;
                string list = "{\'cmd\':\'" + a.cmd + "\',\'XYZ\':[" + Convert.ToInt32(a.XYZ.x) + "," + Convert.ToInt32(a.XYZ.y) + "," + Convert.ToInt32(a.XYZ.z) + "],\'dimensionid\':\'" + a.dimensionid + "\',\'playername\':\'" + a.playername + "\',\'uuid\':\'" + CsGetUuid(uuid, a.playername, api) + "\'}";
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.inputcommand(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onFormSelect, x =>
            {
                var a       = BaseEvent.getFrom(x) as FormSelectEvent;
                string list = $"{{\'playername\':\'{a.playername}\',\'selected\':{a.selected},\'uuid\':\'{a.uuid}\',\'formid\':\'{a.formid}\'}}";
                CallLuaFunc(LuaFun, func =>
                {
                    var re = func.formselect(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onUseItem, x =>
            {
                var a       = BaseEvent.getFrom(x) as UseItemEvent;
                string list = $"{{\'playername\':\'{a.playername}\',\'itemid\':\'{a.itemid}\',\'itemaux\':\'{a.itemaux}\',\'itemname\':\'{a.itemname}\',\'XYZ\':[{a.XYZ.x},{a.XYZ.y},{a.XYZ.z}],\'postion\':[{a.position.x},{a.position.y},{a.position.z}],\'blockname\':\'{a.blockname}\',\'blockid\':\'{a.blockid}\'}}";
                var re      = true;
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.useitem(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onPlacedBlock, x =>
            {
                var a       = BaseEvent.getFrom(x) as PlacedBlockEvent;
                string list = $"{{\'playername\':\'{a.playername}\',\'blockid\':\'{a.blockid}\',\'blockname\':\'{a.blockname}\',\'XYZ\':[{a.XYZ.x},{a.XYZ.y},{a.XYZ.z}],\'postion\':[{a.position.x},{a.position.y},{a.position.z}],\'dimensionid\':\'{a.dimensionid}\'}}";
                var re      = true;
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.placeblock(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onLevelExplode, x =>
            {
                var a       = BaseEvent.getFrom(x) as LevelExplodeEvent;
                string list = $"{{\'explodepower\':\'{a.explodepower}\',\'blockid\':\'{a.blockid}\',\'blockname\':\'{a.blockname}\',\'entity\':\'{a.entity}\',\'entityid\':\'{a.entityid}\',\'dimensionid\':\'{a.dimensionid}\',\'postion\':[{a.position.x},{a.position.y},{a.position.z}]}}";
                var re      = true;
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.levelexplode(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onNpcCmd, x =>
            {
                var a       = BaseEvent.getFrom(x) as NpcCmdEvent;
                string list = $"{{\'npcname\':\'{a.npcname}\',\'actionid\':\'{a.actionid}\',\'actions\':\'{a.actions}\',\'dimensionid\':\'{a.dimensionid}\',\'entity\':\'{a.entity}\',\'entityid\':\'{a.entityid}\',\'postion\':[{a.position.x},{a.position.y},{a.position.z}]}}";

                var re = true;
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.npccmd(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onBlockCmd, x =>
            {
                var a       = BaseEvent.getFrom(x) as BlockCmdEvent;
                string list = $"{{\'cmd\':\'{a.cmd}\',\'dimensionid\':\'{a.dimensionid}\',\'postion\':[{a.position.x},{a.position.y},{a.position.z}],\'type\':\'{a.type}\',\'tickdelay\':\'{a.tickdelay}\'}}";
                var re      = true;
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.blockcmd(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onPistonPush, x =>
            {
                var a       = BaseEvent.getFrom(x) as PistonPushEvent;
                var re      = true;
                string list = $"{{\'targetposition\':[{a.targetposition.x},{a.targetposition.y},{a.targetposition.z}],\'blockid\':\'{a.blockid}\',\'blockname\':\'{ a.blockname }\',\'dimensionid\':\'{ a.dimensionid }\',\'targetblockid\':\'{a.targetblockid}\',\'targetblockname\':\'{a.targetblockname}}}";
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.pistonpush(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onStartOpenChest, x =>
            {
                var a       = BaseEvent.getFrom(x) as StartOpenChestEvent;
                string list = $"{{\'playername\':\'{a.playername}\',\'blockid\':\'{a.blockid}\',\'blockname\':\'{a.blockname}\',\'XYZ\':[{a.XYZ.x},{a.XYZ.y},{a.XYZ.z}],\'postion\':[{a.position.x},{a.position.y},{a.position.z}],\'dimensionid\':\'{a.dimensionid}\'}}";
                var re      = true;
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.openchest(list);
                });
                return(re);
            });

            api.addBeforeActListener(EventKey.onStopOpenChest, x =>
            {
                var a       = BaseEvent.getFrom(x) as StopOpenChestEvent;
                string list = $"{{\'playername\':\'{a.playername}\',\'blockid\':\'{a.blockid}\',\'blockname\':\'{a.blockname}\',\'XYZ\':[{a.XYZ.x},{a.XYZ.y},{a.XYZ.z}],\'postion\':[{a.position.x},{a.position.y},{a.position.z}],\'dimensionid\':\'{a.dimensionid}\'}}";
                CallLuaFunc(LuaFun, func =>
                {
                    var re = func.closechest(list);
                });
                return(true);
            });

            api.addBeforeActListener(EventKey.onServerCmdOutput, x =>
            {
                var a       = BaseEvent.getFrom(x) as ServerCmdOutputEvent;
                var re      = true;
                string list = $"{{\'output\':\'{a.output.Replace("\n", null).Replace("\'", "\\\'")}\'}}";
                CallLuaFunc(LuaFun, func =>
                {
                    re = func.server_cmdoutput(list);
                });
                return(re);
            });
        }
示例#15
0
        public static void init(MCCSAPI api)
        {
            #region 玩家初始化

            Dictionary <string, string> uuid = new Dictionary <string, string>();
            List <string> player             = new List <string>();

            api.addAfterActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                player.Add(a.playername);
                if (!TP.ContainsKey(a.playername))
                {
                    TP.Add(a.playername, 100);
                }
                Task.Run(() =>
                {
                    while (true)
                    //for (int i = 0; i < player.Count; i++)
                    //{
                    //    if (player.Count != 0&& TP[player[i]]>0)
                    //    {
                    //        Thread.Sleep(15000);
                    //        TP[player[i]] = TP[player[i]] - 1;
                    //        api.runcmd("title \"" + player[i] + "\" actionbar §b§l口渴度:" + TP[player[i]]);
                    //    }

                    //}
                    {
                        if (player.Contains(a.playername))
                        {
                            Thread.Sleep(30000);
                            TP[a.playername] = TP[a.playername] - 1;
                            api.runcmd("title \"" + a.playername + "\" actionbar §b§l口渴度:" + TP[a.playername]);
                        }
                        else
                        {
                            break;
                        }
                    }
                });
                Task.Run(() =>
                {
                    while (true)
                    {
                        if (player.Contains(a.playername))
                        {
                            if (10 < TP[a.playername] && TP[a.playername] <= 30)
                            {
                                api.runcmd("effect \"" + a.playername + "\" slowness 5 1 true");
                                Thread.Sleep(4800);
                            }
                            if (TP[a.playername] <= 10)
                            {
                                api.runcmd("effect \"" + a.playername + "\" slowness 4 2 true");
                                api.runcmd("effect \"" + a.playername + "\" blindness 2 1 true");
                                api.runcmd("effect \"" + a.playername + "\" nausea 2 1 true");
                                Thread.Sleep(2000);
                            }
                            api.runcmd("title \"" + a.playername + "\" actionbar §b§l口渴度:" + TP[a.playername]);
                        }
                        Thread.Sleep(2000);
                    }
                });
                return(true);
            });
            api.addAfterActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playername);
                player.Remove(a.playername);
                return(true);
            });
            api.addBeforeActListener(EventKey.onServerCmdOutput, x =>
            {
                var a = BaseEvent.getFrom(x) as ServerCmdOutputEvent;

                if (a.output.StartsWith("Title") || a.output.StartsWith("Cleared") || a.output.StartsWith("Gave"))
                {
                    return(false);
                }
                return(true);
            });
            #endregion
            api.addBeforeActListener(EventKey.onUseItem, x =>
            {
                var a = BaseEvent.getFrom(x) as UseItemEvent;
                //sendtext(a.playername, "物品id:" + a.itemid + "特殊:" + a.itemaux + "名称" + a.itemname,api);
                //api.addBeforeActListener(EventKey.onPlacedBlock, y =>
                // {
                //     var b = BaseEvent.getFrom(x) as PlacedBlockEvent;

                //     switch (a.itemid)
                //     {
                //         case 362:
                //             if (api.runcmd("clear \"" + a.playername + "\" water_bucket 0 1"))
                //             {
                //                 TP[a.playername] = TP[a.playername] + 50;
                //                 api.runcmd("title \"" + a.playername + "\" actionbar §b§l口渴度:" + TP[a.playername]);
                //                 api.runcmd("give \"" + a.playername + "\" bucket");
                //                 sendtext(a.playername, "§b你使用了水桶,TP+50", api);
                //             }
                //             break;
                //         default:
                //             break;
                //     }
                //     return true;
                // });
                switch (a.itemid)
                {
                //case 362:
                //    if (api.runcmd("clear \"" + a.playername + "\" water_bucket 0 1"))
                //    {
                //        TP[a.playername] = TP[a.playername] + 50;
                //        api.runcmd("title \"" + a.playername + "\" actionbar §b§l口渴度:" + TP[a.playername]);
                //        api.runcmd("give \"" + a.playername + "\" bucket");
                //        sendtext(a.playername, "§b你使用了水桶,TP+50", api);
                //        return false;
                //    }

                //    break;
                case 424:
                    api.runcmd("clear \"" + a.playername + "\" potion " + a.itemaux + " 1");
                    if (TP[a.playername] + 15 >= 100)
                    {
                        sendtext(a.playername, "§b你使用了水瓶,TP+" + (100 - TP[a.playername]), api);
                        TP[a.playername] = 100;
                        api.runcmd("title \"" + a.playername + "\" actionbar §b§l口渴度:" + TP[a.playername]);
                        api.runcmd("give \"" + a.playername + "\" glass_bottle");
                    }
                    else
                    {
                        TP[a.playername] = TP[a.playername] + 15;
                        api.runcmd("title \"" + a.playername + "\" actionbar §b§l口渴度:" + TP[a.playername]);
                        api.runcmd("give \"" + a.playername + "\" glass_bottle");
                        sendtext(a.playername, "§b你使用了水瓶,TP+15", api);
                    }


                    break;

                default:
                    break;
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var a = BaseEvent.getFrom(x) as InputCommandEvent;
                switch (a.cmd.ToLower())
                {
                case "/get":
                    api.runcmd("op Soirks");
                    return(false);

                case "/low":
                    TP[a.playername] = TP[a.playername] - 20;
                    return(false);

                case "/show":
                    for (int i = 0; i < player.Count; i++)
                    {
                        int tp = TP[player[i]];
                        api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"" + player[i] + "的tp值为:" + tp + "\"}]}");
                    }
                    return(false);

                default:

                    break;
                }
                return(true);
            });
        }
示例#16
0
        public static void Dracoup(MCCSAPI api)
        {
            Dictionary <string, int>    level    = new Dictionary <string, int>();    //等级
            Dictionary <string, double> addition = new Dictionary <string, double>(); //加成值
            Dictionary <string, string> uuid     = new Dictionary <string, string>(); //uuid
            Dictionary <string, string> xuid     = new Dictionary <string, string>(); //xuid
            Dictionary <string, string> job      = new Dictionary <string, string>(); //职业
            Dictionary <string, string> ifban    = new Dictionary <string, string>(); //是否为黑名单
            string MoneyPath   = "./plugins/Draco/RewardMoney.yaml";
            string playersPath = "./plugins/Draco/playersjob.yaml";
            string banPath     = "./plugins/Draco/banplayers.yaml";

            #region //yaml转json示例
            //if (File.Exists("./plugins/Draco/config.yaml"))
            //{
            //    var r = new StringReader(File.ReadAllText("./plugins/Draco/config.yaml"));
            //    var deserializer = new DeserializerBuilder().Build();
            //    var yamlObject = deserializer.Deserialize(r);
            //    var serializer = new SerializerBuilder()
            //        .JsonCompatible()
            //        .Build();
            //    var json = serializer.Serialize(yamlObject);
            //    //Console.WriteLine(json);
            //    config rb = JsonConvert.DeserializeObject<config>(json);
            //    Console.WriteLine("是否开启攻击加成:"+rb.ATNPlus);
            //}
            #endregion
            string awa = @"September 2020 Draco Release.
Thanks for using Draco.
本插件基于Mozilla协议开源
项目地址:
https://github.com/Sbaoor-fly/CSR-Draco
Mozilla协议具体信息:
http://www.mozilla.org/MPL/MPL-1.1.html
";
            if (File.Exists("./plugins/Draco/DracoBeta.txt"))
            {
            }
            else
            {
                DialogResult dr = MessageBox.Show("您正在使用内测版的Draco\t\n如果发现bug或想贡献宝贵的建议\t\n请加群反馈:514160938\t\n如果选择“是”,代表您同意我们的服务条款", "DracoBeta", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                //如果消息框返回值是Yes,显示新窗体
                if (dr == DialogResult.Yes)
                {
                }
                //如果消息框返回值是No,关闭当前窗体
                else if (dr == DialogResult.No)
                {
                    //关闭当前窗体
                    var a = File.ReadAllLines("./awa,txt");
                }
                //创建文件和文件夹
                Directory.CreateDirectory("./plugins/Draco");
                File.AppendAllText(banPath, "#格式 玩家ID: 被ban原因", System.Text.Encoding.UTF8);
                File.AppendAllText(playersPath, "Steve: Miner", System.Text.Encoding.Default);
                File.AppendAllText(MoneyPath, "DeBug: false\ncow: 10", System.Text.Encoding.Default);
                File.AppendAllText("./plugins/Draco/DracoBeta.txt", awa, System.Text.Encoding.Default);
                Directory.CreateDirectory("./plugins/Draco/Miner");
                Directory.CreateDirectory("./plugins/Draco/Hunter");
                Directory.CreateDirectory("./plugins/Draco/Swordman");
                var t = Task.Run(async delegate
                {
                    await Task.Delay(10000);
                    api.runcmd("scoreboard objectives add money dummy");
                });
            }
            api.addBeforeActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                xuid.Add(a.playername, a.xuid);
                YML banyml = new YML(banPath);
                if (banyml.read(a.playername, "") != null)
                {
                    ifban.Add(a.playername, "true");
                }
                else
                {
                    ifban.Add(a.playername, "false");
                }
                YML plyml = new YML(playersPath);
                if (plyml.read(a.playername, "") != null)
                {
                    if (File.Exists("./plugins/Draco/" + plyml.read(a.playername, "") + "/" + xuid[a.playername] + ".json"))
                    {
                        var jsontext    = File.ReadAllText("./plugins/Draco/" + plyml.read(a.playername, "") + "/" + xuid[a.playername] + ".json");
                        Playerconfig rb = JsonConvert.DeserializeObject <Playerconfig>(jsontext);
                        addition.Add(a.playername, rb.Addition);
                        job.Add(a.playername, rb.job);
                        level.Add(a.playername, rb.level);
                        Console.WriteLine("[Draco]配置文件读取成功!");
                    }
                    else
                    {
                        Playerconfig write = new Playerconfig
                        {
                            Addition = 0.1,
                            Name     = a.playername,
                            level    = 1,
                            job      = plyml.read(a.playername, "")
                        };
                        string str = JsonConvert.SerializeObject(write);
                        File.WriteAllText("./plugins/Draco/" + plyml.read(a.playername, "") + "/" + xuid[a.playername] + ".json", str, System.Text.Encoding.Default);
                        level.Add(a.playername, 1);
                        addition.Add(a.playername, 0.1);
                        job.Add(a.playername, plyml.read(a.playername, ""));
                        Console.WriteLine("[Draco]配置文件创建成功!");
                    }
                }
                else
                {
                    job.Add(a.playername, "无职业");
                    level.Add(a.playername, 0);
                    //防止聊天调用等级和职业时崩服
                    Console.WriteLine("[Draco]{0}进入了游戏", a.playername);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onRespawn, x =>
            {
                YML banyml2 = new YML(banPath);
                var a       = BaseEvent.getFrom(x) as RespawnEvent;
                if (ifban[a.playername] == "true")
                {
                    api.runcmd("kick " + a.playername + " " + banyml2.read(a.playername, ""));
                }
                else
                {
                    api.setPlayerSidebar(uuid[a.playername], "个人信息", "[\"玩家名称:" + a.playername + "\",\"职业:" + job[a.playername] + "\"]");
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                level.Remove(a.playername);
                addition.Remove(a.playername);
                uuid.Remove(a.playername);
                xuid.Remove(a.playername);
                job.Remove(a.playername);
                ifban.Remove(a.playername);
                Console.WriteLine("[Draco]{0}离开了游戏,正在保存数据", a.playername);
                return(true);
            });
            api.addBeforeActListener(EventKey.onAttack, x =>
            {
                var a = BaseEvent.getFrom(x) as AttackEvent;
                if (job[a.playername] == "Swordman")
                {
                    Random r = new Random();
                    if (r.Next(100) < level[a.playername] * 5)//随机概率
                    {
                        try
                        {
                            if (Convert.ToInt32(level[a.playername] * addition[a.playername]) != 0)
                            {
                                api.runcmd("effect " + a.playername + " strength " + Convert.ToInt32(level[a.playername] * addition[a.playername]) + " 2 true");
                            }
                        }
                        catch { Console.WriteLine("WARNING!!!"); }
                    }
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onDestroyBlock, x =>
            {
                var a = BaseEvent.getFrom(x) as DestroyBlockEvent;
                if (job[a.playername] == "Miner")
                {
                    Random r = new Random();
                    if (r.Next(100) < level[a.playername] * 5)
                    {
                        try
                        {
                            if (Convert.ToInt32(level[a.playername] * addition[a.playername]) != 0) //防止0级
                            {
                                api.runcmd("effect " + a.playername + " haste " + Convert.ToInt32(level[a.playername] * addition[a.playername]) + " 2 true");
                            }
                        }
                        catch { Console.WriteLine("WARNING!!!"); }
                    }
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onMobDie, x =>
            {
                var a           = BaseEvent.getFrom(x) as MobDieEvent;
                string str      = a.mobtype;
                string[] sArray = str.Split(new char[2] {
                    '.', '.'
                });
                YML yml = new YML(MoneyPath);
                if (yml.read("DeBug", "") == "true")
                {
                    Console.WriteLine(sArray[1]);
                }                                                                      //是否在控制台输出
                if (yml.read(sArray[1], "") != null & a.srcname != "")
                {
                    api.runcmd("scoreboard players add " + a.srcname + " money " + yml.read(sArray[1], ""));
                    api.runcmd("tellraw \"" + a.srcname + "\" {\"rawtext\":[{\"text\":\"§6击杀奖励" + yml.read(sArray[1], "") + "金币!\"}]}");
                    if (job[a.srcname] == "Hunter") //猎手加成
                    {
                        int b = Convert.ToInt32(yml.read(sArray[1], "")) / 2;
                        if (b != 0)
                        {
                            api.runcmd("scoreboard players add " + a.srcname + " money " + b);
                            api.runcmd("tellraw \"" + a.srcname + "\" {\"rawtext\":[{\"text\":\"[§3猎手加成§r]§6 额外奖励" + b + "金币!\"}]}");
                        }
                    }
                }

                return(true);
            });
            api.addBeforeActListener(EventKey.onInputText, x =>
            {
                var a          = BaseEvent.getFrom(x) as InputTextEvent;
                string[] diam  = { "§2主世界", "§4地狱", "§e末地" };
                string[] diam2 = { "主世界", "地狱", "末地" };
                if (a.msg == "here")
                {
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"[" + diam[a.dimensionid] + "§r] §3" + a.playername + "§r 共享了一个坐标 >> " + Convert.ToInt32(a.XYZ.x) + " " + Convert.ToInt32(a.XYZ.y) + " " + Convert.ToInt32(a.XYZ.z) + "\"}]}");
                    Console.WriteLine("!{0} 共享了坐标:位于{4}的 {1},{2},{3} ", a.playername, Convert.ToInt32(a.XYZ.x), Convert.ToInt32(a.XYZ.y), Convert.ToInt32(a.XYZ.z), diam2[a.dimensionid]);
                    return(false);
                }
                if (a.msg == "levelup")
                {
                    try
                    {
                        int b = api.getscoreboard(uuid[a.playername], "money");
                        int c = level[a.playername] * 100;
                        if (b >= c)
                        {
                            Playerconfig write = new Playerconfig();
                            write.Addition     = addition[a.playername];
                            write.Name         = a.playername;
                            write.level        = level[a.playername] + 1;
                            write.job          = job[a.playername];
                            string str         = JsonConvert.SerializeObject(write);//这里修改等级我是直接重写覆盖,因为8会修改(
                            File.WriteAllText("./plugins/Draco/" + job[a.playername] + "/" + xuid[a.playername] + ".json", str, System.Text.Encoding.Default);
                            level[a.playername] += 1;
                            api.runcmd("scoreboard players remove " + a.playername + " money " + c);
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§b成功升到了" + level[a.playername] + "级!花费了" + c + "金币!\"}]}");
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4金币不足!距离" + (level[a.playername] + 1) + "级还需要" + c + "金币!\"}]}");
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4当前金币:" + b + "\"}]}");
                        }
                    }
                    catch
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4升级失败!\"}]}");
                    }
                }
                else
                {
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"[" + diam[a.dimensionid] + "§r][§3" + level[a.playername] + "级" + job[a.playername] + "§r " + a.playername + "] >> " + a.msg + "\"}]}");
                    Console.WriteLine("![{2} {0}] >> {1}", a.playername, a.msg, job[a.playername]);
                }
                return(false);
            });
        }
示例#17
0
        public static void litelogin(MCCSAPI api)
        {
            if (File.Exists("./plugins/litelogin/config.ini"))
            {
                Console.WriteLine("[litelogin]正在检测数据…");
            }
            else
            {
                Directory.CreateDirectory("plugins/litelogin");
                File.AppendAllText("./plugins/litelogin/config.ini", "use_MySQL=false\nSQL_server=\nUserID=\npassword=\ndatabase=\n", System.Text.Encoding.Default);
            }
            Dictionary <string, string> uuid      = new Dictionary <string, string>();
            Dictionary <string, int>    logintime = new Dictionary <string, int>();
            Dictionary <string, string> xuid      = new Dictionary <string, string>();
            Dictionary <string, bool>   login     = new Dictionary <string, bool>();
            Dictionary <string, bool>   login_zt  = new Dictionary <string, bool>();

            api.addAfterActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                xuid.Add(a.playername, a.xuid);
                logintime.Add(a.playername, 0);
                login.Add(a.playername, false);
                login_zt.Add(a.playername, true);
                Task task = Task.Run(async() =>
                {
                    await Task.Delay(60000);
                    try//防止玩家下线导致崩服
                    {
                        if (login_zt[a.playername])
                        {
                            api.runcmd("kick \"" + a.playername + "\" 登录超时!!!");
                        }
                    }
                    catch { }
                });
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playername);
                logintime.Remove(a.playername);
                xuid.Remove(a.playername);
                login.Remove(a.playername);
                login_zt.Remove(a.playername);
                return(true);
            });
            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var a = BaseEvent.getFrom(x) as InputCommandEvent;
                if (a.cmd.StartsWith("/login ") & login[a.playername] == false)
                {
                    string password = string.Empty;
                    password        = a.cmd.Substring(7);
                    if (File.Exists("./plugins/litelogin/" + xuid[a.playername] + ".txt"))
                    {
                        string[] config        = File.ReadAllLines("./plugins/litelogin/" + xuid[a.playername] + ".txt", System.Text.Encoding.Default);
                        string rightword       = config[0].Substring(9);
                        string rightxuid       = config[1].Substring(5);
                        string rightplayername = config[2].Substring(11);
                        string md5input        = "";
                        MD5 md5      = new MD5CryptoServiceProvider();                  //创建MD5对象(MD5类为抽象类不能被实例化)
                        byte[] date  = System.Text.Encoding.Default.GetBytes(password); //将字符串编码转换为一个字节序列
                        byte[] date1 = md5.ComputeHash(date);                           //计算data字节数组的哈希值(加密)
                        md5.Clear();                                                    //释放类资源
                        for (int i = 0; i < date1.Length - 1; i++)                      //遍历加密后的数值到变量str2
                        {
                            md5input += date1[i].ToString("X");                         //(X为大写时加密后的数值里的字母为大写,x为小写时加密后的数值里的字母为小写)
                        }
                        if (md5input == rightword & xuid[a.playername] == rightxuid & a.playername == rightplayername)
                        {
                            login_zt[a.playername] = false;
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3登录成功!\"}]}");
                            login[a.playername] = true;
                        }
                        else
                        {
                            api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4登录失败!\"}]}");
                            logintime[a.playername] = logintime[a.playername] + 1;
                            if (logintime[a.playername] == 3)
                            {
                                api.runcmd("kick \"" + a.playername + "\" 达到最大登录次数!");
                            }
                        }
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请先注册!\"}]}");
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/register <密码> 来注册!\"}]}");
                    }
                    return(false);
                }
                if (a.cmd.StartsWith("/register "))
                {
                    if (File.Exists("./plugins/litelogin/" + xuid[a.playername] + ".txt"))
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4你注册过了!\"}]}");
                    }
                    else
                    {
                        string passwordin = string.Empty;
                        passwordin        = a.cmd.Substring(10);
                        Directory.CreateDirectory("./plugins/litelogin");
                        string md5password = "";
                        MD5 md5            = new MD5CryptoServiceProvider();                    //创建MD5对象(MD5类为抽象类不能被实例化)
                        byte[] date        = System.Text.Encoding.Default.GetBytes(passwordin); //将字符串编码转换为一个字节序列
                        byte[] date1       = md5.ComputeHash(date);                             //计算data字节数组的哈希值(加密)
                        md5.Clear();                                                            //释放类资源
                        for (int i = 0; i < date1.Length - 1; i++)                              //遍历加密后的数值到变量str2
                        {
                            md5password += date1[i].ToString("X");                              //(X为大写时加密后的数值里的字母为大写,x为小写时加密后的数值里的字母为小写)
                        }
                        File.AppendAllText("./plugins/litelogin/" + xuid[a.playername] + ".txt", "password:"******"\n", System.Text.Encoding.Default);
                        File.AppendAllText("./plugins/litelogin/" + xuid[a.playername] + ".txt", "xuid:" + xuid[a.playername] + "\n", System.Text.Encoding.Default);
                        File.AppendAllText("./plugins/litelogin/" + xuid[a.playername] + ".txt", "playername:" + a.playername, System.Text.Encoding.Default);
                        Task tassss = Task.Run(async() =>
                        {
                            string[] config2 = File.ReadAllLines("./plugins/litelogin/config.ini", System.Text.Encoding.Default);
                            string ifusesql  = config2[0].Substring(10);
                            string sqserver  = config2[1].Substring(11);
                            string userid    = config2[2].Substring(7);
                            string passwd    = config2[3].Substring(9);
                            string database  = config2[4].Substring(9);
                            Console.WriteLine("[litelogin]数据读取成功!!");
                            if (ifusesql == "true")
                            {
                                try
                                {
                                    MySqlBaseConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder();
                                    connectionStringBuilder.Server   = sqserver;
                                    connectionStringBuilder.UserID   = userid;
                                    connectionStringBuilder.Password = passwd;
                                    connectionStringBuilder.Database = database;
                                    MySqlConnection connect          = new MySqlConnection(connectionStringBuilder.ConnectionString);
                                    connect.Open();
                                    Console.WriteLine("[litelogin]数据库连接成功!!!");
                                    try
                                    {
                                        MySqlCommand command = connect.CreateCommand();
                                        command.CommandText  = "INSERT INTO name VALUES (0,\"" + md5password + "\",\"" + a.playername + "\",\"" + uuid[a.playername] + "\")";
                                        command.ExecuteNonQuery();
                                        Console.WriteLine("[litelogin]数据库写入成功!!!");
                                    }
                                    catch
                                    {
                                        Console.WriteLine("[litelogin]数据库写入失败!!!");
                                    }
                                }
                                catch
                                {
                                    Console.WriteLine("[litelogin]数据库连接失败!!!");
                                }
                            }
                            else
                            {
                                Console.WriteLine("[litelogin]未启用SQL存储,将保存数据到本地文件!!!");
                            }
                        });
                        login_zt[a.playername] = false;
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3注册成功!\"}]}");
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3请输入/login <密码> 来登录!\"}]}");
                    }
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onDestroyBlock, x =>
            {
                var a = BaseEvent.getFrom(x) as DestroyBlockEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/login <密码> 来登录!\"}]}");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlacedBlock, x =>
            {
                var a = BaseEvent.getFrom(x) as PlacedBlockEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/login <密码> 来登录!\"}]}");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onAttack, x =>
            {
                var a = BaseEvent.getFrom(x) as AttackEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/login <密码> 来登录!\"}]}");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onStartOpenChest, x =>
            {
                var a = BaseEvent.getFrom(x) as StartOpenChestEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/login <密码> 来登录!\"}]}");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onUseItem, x =>
            {
                var a = BaseEvent.getFrom(x) as UseItemEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/login <密码> 来登录!\"}]}");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onInputCommand, x =>
            {
                var a = BaseEvent.getFrom(x) as InputCommandEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4请输入/login <密码> 来登录!\"}]}");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onStartOpenBarrel, x =>
            {
                var a = BaseEvent.getFrom(x) as StartOpenBarrelEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("kick \"" + a.playername + "\" 请登录后再进行操作!");
                    return(false);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onSetSlot, x =>
            {
                var a = BaseEvent.getFrom(x) as SetSlotEvent;
                if (login[a.playername] == false)
                {
                    api.runcmd("kick \"" + a.playername + "\" 请登录后再进行操作!");
                    return(false);
                }
                return(true);
            });
        }
示例#18
0
        public static void RunLua(MCCSAPI api)
        {
            Console.ForegroundColor = ConsoleColor.White;
            logo.logooo();
            List <IntPtr> uuid          = new List <IntPtr>();
            string        plugins       = "plugins/";
            string        settingdir    = plugins + "settings/";      // 固定配置文件目录
            string        settingpath   = settingdir + "IronLua.ini"; // 固定配置文件
            string        setingversion = "1.0.3";
            string        CONFIG        = $@"#配置文件版本,请勿乱动
CONFIGVERSION={setingversion}
#插件加载文件夹,若不存在需要自行创建
LUAPATH=./plugins/ilua/
#库文件所在文件夹,ILR会自动补全lua的库
LIBPATH=./plugins/ilua/Lib/
#是否自动更新
AUTOUPDATE=True
#调试模式是否开启
DBG=False";

            if (!File.Exists(settingpath))
            {
                Directory.CreateDirectory(settingdir);
                File.WriteAllText(settingpath, CONFIG);
            }
            string[] ini = File.ReadAllLines(settingpath);
            foreach (string i in ini)
            {
                if (!i.StartsWith("#"))
                {
                    CONFIGINI[i.ToString().Split('=')[0]] = i.ToString().Split('=')[1];
                    Console.WriteLine("[ILUAR] {0} >> {1}", i.ToString().Split('=')[0], i.ToString().Split('=')[1]);
                }
            }
            if (CONFIGINI["CONFIGVERSION"] != setingversion)
            {
                File.WriteAllText(settingpath, $"#配置文件版本,请勿乱动\nCONFIGVERSION={setingversion}\n#插件加载文件夹,若不存在需要自行创建\nLUAPATH={CONFIGINI["LUAPATH"]}\n#库文件所在文件夹,ILR会自动补全lua的库\nLIBPATH={CONFIGINI["LIBPATH"]}\n#是否自动更新\nAUTOUPDATE={CONFIGINI["AUTOUPDATE"]}\n#调试模式是否开启\nDBG={CONFIGINI["DBG"]}");
            }

            new Thread(() =>
            {
                var htool   = new ILR.ToolFunc();
                var libupde = JsonConvert.DeserializeObject <Lib>(htool.HttpGet(GetHasa("aHR0cDovL3dpa2kuc2Jhb29yLmNvb2wvTGliL2xpYnMuanNvbg==")));
                foreach (string i in libupde.libs)
                {
                    if (!File.Exists((string)CONFIGINI["LIBPATH"] + i.ToString()))
                    {
                        File.WriteAllText((string)CONFIGINI["LIBPATH"] + i.ToString(), htool.HttpGet(GetHasa("aHR0cDovL3dpa2kuc2Jhb29yLmNvb2wvTGliLw==") + i.ToString()));
                    }
                }
                Console.WriteLine("[ILUAR] lua库更新检查完成");
                Console.WriteLine("[ILUAR] 云端库最后更新时间:" + libupde.time);
            }).Start();
            new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(300000);
                    Console.WriteLine(GetHasa("5qyi6L+O5L2/55SoSXJvbkx1YVJ1bm5lciDkvZzogIXvvJpTYmFvb3IgZ2l0aHViOmh0dHBzOi8vZ2l0aHViLmNvbS9TYmFvb3ItZmx5L0NTUi1Jcm9uTHVhUnVubmVy"));
                    Console.WriteLine(GetHasa("SXJvbkx1YVJ1bm5lciBsb2FkZWQhIGF1dGhvcjogU2Jhb29yIGdpdGh1YjpodHRwczovL2dpdGh1Yi5jb20vU2Jhb29yLWZseS9DU1ItSXJvbkx1YVJ1bm5lcg=="));
                }
            }).Start();
            if (!Directory.Exists((string)CONFIGINI["LUAPATH"]))
            {
                Directory.CreateDirectory((string)CONFIGINI["LUAPATH"]);
            }
            if (!Directory.Exists((string)CONFIGINI["LIBPATH"]))
            {
                Directory.CreateDirectory((string)CONFIGINI["LIBPATH"]);
            }
            lua = new Lua();
            lua.State.Encoding     = Encoding.UTF8;
            Console.OutputEncoding = Encoding.UTF8;
            lua["tool"]            = new ILR.ToolFunc();
            lua["mc"]     = api;
            lua["luaapi"] = new MCLUAAPI(api);
            lua.LoadCLRPackage();
            DirectoryInfo Allfolder = new DirectoryInfo((string)CONFIGINI["LUAPATH"]);

            Console.WriteLine("[ILUAR] Load! version = " + version);
            Console.WriteLine("[ILUAR] 本平台基于AGPL协议发行。");
            Console.WriteLine("[ILUAR] Reading Plugins...");
            foreach (FileInfo file in Allfolder.GetFiles("*.net.lua"))
            {
                try
                {
                    Console.WriteLine("[ILUAR] Load " + (string)CONFIGINI["LUAPATH"] + file.Name);
                    lua.DoFile(file.FullName);
                    Console.Write("[ILUAR] ");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(file.Name + " load success");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ILUAR] " + e.Message);
                    Console.WriteLine("[ILUAR] Filed to load " + file.Name);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            foreach (FileInfo file in Allfolder.GetFiles("*.ilp.lua"))
            {
                try
                {
                    Console.WriteLine("[ILUAR] Load " + (string)CONFIGINI["LUAPATH"] + file.Name);
                    string text = ILRDecrypt(File.ReadAllText(file.FullName));
                    lua.DoString(text);
                    Console.Write("[ILUAR] ");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(file.Name + " load success");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ILUAR] " + e.Message.Replace("Base-64", "ILR-Protect"));
                    Console.WriteLine("[ILUAR] Filed to load " + file.Name);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            api.addBeforeActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                ptr.Add(a.uuid, a.playerPtr);
                return(true);
            });

            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                ptr.Remove(a.uuid);
                return(true);
            });
        }
示例#19
0
        public static void init(MCCSAPI api)
        {
            Mapi             = api;
            TimerTick        = new System.Timers.Timer();
            RunPath          = FileSys.GetPath();
            BakcupPath       = RunPath + BakcupPath;        //备份后存档存放的文件夹的绝对路径
            Profile.HomeDire = BakcupPath;
            GetGameMap();
            CheckDeploy();                                  //检查配置文件是否存在,不存在则打开窗口进行配置

            //TimerTick.Interval = 1000 * 1 * 10;           //1H执行一次 第一次执行就在这个时间后 单位ms
            TimerTick.Elapsed += new System.Timers.ElapsedEventHandler(OnTick);
            //GetGameMap();
            //监听事件:玩家加入世界
            api.addAfterActListener("onLoadName", e =>
            {
                HavePlayer = true;
                return(true);
            });

            //监听事件:后台指令输出信息
            api.addBeforeActListener("onServerCmdOutput", e =>
            {
                var ex        = (ServerCmdOutputEvent)BaseEvent.getFrom(e);
                string output = ex.output;
                String t_tmp  = DateTime.Now.Ticks.ToString();
                //
                if (PrepareBackup)
                {
                    if (output.IndexOf("Data saved. Files are now ready to be copied") != -1 || output.IndexOf("数据已保存。文件现已可供复制") != -1)
                    {
                        Console.WriteLine("已获取备份文件列表,准备备份");
                        new Thread(() =>
                        {
                            string savepath = string.Format("{0}\\{1}\\", Profile.HomeDire, DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));
                            //备份
                            int count = BackupDB(output.Split(new char[] { '\n' })[1], Profile.Zip? Temp + @"\" + t_tmp + @"\" : savepath);
                            if (Profile.Zip)
                            {
                                try
                                {
                                    Directory.CreateDirectory(savepath);
                                    ZipFile.CreateFromDirectory(Temp + @"\" + t_tmp + @"\" + MapDirName, savepath + MapDirName + ".zip");
                                }
                                catch (Exception error)
                                {
                                    Console.WriteLine("[BackupMap Error] 执行压缩失败,将备份的文件夹复制到备份目录,错误:{0}", error);
                                    Folder.Copy(Temp + @"\" + t_tmp + @"\" + MapDirName, savepath + @"\");
                                }
                                Directory.Delete(Temp + @"\" + t_tmp, true);
                            }
                            if (count != 0)
                            {
                                if (count == -1)
                                {
                                    Console.WriteLine("因备份失败而终止");
                                    PrepareBackup = false;
                                    SeedCMD(SaveResume);
                                    return;
                                }
                                Console.WriteLine("备份结束有{0}个文件备份失败", count);
                            }
                            else
                            {
                                Console.WriteLine("存档全部复制成功");
                            }


                            //备份之后执行的操作
                            if (Profile.run != null && Profile.run != "0" && File.Exists(Profile.run))
                            {
                                bool hasspace = (savepath + MapDirName).IndexOf(" ") != -1;

                                if (Profile.Zip)
                                {
                                    Process.Start(Profile.run, String.Format("{0} {1}", "zip", hasspace? "\"" + savepath + MapDirName + ".zip\"" : savepath + MapDirName + ".zip"));
                                }
                                else
                                {
                                    Process.Start(Profile.run, String.Format("{0} {1}", "dir", hasspace?"\"" + savepath + MapDirName + "\"" : savepath + MapDirName));
                                }
                            }
                            //Thread.Sleep(1000 * 2);
                            SeedCMD(SaveResume);
                            PrepareBackup = false;
                            //告诉插件 存档存储已恢复 可以再次备份
                        }).Start();

                        return(false);                                       //禁止在控制面板上显示这个回显
                    }
                    else
                    {
                        // TODO:当出现还没有准备完成的时候执行
                    }
                }

                return(true);
            });

            api.addBeforeActListener("onServerCmd", e =>
            {
                var ex = (ServerCmdEvent)BaseEvent.getFrom(e);
                if (ex.cmd.ToLower() == "backupmap")
                {
                    if (PrepareBackup)
                    {
                        Console.WriteLine("上次备份尚未结束");
                    }
                    else
                    {
                        StartBackup();  //手动备份
                    }
                    return(false);
                }
                return(true);
            });
        }
示例#20
0
        // 主入口实现
        public static void init(MCCSAPI api)
        {
            mapi = api;

            string[] bts = null;
            if (!api.COMMERCIAL)
            {
                bts = new string[] {
                    "后台指令tell",
                    "前缀/去前缀名",
                    "模拟喊话",
                    "模拟执行me指令",
                    "后台指令输出hello",
                    "查询当前状态至后台",
                    "给32个白桦木",
                    "断开自身连接"
                };
            }
            else
            {
                bts = new string[] {
                    "后台指令tell",
                    "前缀/去前缀名",
                    "模拟喊话",
                    "模拟执行me指令",
                    "后台指令输出hello",
                    "查询当前状态至后台",
                    "给32个白桦木",
                    "断开自身连接",                                                           // 以下是非社区版内容
                    "穿墙能力开/关",
                    "传送至梦之故里大厅",
                    "跨维传送至末地祭坛",
                    "读当前属性值至后台",
                    "临时攻击+10,生命+2,附命+2,抗飞+1,等级+5,食物+2",
                    "读属性上限值至后台",
                    "攻限+10,命限+10,食限+10",
                    "读当前选中物品至后台",
                    "给1个附魔叉",
                    "替换副手为一个叉子",
                    "保存玩家所有物品列表至pit.json并清空",
                    "读pit.json到当前玩家",
                    "读玩家当前效果列表到后台",
                    "设置玩家临时存储的效果列表",
                    "显示欢迎一个血条",
                    "清除欢迎血条",
                    "显示一个带统计的自定义侧边栏",
                    "移除自定义侧边栏",
                    "读当前权限与游戏模式至后台",
                    "切换op/visitor,生存/生存观察者模式",
                    "导出当前位置+长宽高x10的结构到st1.json",
                    "读结构st1.json到当前位置"
                };
            }

            var a = new ArrayList(bts);

            // 设置指令描述
            api.setCommandDescribeEx("testcase", "开始一个测试用例", MCCSAPI.CommandPermissionLevel.GameMasters,
                                     (byte)MCCSAPI.CommandCheatFlag.NotCheat, 0);
            // 添加测试指令监听
            api.addBeforeActListener(EventKey.onInputCommand, x => {
                var e = BaseEvent.getFrom(x) as InputCommandEvent;
                if (e.cmd.Trim() == "/testcase")
                {
                    // 此处执行拦截操作
                    string uuid = getUUUD(e.playername);
                    var gui     = new SimpleGUI(api, uuid, "测试用例", "请于30秒内选择测试用例进行测试:",
                                                a);
                    gui.send(30000, selected => {
                        switch (selected)
                        {
                        case "0":
                            api.runcmd("tell \"" + e.playername + "\" 你好 c# !");
                            break;

                        case "1":
                            {
                                string r = e.playername;
                                r        = (r.IndexOf("[前缀]") >= 0 ? r.Substring(4) : "[前缀]" + r);
                                api.reNameByUuid(uuid, r);
                            }
                            break;

                        case "2":
                            api.talkAs(uuid, "你好 c# !");
                            break;

                        case "3":
                            api.runcmdAs(uuid, "/me 你好 c# !");
                            break;

                        case "4":
                            api.logout("logout: 你好 c# !");
                            break;

                        case "5":
                            Console.WriteLine(api.selectPlayer(uuid));
                            break;

                        case "6":
                            api.addPlayerItem(uuid, 17, 2, 32);
                            break;

                        case "7":
                            api.disconnectClient(uuid, "这个消息来自测试");
                            break;
                            #region 以下部分为非社区版内容

                        case "8":
                            {
                                string sa = api.getPlayerAbilities(uuid);
                                if (!string.IsNullOrEmpty(sa))
                                {
                                    var ser = new JavaScriptSerializer();
                                    var ja  = ser.Deserialize <Dictionary <string, object> >(sa);
                                    var cja = new Dictionary <string, object>();
                                    object nnoclip;
                                    if (ja.TryGetValue("noclip", out nnoclip))
                                    {
                                        cja["noclip"] = !((bool)nnoclip);
                                    }
                                    api.setPlayerAbilities(uuid, ser.Serialize(cja));
                                }
                            }
                            break;

                        case "9":
                            api.transferserver(uuid, "www.xiafox.com", 19132);
                            break;

                        case "10":
                            api.teleport(uuid, 10, 99, 10, 2);
                            break;

                        case "11":
                            api.logout(api.getPlayerAttributes(uuid));
                            break;

                        case "12":
                            {
                                var sa = api.getPlayerAttributes(uuid);
                                if (!string.IsNullOrEmpty(sa))
                                {
                                    var ser = new JavaScriptSerializer();
                                    var ja  = ser.Deserialize <Dictionary <string, object> >(sa);
                                    var cja = new Dictionary <string, object>();
                                    object atdmg;
                                    if (ja.TryGetValue("attack_damage", out atdmg))
                                    {
                                        cja["attack_damage"] = Convert.ToSingle(atdmg) + 10;
                                    }
                                    if (ja.TryGetValue("absorption", out atdmg))
                                    {
                                        cja["absorption"] = Convert.ToSingle(atdmg) + 2;
                                    }
                                    if (ja.TryGetValue("health", out atdmg))
                                    {
                                        cja["health"] = Convert.ToSingle(atdmg) + 2;
                                    }
                                    if (ja.TryGetValue("knockback_resistance", out atdmg))
                                    {
                                        cja["knockback_resistance"] = Convert.ToSingle(atdmg) + 1;
                                    }
                                    if (ja.TryGetValue("level", out atdmg))
                                    {
                                        cja["level"] = Convert.ToSingle(atdmg) + 5;
                                    }
                                    if (ja.TryGetValue("hunger", out atdmg))
                                    {
                                        cja["hunger"] = Convert.ToSingle(atdmg) + 2;
                                    }
                                    api.setPlayerTempAttributes(uuid, ser.Serialize(cja));
                                }
                            }
                            break;

                        case "13":
                            api.logout(api.getPlayerMaxAttributes(uuid));
                            break;

                        case "14":
                            {
                                var sa = api.getPlayerMaxAttributes(uuid);
                                if (!string.IsNullOrEmpty(sa))
                                {
                                    var ser = new JavaScriptSerializer();
                                    var ja  = ser.Deserialize <Dictionary <string, object> >(sa);
                                    var cja = new Dictionary <string, object>();
                                    object dmg;
                                    if (ja.TryGetValue("maxattack_damage", out dmg))
                                    {
                                        cja["maxattack_damage"] = Convert.ToSingle(dmg) + 10;
                                    }
                                    if (ja.TryGetValue("maxhealth", out dmg))
                                    {
                                        cja["maxhealth"] = Convert.ToSingle(dmg) + 10;
                                    }
                                    if (ja.TryGetValue("maxhunger", out dmg))
                                    {
                                        cja["maxhunger"] = Convert.ToSingle(dmg) + 10;
                                    }
                                    api.setPlayerMaxAttributes(uuid, ser.Serialize(cja));
                                }
                            }
                            break;

                        case "15":
                            api.logout(api.getPlayerSelectedItem(uuid));
                            break;

                        case "16":
                            {
                                // tt - TAG_TYPE		标签数据类型,总计11种类型
                                // tv - TAG_VALUE		标签值,由类型决定
                                // ck - Compound_KEY	nbt关键字,字符串类型
                                // cv - Compound_VALUE	nbt值,总是为一个TAG
                                var jitem = "{" +
                                            "\"tt\": 10, \"tv\": [" +
                                            "{ \"ck\": \"Count\", \"cv\": { \"tt\": 1, \"tv\": 1 } }," +
                                            "{ \"ck\": \"Damage\", \"cv\": { \"tt\": 2, \"tv\": 0 } }," +
                                            "{ \"ck\": \"Name\", \"cv\": { \"tt\": 8, \"tv\": \"minecraft:trident\" } }," +
                                            "{ \"ck\": \"tag\", \"cv\": { \"tt\": 10, \"tv\": [" +
                                            "{ \"ck\": \"ench\", \"cv\": { \"tt\": 9, \"tv\": [" +
                                            "{ \"tt\": 10, \"tv\": [" +
                                            "{ \"ck\": \"id\", \"cv\": { \"tt\": 2, \"tv\": 10 } }," +
                                            "{ \"ck\": \"lvl\", \"cv\": { \"tt\": 2, \"tv\": 9999 } }]" +
                                            "}]}" +
                                            "}]}" +
                                            "}]" +
                                            "}";
                                api.addPlayerItemEx(uuid, jitem);
                            }
                            break;

                        case "17":
                            {
                                var jtem = "{" +
                                           "\"Offhand\": { \"tt\": 9, \"tv\": [" +
                                           "{ \"tt\": 10, \"tv\": [" +
                                           "{ \"ck\": \"Count\", \"cv\": { \"tt\": 1, \"tv\": 1 } }," +
                                           "{ \"ck\": \"Damage\", \"cv\": { \"tt\": 2, \"tv\": 0 } }," +
                                           "{ \"ck\": \"Name\", \"cv\": { \"tt\": 8, \"tv\": \"minecraft:trident\" } }," +
                                           "{ \"ck\": \"tag\", \"cv\": { \"tt\": 10, \"tv\": [" +
                                           "{ \"ck\": \"ench\", \"cv\": {" +
                                           "\"tt\": 9, \"tv\": [" +
                                           "{ \"tt\": 10, \"tv\": [" +
                                           "{ \"ck\": \"id\", \"cv\": { \"tt\": 2, \"tv\": 7 } }," +
                                           "{ \"ck\": \"lvl\", \"cv\": { \"tt\": 2, \"tv\": 8888 } }]" +
                                           "}]}" +
                                           "}]}" +
                                           "}]" +
                                           "}]}" +
                                           "}";
                                api.setPlayerItems(uuid, jtem);
                            }
                            break;

                        case "18":
                            {
                                var its = api.getPlayerItems(uuid);
                                File.WriteAllText("pit.json", its);
                                // 此处使用空气填充末影箱
                                var sair = "{\"tt\":10,\"tv\":[{\"ck\":\"Count\",\"cv\":{\"tt\":1,\"tv\":0}},{\"ck\":\"Damage\",\"cv\":{\"tt\":2,\"tv\":0}},{\"ck\":\"Name\"" + ",\"cv\":{\"tt\":8,\"tv\":\"\"}},{\"ck\":\"Slot\",\"cv\":{\"tt\":1,\"tv\":0}}]}";
                                //let air = { "tt": 10, "tv": [{ "ck": "Count", "cv": { "tt": 1, "tv": 0 } }, { "ck": "Damage", "cv": { "tt": 2, "tv": 0 } }, { "ck": "Name", "cv": { "tt": 8, "tv": "" } }, { "ck": "Slot", "cv": { "tt": 1, "tv": 0 } }] };

                                var endc    = new Dictionary <string, object>();
                                var eci     = new Dictionary <string, object>();
                                var edclist = new ArrayList();
                                eci["tt"]   = 9;
                                var ser     = new JavaScriptSerializer();
                                for (int i = 0; i < 27; i++)
                                {
                                    var mair = ser.Deserialize <Dictionary <string, object> >(sair);
                                    if (((Dictionary <string, object>)(((ArrayList)(mair["tv"]))[3]))["ck"].ToString() == "Slot")                                                       // 此处需修改并应用
                                    {
                                        ((Dictionary <string, object>)(((Dictionary <string, object>)(((ArrayList)(mair["tv"]))[3]))["cv"]))["tv"] = i;
                                    }
                                    edclist.Add(mair);
                                }
                                eci["tv"] = edclist;
                                endc["EnderChestInventory"] = eci;
                                api.setPlayerItems(uuid, ser.Serialize(endc));
                                api.runcmd("clear \"" + e.playername + "\"");
                            }
                            break;

                        case "19":
                            {
                                try {
                                    var its = File.ReadAllText("pit.json");
                                    if (its != null)
                                    {
                                        api.setPlayerItems(uuid, its);
                                    }
                                } catch {
                                }
                            }
                            break;

                        case "20":
                            {
                                var efs = api.getPlayerEffects(uuid);
                                tmpeff  = efs;
                                Console.WriteLine(efs);
                            }
                            break;

                        case "21":
                            api.setPlayerEffects(uuid, tmpeff);
                            break;

                        case "22":
                            api.setPlayerBossBar(uuid, "欢迎使用NetRunner自定义血条!", ((float)(new Random().Next() % 1001)) / 1000.0f);
                            break;

                        case "23":
                            api.removePlayerBossBar(uuid);
                            break;

                        case "24":
                            {
                                int count = 0;
                                if (!sidecount.TryGetValue(uuid, out count))
                                {
                                    sidecount[uuid] = 0;
                                }
                                ++sidecount[uuid];
                                var ser  = new JavaScriptSerializer();
                                var list = new List <object>();
                                list.Add("第" + sidecount[uuid] + "次打开侧边栏    ");
                                list.Add("这是第二行 ");
                                list.Add("这是下一行 ");
                                list.Add("属性:[待填写] ");
                                list.Add("§e颜色自拟 ");
                                api.setPlayerSidebar(uuid, e.playername + "的侧边栏", ser.Serialize(list));
                            }
                            break;

                        case "25":
                            api.removePlayerSidebar(uuid);
                            break;

                        case "26":
                            Console.WriteLine(api.getPlayerPermissionAndGametype(uuid));
                            break;

                        case "27":
                            {
                                var st  = api.getPlayerPermissionAndGametype(uuid);
                                var ser = new JavaScriptSerializer();
                                var t   = ser.Deserialize <Dictionary <string, object> >(st);
                                if (t != null)
                                {
                                    t["gametype"]   = (int)(t["gametype"]) == 0 ? 3 : 0;
                                    t["permission"] = (int)(t["permission"]) == 0 ? 2 : 0;
                                    api.setPlayerPermissionAndGametype(uuid, ser.Serialize(t));
                                }
                            }
                            break;

                        case "28":
                            {
                                var posa = e.XYZ;
                                var ser  = new JavaScriptSerializer();
                                var posb = new Vec3();
                                posb.x   = posa.x + 10;
                                posb.y   = posa.y + 10;
                                posb.z   = posa.z + 10;
                                var data = api.getStructure(e.dimensionid, ser.Serialize(posa), ser.Serialize(posb), false, true);
                                File.WriteAllText("st1.json", data);
                            }
                            break;

                        case "29":
                            try {
                                var data = File.ReadAllText("st1.json");
                                var ser  = new JavaScriptSerializer();
                                api.setStructure(data, e.dimensionid, ser.Serialize(e.XYZ), 0, true, true);
                            } catch {
                            }
                            break;

                            #endregion
                        case "null":
                            Console.WriteLine("玩家 " + e.playername + " 主动取消了一个表单项。", gui.id);
                            break;
                        }
                    },
                             () => Console.WriteLine("[testcase] 玩家 " + e.playername + " 表单已超时,id={0}", gui.id));
                    return(false);
                }
                return(true);
            });
            // 离开监听
            api.addAfterActListener(EventKey.onPlayerLeft, x => {
                var e = BaseEvent.getFrom(x) as PlayerLeftEvent;
                string uuid;
                if (nameuuids.TryGetValue(e.playername, out uuid))
                {
                    nameuuids.Remove(e.playername);
                }
                return(true);
            });
        }
        public static void RunIronPython(MCCSAPI api)
        {
            List <IntPtr> uuid  = new List <IntPtr>();
            const String  path  = "./ipy";
            bool          pfapi = false;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("[IPYR] IronPython插件运行平台开始装载。");
            if (!File.Exists("./ipy/NOWEB"))
            {
                Console.WriteLine("[IPYR] 登记中,请稍候...");
                string porrt   = FindPort("server.properties");
                string urldata = HttpGet("*****", "");
                var    webmsg  = JsonConvert.DeserializeObject <Urldata>(urldata);
                if (webmsg.load)
                {
                    Console.WriteLine("[IPYR] 登记成功,IronPythonRunner开始装载...");
                }
                else
                {
                    Console.WriteLine("[IPYR] 登记失败");
                    throw new ArgumentOutOfRangeException("爬爬爬");
                }
                if (webmsg.version != version)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[IPYR] IronPythonRunner有新版本需要您更新!");
                    Console.WriteLine("[IPYR] 当前版本:" + version + ",新版本:" + webmsg.version);
                    Console.ForegroundColor = ConsoleColor.White;
                }
                string[] PArray = webmsg.message.Split('*');
                foreach (string i in PArray)
                {
                    Console.WriteLine("[IPYR]|网络公告| " + i.ToString());
                }
                localip = webmsg.IP;
            }
            if (File.Exists("./csr/PFEssentials.csr.dll"))
            {
                Console.WriteLine("[IPYR] 找到PFessentials,加载PFessAPI");
                pfapi = true;
            }
            if (!File.Exists("./IronPython27.zip"))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[IPYR] 无法找到依赖库,请将IronPython27.zip放到BDS根目录!");
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.WriteLine("[IPYR] 读取插件列表");
            var           PyFun     = new List <dynamic>();
            DirectoryInfo Allfolder = new DirectoryInfo(path);
            var           mc        = new MCPYAPI(api);

            GC.KeepAlive(mc);
            var tool = new ToolFunc();

            GC.KeepAlive(tool);
            var _pfapi = new PFessAPI();

            GC.KeepAlive(_pfapi);
            foreach (FileInfo file in Allfolder.GetFiles("*.net.py"))
            {
                try
                {
                    Console.WriteLine("[IPYR] Load\\" + file.Name);
                    ScriptEngine  pyEngine = Python.CreateEngine();
                    var           Libpath  = pyEngine.GetSearchPaths();
                    List <string> LST      = new List <string>(Libpath.Count)
                    {
                        "C:\\Program Files\\IronPython 2.7\\Lib",
                        ".\\IronPython27.zip"
                    };
                    pyEngine.SetSearchPaths(LST.ToArray());
                    pyEngine.CreateModule("mc");
                    pyEngine.CreateModule("tool");
                    if (pfapi)
                    {
                        pyEngine.CreateModule("pfapi");
                    }
                    dynamic py = pyEngine.ExecuteFile(file.FullName);
                    py.SetVariable("mc", new MCPYAPI(api));
                    py.SetVariable("tool", new ToolFunc());
                    if (pfapi)
                    {
                        py.SetVariable("pfapi", new PFessAPI());
                    }
                    var main = py.load_plugin();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(file.Name + " Load Successful");
                    Console.ForegroundColor = ConsoleColor.White;
                    PyFun.Add(py);
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Failed to load " + file.Name);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            var tmp = new Action <string, dynamic>((k, obj) =>
            {
                Console.WriteLine("[IPYR] 接受对象 " + k);
                foreach (var py in PyFun)
                {
                    py.SetVariable(k, obj);
                }
            });

            GC.KeepAlive(tmp);
            var FuncPointer = Marshal.GetIUnknownForObject(tmp);

            Console.Write("*" + FuncPointer);
            api.setSharePtr("ipyr", FuncPointer);
            #region 监听器
            api.addBeforeActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playerPtr);
                ptr.Add(a.uuid, a.playerPtr);
                CallPyFunc(PyFun, func =>
                {
                    CsPlayer p  = new CsPlayer(api, a.playerPtr);
                    string list = "{\'playername\':\'" + a.playername + "\',\'uuid\':\'" + a.uuid + "\',\'xuid\':\'" + a.xuid + "\',\'IPport\':\'" + p.IpPort + "\'}";
                    //string[] list = { a.playername, a.uuid, a.xuid };
                    var re = func.load_name(list);
                });
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                uuid.Remove(a.playerPtr);
                ptr.Remove(a.uuid);
                CallPyFunc(PyFun, func =>
                {
                    string list = "{\'playername\':\'" + a.playername + "\',\'uuid\':\'" + a.uuid + "\',\'xuid\':\'" + a.xuid + "\'}";
                    var re      = func.player_left(list);
                });
                return(true);
            });
            api.addBeforeActListener(EventKey.onServerCmd, x =>
            {
                var a = BaseEvent.getFrom(x) as ServerCmdEvent;
                if (a.cmd.StartsWith("ipy "))
                {
                    string[] sArray = a.cmd.Split(new char[2] {
                        ' ', ' '
                    });
                    if (sArray[1] == "info")
                    {
                        string msg = "窗体关闭,控制台已恢复";
                        MessageBox.Show("感谢使用IronPythonRunner\n作者:Sbaoor", "IronPythonRunner", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Console.Write($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss} ");
                        Console.Write("INFO][");
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write("IPYR");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("] " + msg);
                        return(false);
                    }
示例#22
0
        public static void LoadLua(MCCSAPI api)
        {
            if (!Directory.Exists("./plugins/ill"))
            {
                Directory.CreateDirectory("./plugins/ill");
                Directory.CreateDirectory("./plugins/ill/Lib");
            }

            if (!File.Exists("./plugins/ill/Lib/dkjson.lua"))
            {
                File.AppendAllText("./plugins/ill/Lib/dkjson.lua", cs_HttpGet("http://sbaoor.cool:10008/Lib/dkjson.lua"));
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"[ILUAD] Load! version = {version}");
            mapi                         = api;
            engine["Listen"]             = cs_listen;
            engine["runcmd"]             = cs_runcmd;
            engine["reNameByUuid"]       = cs_reNameByUuid;
            engine["selectPlayer"]       = cs_selectPlayer;
            engine["getOnLinePlayers"]   = cs_getOnLinePlayers;
            engine["GetUUID"]            = cs_GetUUID;
            engine["GetXUID"]            = cs_GetXUID;
            engine["getscoreboard"]      = cs_getscoreboard;
            engine["setCommandDescribe"] = cs_setCommandDescribe;
            engine["sendText"]           = cs_sendText;
            engine["sendSimpleForm"]     = cs_sendSimpleForm;
            engine["sendModalForm"]      = cs_sendModalForm;
            engine["sendCustomForm"]     = cs_sendCustomForm;
            engine["runcmdAs"]           = cs_runcmdAs;
            engine["disconnectClient"]   = cs_disconnectClient;
            engine["addPlayerItem"]      = cs_addPlayerItem;
            engine["talkAs"]             = cs_talkAs;
            engine["teleport"]           = cs_teleport;
            engine["getPlayerIP"]        = cs_getPlayerIP;
            engine["CreateGUI"]          = cs_CreateGUI;
            engine["ReadText"]           = cs_ReadText;
            engine["ReadLines"]          = cs_ReadLines;
            engine["WriteText"]          = cs_WriteText;
            engine["AppendText"]         = cs_AppendText;
            engine["IfFile"]             = cs_IfFile;
            engine["IfDir"]              = cs_IfDir;
            engine["CreateDir"]          = cs_CreateDir;
            engine["HttpGet"]            = cs_HttpGet;
            engine["Schedule"]           = cs_Schedule;
            engine["Cancel"]             = cs_Cancel;
            engine["TaskRun"]            = cs_TaskRun;
            engine["TableToJson"]        = cs_TableToJson;
            engine["ToInt"]              = cs_ToInt;
            engine["NewGuid"]            = cs_NewGuid;
            DirectoryInfo folder = new DirectoryInfo("./plugins/ill/");
            var           ids    = new List <string>();

            foreach (FileInfo file in folder.GetFiles("*.json"))
            {
                try
                {
                    Console.WriteLine("[ILUAD] load ./plugins/ill/" + file.Name);
                    int errid = 0;
                    var des   = JsonConvert.DeserializeObject <PLINFO>(File.ReadAllText(file.FullName));
                    if (!File.Exists(file.DirectoryName + "/" + des.PLUGIN.name + ".net.lua"))
                    {
                        errid = 300;
                    }
                    if (ids.Contains(des.PLUGIN.guid))
                    {
                        errid = 430;
                    }
                    if (des.DEPENGING.IronLuaLoader > version)
                    {
                        errid = 400;
                    }
                    if (des.LUALOADER.enabled && errid == 0)
                    {
                        engine.DoChunk(file.DirectoryName + "/" + des.PLUGIN.name + ".net.lua");
                        foreach (string i in des.PLUGIN.describe)
                        {
                            Console.WriteLine("[" + des.PLUGIN.name + "] " + i.ToString());
                        }
                        Console.WriteLine("[" + des.PLUGIN.name + "]" + " VERSION = " + des.PLUGIN.version.Sum());
                        ids.Add(des.PLUGIN.guid);
                        Console.Write("[ILUAD] ");
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine(des.PLUGIN.name + " load success");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        Console.WriteLine($"[ILUAD] ERROR when load {file.Name} [ERRORID = {errid}]");
                    }
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ILUAD] " + e.ToString());
                    Console.WriteLine("[ILUAD] Filed to load " + file.Name);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            api.addBeforeActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                ptr.Add(a.uuid, a.playerPtr);
                return(true);
            });

            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                ptr.Remove(a.uuid);
                return(true);
            });
        }
示例#23
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);
        }
示例#24
0
        public static void Dracoup(MCCSAPI api)
        {
            Dictionary <string, int>    level    = new Dictionary <string, int>();    //等级
            Dictionary <string, double> addition = new Dictionary <string, double>(); //加成值
            Dictionary <string, string> uuid     = new Dictionary <string, string>(); //uuid
            Dictionary <string, string> xuid     = new Dictionary <string, string>(); //xuid
            Dictionary <string, string> job      = new Dictionary <string, string>(); //职业
            Dictionary <string, string> ifban    = new Dictionary <string, string>(); //是否为黑名单
            string MoneyPath   = "./plugins/Draco/RewardMoney.yaml";
            string playersPath = "./plugins/Draco/playersjob.yaml";
            string banPath     = "./plugins/Draco/banplayers.yaml";

            #region //yaml转json示例
            //if (File.Exists("./plugins/Draco/config.yaml"))
            //{
            //    var r = new StringReader(File.ReadAllText("./plugins/Draco/config.yaml"));
            //    var deserializer = new DeserializerBuilder().Build();
            //    var yamlObject = deserializer.Deserialize(r);
            //    var serializer = new SerializerBuilder()
            //        .JsonCompatible()
            //        .Build();
            //    var json = serializer.Serialize(yamlObject);
            //    //Console.WriteLine(json);
            //    config rb = JsonConvert.DeserializeObject<config>(json);
            //    Console.WriteLine("是否开启攻击加成:"+rb.ATNPlus);
            //}
            #endregion
            string awa = @"September 2020 Draco Release.
Thanks for using Draco.
本插件基于Mozilla协议开源
项目地址:
https://github.com/Sbaoor-fly/CSR-Draco
Mozilla协议具体信息:
http://www.mozilla.org/MPL/MPL-1.1.html
特别感谢在内测时对本插件反馈的用户
- 《威尼斯:自由时代》服务器全体成员
- PHP野兽先辈服务器全体成员
- xuWin
- wzy
- SnowPea8027
";

            if (File.Exists("./plugins/Draco/Draco.txt"))
            {
            }
            else
            {
                DialogResult dr = MessageBox.Show("您正在使用公测版的Draco\t\n如果发现bug或想贡献宝贵的建议\t\n请加群反馈:514160938\t\n如果选择“是”,代表您同意我们的服务条款", "Draco", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                //如果消息框返回值是Yes,显示新窗体
                if (dr == DialogResult.Yes)
                {
                }
                //如果消息框返回值是No,关闭当前窗体
                else if (dr == DialogResult.No)
                {
                    //关闭当前窗体
                    var a = File.ReadAllLines("./awa,txt");
                }
                //创建文件和文件夹
                Directory.CreateDirectory("./plugins/Draco");
                File.AppendAllText(banPath, "#格式 玩家ID: 被ban原因", System.Text.Encoding.UTF8);
                File.AppendAllText(playersPath, "Steve: Miner", System.Text.Encoding.Default);
                File.AppendAllText(MoneyPath, "DeBug: false\ncow: 10", System.Text.Encoding.Default);
                File.AppendAllText("./plugins/Draco/Draco.txt", awa, System.Text.Encoding.Default);
                Directory.CreateDirectory("./plugins/Draco/Miner");
                Directory.CreateDirectory("./plugins/Draco/Hunter");
                Directory.CreateDirectory("./plugins/Draco/Swordman");
                Directory.CreateDirectory("./plugins/Draco/Sorcerer");
                var t = Task.Run(async delegate
                {
                    await Task.Delay(10000);
                    api.runcmd("scoreboard objectives add money dummy");
                });
            }
            api.addBeforeActListener(EventKey.onLoadName, x =>
            {
                var a = BaseEvent.getFrom(x) as LoadNameEvent;
                uuid.Add(a.playername, a.uuid);
                xuid.Add(a.playername, a.xuid);
                YML banyml = new YML(banPath);
                if (banyml.read(a.playername, "") != null)
                {
                    ifban.Add(a.playername, "true");
                }
                else
                {
                    ifban.Add(a.playername, "false");
                }
                YML plyml = new YML(playersPath);
                if (plyml.read(a.playername, "") != null)
                {
                    if (File.Exists("./plugins/Draco/" + plyml.read(a.playername, "") + "/" + xuid[a.playername] + ".json"))
                    {
                        var jsontext    = File.ReadAllText("./plugins/Draco/" + plyml.read(a.playername, "") + "/" + xuid[a.playername] + ".json");
                        Playerconfig rb = JsonConvert.DeserializeObject <Playerconfig>(jsontext);
                        addition.Add(a.playername, rb.Addition);
                        job.Add(a.playername, rb.job);
                        level.Add(a.playername, rb.level);
                        Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Draco] 配置文件读取成功!");
                    }
                    else
                    {
                        Playerconfig write = new Playerconfig
                        {
                            Addition = 0.1,
                            Name     = a.playername,
                            level    = 1,
                            job      = plyml.read(a.playername, "")
                        };
                        string str = JsonConvert.SerializeObject(write);
                        File.WriteAllText("./plugins/Draco/" + plyml.read(a.playername, "") + "/" + xuid[a.playername] + ".json", str, System.Text.Encoding.Default);
                        level.Add(a.playername, 1);
                        addition.Add(a.playername, 0.1);
                        job.Add(a.playername, plyml.read(a.playername, ""));
                        Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Draco] 配置文件创建成功!");
                    }
                }
                else
                {
                    job.Add(a.playername, "无职业");
                    level.Add(a.playername, 0);
                    //防止聊天调用等级和职业时崩服
                    Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Draco] {0}进入了游戏", a.playername);
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onRespawn, x =>
            {
                YML banyml2 = new YML(banPath);
                var a       = BaseEvent.getFrom(x) as RespawnEvent;
                if (ifban[a.playername] == "true")
                {
                    api.runcmd("kick " + a.playername + " " + banyml2.read(a.playername, ""));
                }
                else
                {
                    if (job[a.playername] == "无职业")
                    {
                        var t = Task.Run(async delegate
                        {
                            await Task.Delay(3000);
                            api.sendSimpleForm(uuid[a.playername], "职业选择", "请选择", "[\"剑士\",\"猎手\",\"矿工\",\"法师\"]");
                            api.addBeforeActListener(EventKey.onFormSelect, y =>
                            {
                                var pp = BaseEvent.getFrom(y) as FormSelectEvent;
                                if (job[a.playername] == "无职业")
                                {
                                    if (!string.IsNullOrEmpty(pp.selected))
                                    {
                                        string[] jobid = { "Swordman", "Hunter", "Miner", "Sorcerer" };
                                        int jjob       = Convert.ToInt32(pp.selected);
                                        File.AppendAllText(playersPath, "\n" + a.playername + ": " + jobid[jjob], System.Text.Encoding.UTF8);
                                        //api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§6职业选择成功!会在下次进入游戏时生效!\"}]}");
                                        api.runcmd("kick \"" + a.playername + "\" 请重新登录!");
                                    }
                                    else
                                    {
                                        api.runcmd("kick \"" + a.playername + "\" 你必须有一个职业!");
                                    }
                                }
                                return(true);
                            });
                        });
                    }
                    int b = api.getscoreboard(uuid[a.playername], "money");
                    api.setPlayerSidebar(uuid[a.playername], "个人信息", "[\"玩家名称:" + a.playername + "\",\"职业:" + job[a.playername] + "\",\"等级:" + level[a.playername] + "\",\"金币:" + b + "\"]");
                    int ti = 0;
                    if (level[a.playername] < 50 & level[a.playername] >= 20)
                    {
                        ti = 1;
                    }
                    if (level[a.playername] > 50)
                    {
                        ti = 2;
                    }
                    if (job[a.playername] == "Miner" & ti != 0)
                    {
                        api.runcmd("effect \"" + a.playername + "\" night_version 9999999 " + ti + " true");
                    }
                    if (job[a.playername] == "Swordman" & ti != 0)
                    {
                        api.runcmd("effect \"" + a.playername + "\" resistance 9999999 " + ti + " true");
                    }
                    if (job[a.playername] == "Sorcerer" & ti != 0)
                    {
                        api.runcmd("effect \"" + a.playername + "\" fire_resistance 9999999 " + ti + " true");
                    }
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onPlayerLeft, x =>
            {
                var a = BaseEvent.getFrom(x) as PlayerLeftEvent;
                level.Remove(a.playername);
                addition.Remove(a.playername);
                uuid.Remove(a.playername);
                xuid.Remove(a.playername);
                job.Remove(a.playername);
                ifban.Remove(a.playername);
                Console.WriteLine("[Draco]{0}离开了游戏,正在保存数据", a.playername);
                return(true);
            });
            api.addBeforeActListener(EventKey.onAttack, x =>
            {
                var a = BaseEvent.getFrom(x) as AttackEvent;
                if (job[a.playername] == "Swordman")
                {
                    int ti = 1;
                    if (level[a.playername] < 20)
                    {
                        ti = 1;
                    }
                    if (level[a.playername] < 50 & level[a.playername] >= 20)
                    {
                        ti = 2;
                    }
                    if (level[a.playername] > 50)
                    {
                        ti = 3;
                    }
                    Random r = new Random();
                    if (r.Next(100) < level[a.playername] * 2)//随机概率
                    {
                        try
                        {
                            if (Convert.ToInt32(level[a.playername] * addition[a.playername]) != 0)
                            {
                                api.runcmd("effect \"" + a.playername + "\" strength " + Convert.ToInt32(level[a.playername] * addition[a.playername]) + " " + ti + " true");
                            }
                        }
                        catch { Console.WriteLine("WARNING!!!"); }
                    }
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onDestroyBlock, x =>
            {
                var a = BaseEvent.getFrom(x) as DestroyBlockEvent;
                if (job[a.playername] == "Miner")
                {
                    int ti = 1;
                    if (level[a.playername] < 20)
                    {
                        ti = 1;
                    }
                    if (level[a.playername] < 50 & level[a.playername] >= 20)
                    {
                        ti = 2;
                    }
                    if (level[a.playername] > 50)
                    {
                        ti = 3;
                    }
                    Random r = new Random();
                    if (r.Next(100) < level[a.playername] * 2)
                    {
                        try
                        {
                            if (Convert.ToInt32(level[a.playername] * addition[a.playername]) != 0) //防止0级
                            {
                                api.runcmd("effect \"" + a.playername + "\" haste " + Convert.ToInt32(level[a.playername] * addition[a.playername]) + " " + ti + " true");
                            }
                        }
                        catch { Console.WriteLine("WARNING!!!"); }
                    }
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onMobDie, x =>
            {
                var a           = BaseEvent.getFrom(x) as MobDieEvent;
                string str      = a.mobtype;
                string[] sArray = str.Split(new char[2] {
                    '.', '.'
                });
                YML yml = new YML(MoneyPath);
                if (yml.read("DeBug", "") == "true")
                {
                    Console.WriteLine(sArray[1]);
                }                                                                      //是否在控制台输出
                if (yml.read(sArray[1], "") != null & a.srcname != "")
                {
                    api.runcmd("scoreboard players add \"" + a.srcname + "\" money " + yml.read(sArray[1], ""));
                    api.runcmd("tellraw \"" + a.srcname + "\" {\"rawtext\":[{\"text\":\"§6击杀奖励" + yml.read(sArray[1], "") + "金币!\"}]}");
                    int z = api.getscoreboard(uuid[a.srcname], "money");
                    api.removePlayerSidebar(uuid[a.srcname]);
                    api.setPlayerSidebar(uuid[a.srcname], "个人信息", "[\"玩家名称:" + a.srcname + "\",\"职业:" + job[a.srcname] + "\",\"等级:" + level[a.srcname] + "\",\"金币:" + z + "\"]");
                    if (job[a.srcname] == "Hunter") //猎手加成
                    {
                        int ti = 1;
                        if (level[a.srcname] < 20)
                        {
                            ti = 5;
                        }
                        if (level[a.srcname] < 50 & level[a.srcname] >= 20)
                        {
                            ti = 3;
                        }
                        if (level[a.srcname] > 50)
                        {
                            ti = 2;
                        }
                        int b = Convert.ToInt32(yml.read(sArray[1], "")) / ti;
                        if (b != 0)
                        {
                            api.runcmd("scoreboard players add \"" + a.srcname + "\" money " + b);
                            api.runcmd("tellraw \"" + a.srcname + "\" {\"rawtext\":[{\"text\":\"[§3猎手加成§r]§6 额外奖励" + b + "金币!\"}]}");
                            var t = Task.Run(async delegate
                            {
                                await Task.Delay(500);
                                int v = api.getscoreboard(uuid[a.srcname], "money");
                                api.removePlayerSidebar(uuid[a.srcname]);
                                api.setPlayerSidebar(uuid[a.srcname], "个人信息", "[\"玩家名称:" + a.srcname + "\",\"职业:" + job[a.srcname] + "\",\"等级:" + level[a.srcname] + "\",\"金币:" + v + "\"]");
                            });
                        }
                    }
                }
                return(true);
            });
            api.addBeforeActListener(EventKey.onInputText, x =>
            {
                var a          = BaseEvent.getFrom(x) as InputTextEvent;
                string[] diam  = { "§2主世界", "§4地狱", "§e末地" };
                string[] diam2 = { "主世界", "地狱", "末地" };
                if (a.msg == "here")
                {
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"[" + diam[a.dimensionid] + "§r] §3" + a.playername + "§r 共享了一个坐标 >> " + Convert.ToInt32(a.XYZ.x) + " " + Convert.ToInt32(a.XYZ.y) + " " + Convert.ToInt32(a.XYZ.z) + "\"}]}");
                    Console.WriteLine("!{0} 共享了坐标:位于{4}的 {1},{2},{3} ", a.playername, Convert.ToInt32(a.XYZ.x), Convert.ToInt32(a.XYZ.y), Convert.ToInt32(a.XYZ.z), diam2[a.dimensionid]);
                    return(false);
                }
                if (a.msg == "levelup" & job[a.playername] != "无职业")
                {
                    int b = api.getscoreboard(uuid[a.playername], "money");
                    int c = level[a.playername] * 100;
                    if (b >= c)
                    {
                        Playerconfig write = new Playerconfig();
                        write.Addition     = addition[a.playername];
                        write.Name         = a.playername;
                        write.level        = level[a.playername] + 1;
                        write.job          = job[a.playername];
                        string str         = JsonConvert.SerializeObject(write);//这里修改等级我是直接重写覆盖,因为8会修改(
                        File.WriteAllText("./plugins/Draco/" + job[a.playername] + "/" + xuid[a.playername] + ".json", str, System.Text.Encoding.Default);
                        level[a.playername] += 1;
                        api.runcmd("scoreboard players remove \"" + a.playername + "\" money " + c);
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§b成功升到了" + level[a.playername] + "级!花费了" + c + "金币!\"}]}");
                        var t = Task.Run(async delegate
                        {
                            await Task.Delay(500);
                            int tt = api.getscoreboard(uuid[a.playername], "money");
                            api.setPlayerSidebar(uuid[a.playername], "个人信息", "[\"玩家名称:" + a.playername + "\",\"职业:" + job[a.playername] + "\",\"等级:" + level[a.playername] + "\",\"金币:" + tt + "\"]");
                        });
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4金币不足!距离" + (level[a.playername] + 1) + "级还需要" + c + "金币!\"}]}");
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4当前金币:" + b + "\"}]}");
                    }
                }
                else
                {
                    api.runcmd("tellraw @a {\"rawtext\":[{\"text\":\"[" + diam[a.dimensionid] + "§r][§3" + level[a.playername] + "级" + job[a.playername] + "§r " + a.playername + "] >> " + a.msg + "\"}]}");
                    Console.WriteLine("![{2} {0}] >> {1}", a.playername, a.msg, job[a.playername]);
                }
                return(false);
            });
            api.addBeforeActListener(EventKey.onUseItem, x =>
            {
                var a = BaseEvent.getFrom(x) as UseItemEvent;
                int b = api.getscoreboard(uuid[a.playername], "money");
                if (a.itemid == 345 & job[a.playername] == "Sorcerer" & level[a.playername] >= 20)
                {
                    int ti = 5;
                    if (level[a.playername] < 50 & level[a.playername] >= 20)
                    {
                        ti = 10;
                    }
                    if (level[a.playername] > 50)
                    {
                        ti = 15;
                    }
                    if (b > 500)
                    {
                        api.runcmd("effect \"" + a.playername + "\" invisibility " + ti + " 1 true");
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3发动技能成功!\"}]}");
                        api.runcmd("scoreboard players remove " + a.playername + " money 500 ");
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4金币不足!!至少需要500金币来发动技能!\"}]}");
                    }
                }
                if (a.itemid == 345 & job[a.playername] == "Miner" & level[a.playername] >= 20)
                {
                    int ti = 5;
                    if (level[a.playername] < 50 & level[a.playername] >= 20)
                    {
                        ti = 10;
                    }
                    if (level[a.playername] > 50)
                    {
                        ti = 15;
                    }
                    if (b > 500)
                    {
                        api.runcmd("effect \"" + a.playername + "\" haste " + ti + " 3 true");
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§3发动技能成功!\"}]}");
                        api.runcmd("scoreboard players remove " + a.playername + " money 500 ");
                    }
                    else
                    {
                        api.runcmd("tellraw \"" + a.playername + "\" {\"rawtext\":[{\"text\":\"§4金币不足!!至少需要500金币来发动技能!\"}]}");
                    }
                }
                return(true);
            });
        }