コード例 #1
0
        public override string Run(McClient handler, string command, Dictionary <string, object> localVars)
        {
            if (handler.GetEntityHandlingEnabled())
            {
                string[] args = getArgs(command);
                if (args.Length >= 1)
                {
                    try
                    {
                        int entityID = 0;
                        int.TryParse(args[0], out entityID);
                        if (entityID != 0)
                        {
                            if (handler.GetEntities().ContainsKey(entityID))
                            {
                                string action = args.Length > 1
                                    ? args[1].ToLower()
                                    : "list";
                                switch (action)
                                {
                                case "attack":
                                    handler.InteractEntity(entityID, 1);
                                    return("已攻击实体");

                                case "use":
                                    handler.InteractEntity(entityID, 0);
                                    return("已使用实体");

                                default:
                                    Entity     entity     = handler.GetEntities()[entityID];
                                    int        id         = entity.ID;
                                    float      health     = entity.Health;
                                    int        latency    = entity.Latency;
                                    Item       item       = entity.Item;
                                    string     nickname   = entity.Name;
                                    string     customname = entity.CustomName;
                                    EntityPose pose       = entity.Pose;
                                    EntityType type       = entity.Type;
                                    double     distance   = Math.Round(entity.Location.Distance(handler.GetCurrentLocation()), 2);

                                    string color = "§a";     // Green
                                    if (health < 10)
                                    {
                                        color = "§c";      // Red
                                    }
                                    else if (health < 15)
                                    {
                                        color = "§e";      // Yellow
                                    }
                                    string location = String.Format("X:{0}, Y:{1}, Z:{2}", Math.Round(entity.Location.X, 2), Math.Round(entity.Location.Y, 2), Math.Round(entity.Location.Y, 2));
                                    string done     = String.Format("实体: {0}\n 类型: {1}", id, type);
                                    if (!String.IsNullOrEmpty(nickname))
                                    {
                                        done += String.Format("\n 昵称: {0}", nickname);
                                    }
                                    else if (!String.IsNullOrEmpty(customname))
                                    {
                                        done += String.Format("\n 自定义名称: {0}§8", customname.Replace("&", "§"));
                                    }
                                    if (type == EntityType.Player)
                                    {
                                        done += String.Format("\n 延迟: {0}", latency);
                                    }
                                    else if (type == EntityType.Item || type == EntityType.ItemFrame || type == Mapping.EntityType.EyeOfEnder || type == Mapping.EntityType.Egg || type == Mapping.EntityType.EnderPearl || type == Mapping.EntityType.Potion || type == Mapping.EntityType.Fireball || type == Mapping.EntityType.FireworkRocket)
                                    {
                                        string displayName = item.DisplayName;
                                        if (String.IsNullOrEmpty(displayName))
                                        {
                                            done += String.Format("\n 物品: {0} x{1}", item.Type, item.Count);
                                        }
                                        else
                                        {
                                            done += String.Format("\n 物品: {0} x{1} - {2}§8", item.Type, item.Count, displayName);
                                        }
                                    }

                                    if (entity.Equipment.Count >= 1 && entity.Equipment != null)
                                    {
                                        done += String.Format("\n 设备:");
                                        if (entity.Equipment.ContainsKey(0) && entity.Equipment[0] != null)
                                        {
                                            done += String.Format("\n   主手: {0} x{1}", entity.Equipment[0].Type, entity.Equipment[0].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(1) && entity.Equipment[1] != null)
                                        {
                                            done += String.Format("\n   副手: {0} x{1}", entity.Equipment[1].Type, entity.Equipment[1].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(5) && entity.Equipment[5] != null)
                                        {
                                            done += String.Format("\n   头盔: {0} x{1}", entity.Equipment[5].Type, entity.Equipment[5].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(4) && entity.Equipment[4] != null)
                                        {
                                            done += String.Format("\n   胸甲: {0} x{1}", entity.Equipment[4].Type, entity.Equipment[4].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(3) && entity.Equipment[3] != null)
                                        {
                                            done += String.Format("\n   护腿: {0} x{1}", entity.Equipment[3].Type, entity.Equipment[3].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(2) && entity.Equipment[2] != null)
                                        {
                                            done += String.Format("\n   鞋子: {0} x{1}", entity.Equipment[2].Type, entity.Equipment[2].Count);
                                        }
                                    }
                                    done += String.Format("\n 构成: {0}", pose);
                                    done += String.Format("\n 血量: {0}", color + health + "§8");
                                    done += String.Format("\n 距离: {0}", distance);
                                    done += String.Format("\n 位置: {0}", location);
                                    return(done);
                                }
                            }
                            else
                            {
                                return("实体未找到");
                            }
                        }
                        else
                        {
                            EntityType interacttype = EntityType.Player;
                            Enum.TryParse(args[0], out interacttype);
                            string actionst    = "已攻击该实体";
                            int    actioncount = 0;
                            foreach (var entity2 in handler.GetEntities())
                            {
                                if (entity2.Value.Type == interacttype)
                                {
                                    string action = args.Length > 1
                                    ? args[1].ToLower()
                                    : "list";
                                    if (action == "attack")
                                    {
                                        handler.InteractEntity(entity2.Key, 1);
                                        actionst = "已攻击该实体";
                                        actioncount++;
                                    }
                                    else if (action == "use")
                                    {
                                        handler.InteractEntity(entity2.Key, 0);
                                        actionst = "已使用该实体";
                                        actioncount++;
                                    }
                                    else
                                    {
                                        return(CMDDesc);
                                    }
                                }
                            }
                            return(actioncount + " " + actionst);
                        }
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    Dictionary <int, Mapping.Entity> entities = handler.GetEntities();
                    List <string> response = new List <string>();
                    response.Add("实体:");
                    foreach (var entity2 in entities)
                    {
                        int        id         = entity2.Key;
                        float      health     = entity2.Value.Health;
                        int        latency    = entity2.Value.Latency;
                        string     nickname   = entity2.Value.Name;
                        string     customname = entity2.Value.CustomName;
                        EntityPose pose       = entity2.Value.Pose;
                        EntityType type       = entity2.Value.Type;
                        Item       item       = entity2.Value.Item;
                        string     location   = String.Format("X:{0}, Y:{1}, Z:{2}", Math.Round(entity2.Value.Location.X, 2), Math.Round(entity2.Value.Location.Y, 2), Math.Round(entity2.Value.Location.Y, 2));

                        if (type == EntityType.Item || type == EntityType.ItemFrame || type == Mapping.EntityType.EyeOfEnder || type == Mapping.EntityType.Egg || type == Mapping.EntityType.EnderPearl || type == Mapping.EntityType.Potion || type == Mapping.EntityType.Fireball || type == Mapping.EntityType.FireworkRocket)
                        {
                            response.Add(String.Format(" #{0}: 类型: {1}, 物品: {2}, 位置: {3}", id, type, item.Type, location));
                        }
                        else if (type == Mapping.EntityType.Player && !String.IsNullOrEmpty(nickname))
                        {
                            response.Add(String.Format(" #{0}: 类型: {1}, 昵称: §8{2}§8, 延迟: {3}, 血量: {4}, 构成: {5}, 位置: {6}", id, type, nickname, latency, health, pose, location));
                        }
                        else if (type == Mapping.EntityType.Player && !String.IsNullOrEmpty(customname))
                        {
                            response.Add(String.Format(" #{0}: 类型: {1}, 自定义名称: §8{2}§8, 延迟: {3}, 血量: {4}, 构成: {5}, 位置: {6}", id, type, customname.Replace("&", "§"), latency, health, pose, location));
                        }
                        else
                        {
                            response.Add(String.Format(" #{0}: 类型: {1}, 血量: {2}, 位置: {3}", id, type, health, location));
                        }
                    }
                    response.Add(CMDDesc);
                    return(String.Join("\n", response));
                }
            }
            else
            {
                return("请先开启 Entityhandling.");
            }
        }
コード例 #2
0
        public override string Run(McClient handler, string command, Dictionary <string, object> localVars)
        {
            if (handler.GetEntityHandlingEnabled())
            {
                string[] args = getArgs(command);
                if (args.Length >= 1)
                {
                    try
                    {
                        int entityID = 0;
                        int.TryParse(args[0], out entityID);
                        if (entityID != 0)
                        {
                            if (handler.GetEntities().ContainsKey(entityID))
                            {
                                string action = args.Length > 1
                                    ? args[1].ToLower()
                                    : "list";
                                switch (action)
                                {
                                case "attack":
                                    handler.InteractEntity(entityID, 1);
                                    return(Translations.Get("cmd.entityCmd.attacked"));

                                case "use":
                                    handler.InteractEntity(entityID, 0);
                                    return(Translations.Get("cmd.entityCmd.used"));

                                default:
                                    Entity     entity     = handler.GetEntities()[entityID];
                                    int        id         = entity.ID;
                                    float      health     = entity.Health;
                                    int        latency    = entity.Latency;
                                    Item       item       = entity.Item;
                                    string     nickname   = entity.Name;
                                    string     customname = entity.CustomName;
                                    EntityPose pose       = entity.Pose;
                                    EntityType type       = entity.Type;
                                    double     distance   = Math.Round(entity.Location.Distance(handler.GetCurrentLocation()), 2);

                                    string color = "§a";     // Green
                                    if (health < 10)
                                    {
                                        color = "§c";      // Red
                                    }
                                    else if (health < 15)
                                    {
                                        color = "§e";      // Yellow
                                    }
                                    string location = String.Format("X:{0}, Y:{1}, Z:{2}", Math.Round(entity.Location.X, 2), Math.Round(entity.Location.Y, 2), Math.Round(entity.Location.Z, 2));
                                    string done     = Translations.Replace("([cmd.entityCmd.entity]): {0}\n [MCC] Type: {1}", id, type);
                                    if (!String.IsNullOrEmpty(nickname))
                                    {
                                        done += Translations.Replace("\n [MCC] ([cmd.entityCmd.nickname]): {0}", nickname);
                                    }
                                    else if (!String.IsNullOrEmpty(customname))
                                    {
                                        done += Translations.Replace("\n [MCC] ([cmd.entityCmd.customname]): {0}§8", customname.Replace("&", "§"));
                                    }
                                    if (type == EntityType.Player)
                                    {
                                        done += Translations.Replace("\n [MCC] ([cmd.entityCmd.latency]): {0}", latency);
                                    }
                                    else if (type == EntityType.Item || type == EntityType.ItemFrame || type == Mapping.EntityType.EyeOfEnder || type == Mapping.EntityType.Egg || type == Mapping.EntityType.EnderPearl || type == Mapping.EntityType.Potion || type == Mapping.EntityType.Fireball || type == Mapping.EntityType.FireworkRocket)
                                    {
                                        string displayName = item.DisplayName;
                                        if (String.IsNullOrEmpty(displayName))
                                        {
                                            done += Translations.Replace("\n [MCC] ([cmd.entityCmd.item]): {0} x{1}", item.Type, item.Count);
                                        }
                                        else
                                        {
                                            done += Translations.Replace("\n [MCC] ([cmd.entityCmd.item]): {0} x{1} - {2}§8", item.Type, item.Count, displayName);
                                        }
                                    }

                                    if (entity.Equipment.Count >= 1 && entity.Equipment != null)
                                    {
                                        done += Translations.Replace("\n [MCC] ([cmd.entityCmd.equipment]):");
                                        if (entity.Equipment.ContainsKey(0) && entity.Equipment[0] != null)
                                        {
                                            done += Translations.Replace("\n   [MCC] ([cmd.entityCmd.mainhand]): {0} x{1}", entity.Equipment[0].Type, entity.Equipment[0].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(1) && entity.Equipment[1] != null)
                                        {
                                            done += Translations.Replace("\n   [MCC] ([cmd.entityCmd.offhand]): {0} x{1}", entity.Equipment[1].Type, entity.Equipment[1].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(5) && entity.Equipment[5] != null)
                                        {
                                            done += Translations.Replace("\n   [MCC] ([cmd.entityCmd.helmet]): {0} x{1}", entity.Equipment[5].Type, entity.Equipment[5].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(4) && entity.Equipment[4] != null)
                                        {
                                            done += Translations.Replace("\n   [MCC] ([cmd.entityCmd.chestplate]): {0} x{1}", entity.Equipment[4].Type, entity.Equipment[4].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(3) && entity.Equipment[3] != null)
                                        {
                                            done += Translations.Replace("\n   [MCC] ([cmd.entityCmd.leggings]): {0} x{1}", entity.Equipment[3].Type, entity.Equipment[3].Count);
                                        }
                                        if (entity.Equipment.ContainsKey(2) && entity.Equipment[2] != null)
                                        {
                                            done += Translations.Replace("\n   [MCC] ([cmd.entityCmd.boots]): {0} x{1}", entity.Equipment[2].Type, entity.Equipment[2].Count);
                                        }
                                    }
                                    done += Translations.Replace("\n [MCC] ([cmd.entityCmd.pose]): {0}", pose);
                                    done += Translations.Replace("\n [MCC] ([cmd.entityCmd.health]): {0}", color + health + "§8");
                                    done += Translations.Replace("\n [MCC] ([cmd.entityCmd.distance]): {0}", distance);
                                    done += Translations.Replace("\n [MCC] ([cmd.entityCmd.location]): {0}", location);
                                    return(done);
                                }
                            }
                            else
                            {
                                return(Translations.Get("cmd.entityCmd.not_found"));
                            }
                        }
                        else
                        {
                            EntityType interacttype = EntityType.Player;
                            Enum.TryParse(args[0], out interacttype);
                            string actionst    = "cmd.entityCmd.attacked";
                            int    actioncount = 0;
                            foreach (var entity2 in handler.GetEntities())
                            {
                                if (entity2.Value.Type == interacttype)
                                {
                                    string action = args.Length > 1
                                    ? args[1].ToLower()
                                    : "list";
                                    if (action == "attack")
                                    {
                                        handler.InteractEntity(entity2.Key, 1);
                                        actionst = "cmd.entityCmd.attacked";
                                        actioncount++;
                                    }
                                    else if (action == "use")
                                    {
                                        handler.InteractEntity(entity2.Key, 0);
                                        actionst = "cmd.entityCmd.used";
                                        actioncount++;
                                    }
                                    else
                                    {
                                        return(GetCmdDescTranslated());
                                    }
                                }
                            }
                            return(actioncount + " " + Translations.Get(actionst));
                        }
                    }
                    catch (FormatException) { return(GetCmdDescTranslated()); }
                }
                else
                {
                    Dictionary <int, Entity> entities = handler.GetEntities();
                    List <string>            response = new List <string>();
                    response.Add(Translations.Get("cmd.entityCmd.entities"));
                    foreach (var entity2 in entities)
                    {
                        int        id         = entity2.Key;
                        float      health     = entity2.Value.Health;
                        int        latency    = entity2.Value.Latency;
                        string     nickname   = entity2.Value.Name;
                        string     customname = entity2.Value.CustomName;
                        EntityPose pose       = entity2.Value.Pose;
                        EntityType type       = entity2.Value.Type;
                        Item       item       = entity2.Value.Item;
                        string     location   = String.Format("X:{0}, Y:{1}, Z:{2}", Math.Round(entity2.Value.Location.X, 2), Math.Round(entity2.Value.Location.Y, 2), Math.Round(entity2.Value.Location.Y, 2));

                        if (type == EntityType.Item || type == EntityType.ItemFrame || type == EntityType.EyeOfEnder || type == EntityType.Egg || type == EntityType.EnderPearl || type == EntityType.Potion || type == EntityType.Fireball || type == EntityType.FireworkRocket)
                        {
                            response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.item]): {2}, ([cmd.entityCmd.location]): {3}", id, type, item.Type, location));
                        }
                        else if (type == EntityType.Player && !String.IsNullOrEmpty(nickname))
                        {
                            response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.nickname]): §8{2}§8, ([cmd.entityCmd.latency]): {3}, ([cmd.entityCmd.health]): {4}, ([cmd.entityCmd.pose]): {5}, ([cmd.entityCmd.location]): {6}", id, type, nickname, latency, health, pose, location));
                        }
                        else if (type == EntityType.Player && !String.IsNullOrEmpty(customname))
                        {
                            response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.customname]): §8{2}§8, ([cmd.entityCmd.latency]): {3}, ([cmd.entityCmd.health]): {4}, ([cmd.entityCmd.pose]): {5}, ([cmd.entityCmd.location]): {6}", id, type, customname.Replace("&", "§"), latency, health, pose, location));
                        }
                        else
                        {
                            response.Add(Translations.Replace(" #{0}: ([cmd.entityCmd.type]): {1}, ([cmd.entityCmd.health]): {2}, ([cmd.entityCmd.location]): {3}", id, type, health, location));
                        }
                    }
                    response.Add(GetCmdDescTranslated());
                    return(String.Join("\n", response));
                }
            }
            else
            {
                return(Translations.Get("extra.entity_required"));
            }
        }