Beispiel #1
0
        private static void BotHandler(Player player, CommandReader cmd) {
            string option = cmd.Next();
            if (string.IsNullOrEmpty(option)) {
                CdEntity.PrintUsage(player);
                return;
            }

            if (option.ToLower() == "list") {
                player.Message("_Entities on {0}_", ConfigKey.ServerName.GetString());
                foreach (Bot botCheck in World.Bots) {
                    player.Message(botCheck.Name + " on " + botCheck.World.Name);
                }
                return;
            }
            if (option.ToLower() == "removeall") {
                if (cmd.IsConfirmed) {
                    foreach (Bot b in World.Bots) {
                        b.World.Players.Send(Packet.MakeRemoveEntity(b.ID));
                        if (File.Exists("./Entities/" + b.Name.ToLower() + ".txt")) {
                            File.Delete("./Entities/" + b.Name.ToLower() + ".txt");
                        }
                    }
                    World.Bots.Clear();
                    player.Message("All entities removed.");
                } else {
                    player.Confirm(cmd, "This will remove all the entites everywhere, are you sure?");
                }
                return;
            }

            //finally away from the special cases
            string botName = cmd.Next();
            if (string.IsNullOrEmpty(botName)) {
                CdEntity.PrintUsage(player);
                return;
            }

            Bot bot = new Bot();
            if (option != "create" && option != "add") {
                bot = World.FindBot(botName.ToLower());
                if (bot == null) {
                    player.Message(
                        "Could not find {0}! Please make sure you spelled the entities name correctly. To view all the entities, type /ent list.",
                        botName);
                    return;
                }
            }
            Block blockmodel;

            switch (option.ToLower()) {
                case "create":
                case "add":
                    string requestedModel = "humanoid";
                    if (cmd.HasNext) {
                        requestedModel = cmd.Next().ToLower();
                    }
                    if (!validEntities.Contains(requestedModel)) {
                        if (Map.GetBlockByName(requestedModel, false, out blockmodel)) {
                            requestedModel = blockmodel.GetHashCode().ToString();
                        } else {
                            player.Message(
                                "That wasn't a valid entity model! Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name.");
                            return;
                        }
                    }

                    //if a botname has already been chosen, ask player for a new name
                    var matchingNames = from b in World.Bots where b.Name.ToLower() == botName.ToLower() select b;

                    if (matchingNames.Count() > 0) {
                        player.Message("An entity with that name already exists! To view all entities, type /ent list.");
                        return;
                    }

                    string skinString1 = (cmd.Next() ?? botName);
                    if (skinString1 != null) {
                        if (skinString1.StartsWith("--")) {
                            skinString1 = string.Format("http://minecraft.net/skin/{0}.png", skinString1.Replace("--", ""));
                        }
                        if (skinString1.StartsWith("-+")) {
                            skinString1 = string.Format("http://skins.minecraft.net/MinecraftSkins/{0}.png", skinString1.Replace("-+", ""));
                        }
                        if (skinString1.StartsWith("++")) {
                            skinString1 = string.Format("http://i.imgur.com/{0}.png", skinString1.Replace("++", ""));
                        }
                    }
                    Bot botCreate = new Bot();
                    botCreate.setBot(botName, skinString1, requestedModel, player.World, player.Position, getNewID());
                    botCreate.createBot();
                    player.Message("Successfully created entity {0}&s with id:{1} and skin {2}.", botCreate.Name, botCreate.ID, skinString1 ?? bot.Name);
                    break;
                case "remove":
                    player.Message("{0} was removed from the server.", bot.Name);
                    bot.removeBot();
                    break;
                case "model":
                    if (cmd.HasNext) {
                        string model = cmd.Next().ToLower();
                        string skinString2 = cmd.Next();
                        if (skinString2 != null) {
                            if (skinString2.StartsWith("--")) {
                                skinString2 = string.Format("http://minecraft.net/skin/{0}.png", skinString2.Replace("--", ""));
                            }
                            if (skinString2.StartsWith("-+")) {
                                skinString2 = string.Format("http://skins.minecraft.net/MinecraftSkins/{0}.png", skinString2.Replace("-+", ""));
                            }
                            if (skinString2.StartsWith("++")) {
                                skinString2 = string.Format("http://i.imgur.com/{0}.png", skinString2.Replace("++", ""));
                            }
                        }
                        if (string.IsNullOrEmpty(model)) {
                            player.Message(
                                "Usage is /Ent model <bot> <model>. Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name.");
                            break;
                        }

                        if (model == "human") {
                            model = "humanoid";
                        }
                        if (!validEntities.Contains(model)) {
                            if (Map.GetBlockByName(model, false, out blockmodel)) {
                                model = blockmodel.GetHashCode().ToString();
                            } else {
                                player.Message(
                                    "That wasn't a valid entity model! Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name.");
                                break;
                            }
                        }

                        player.Message("Changed entity model to {0} with skin {1}.", model, skinString2 ?? bot.SkinName);
                        bot.changeBotModel(model, skinString2 ?? bot.SkinName);
                    } else
                        player.Message(
                            "Usage is /Ent model <bot> <model>. Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name.");
                    break;
                case "bring":
                    bot.teleportBot(player.Position);
                    break;
                case "tp":
                case "teleport":
                    World targetWorld = bot.World;
                    Bot target = bot;
                    if (targetWorld == player.World) {
                        if (player.World != null) {
                            player.LastWorld = player.World;
                            player.LastPosition = player.Position;
                        }
                        player.TeleportTo(target.Position);

                    } else {
                        if (targetWorld.Name.StartsWith("PW_") &&
                            !targetWorld.AccessSecurity.ExceptionList.Included.Contains(player.Info)) {
                            player.Message(
                                "You cannot join due to that Bot being in a personal world that you cannot access.");
                            break;
                        }
                        switch (targetWorld.AccessSecurity.CheckDetailed(player.Info)) {
                            case SecurityCheckResult.Allowed:
                            case SecurityCheckResult.WhiteListed:
                                if (player.Info.Rank.Name == "Banned") {
                                    player.Message("&CYou can not change worlds while banned.");
                                    player.Message("Cannot teleport to {0}&S.", target.Name,
                                        targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                    break;
                                }
                                if (targetWorld.IsFull) {
                                    player.Message("Cannot teleport to {0}&S because world {1}&S is full.",
                                        target.Name, targetWorld.ClassyName);
                                    player.Message("Cannot teleport to {0}&S.", target.Name,
                                        targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                    break;
                                }
                                player.StopSpectating();
                                player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position);
                                break;
                            case SecurityCheckResult.BlackListed:
                                player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}",
                                    target.Name, targetWorld.ClassyName);
                                break;
                            case SecurityCheckResult.RankTooLow:
                                if (player.Info.Rank.Name == "Banned") {
                                    player.Message("&CYou can not change worlds while banned.");
                                    player.Message("Cannot teleport to {0}&S.", target.Name,
                                        targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                    break;
                                }

                                if (targetWorld.IsFull) {
                                    if (targetWorld.IsFull) {
                                        player.Message("Cannot teleport to {0}&S because world {1}&S is full.",
                                            target.Name, targetWorld.ClassyName);
                                        player.Message("Cannot teleport to {0}&S.", target.Name,
                                            targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                        break;
                                    }
                                    player.StopSpectating();
                                    player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position);
                                    break;
                                }
                                player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
                                    target.Name, targetWorld.ClassyName,
                                    targetWorld.AccessSecurity.MinRank.ClassyName);
                                break;
                        }
                    }
                    break;
                case "skin":
                    string skinString3 = cmd.Next();
                    if (skinString3 != null) {
                        if (skinString3.StartsWith("--")) {
                            skinString3 = string.Format("http://minecraft.net/skin/{0}.png", skinString3.Replace("--", ""));
                        }
                        if (skinString3.StartsWith("-+")) {
                            skinString3 = string.Format("http://skins.minecraft.net/MinecraftSkins/{0}.png", skinString3.Replace("-+", ""));
                        }
                        if (skinString3.StartsWith("++")) {
                            skinString3 = string.Format("http://i.imgur.com/{0}.png", skinString3.Replace("++", ""));
                        }
                    }
                    player.Message("Changed entity skin to {0}.", skinString3 ?? bot.Name);
                    bot.changeBotSkin(skinString3);
                    break;
                default:
                    CdEntity.PrintUsage(player);
                    break;
            }
        }