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; } }
static void BotHandler(Player player, Command cmd) { if (!player.ClassiCube || !Heartbeat.ClassiCube()) { player.Message("Bots can only be used on ClassiCube servers and clients!"); return; } string option = cmd.Next(); //take in the option arg if (string.IsNullOrEmpty(option)) //empty? return, otherwise continue { CdBot.PrintUsage(player); return; } //certain options that take in specific params are in here, the rest are in the switch-case if (option.ToLower() == "list") { player.Message("_Bots on {0}_", ConfigKey.ServerName.GetString()); foreach (Bot botCheck in Server.Bots) { player.Message(botCheck.Name + " on " + botCheck.World.Name); } return; } else if (option.ToLower() == "removeall") { Server.Bots.ForEach(botToRemove => { botToRemove.removeBot(); }); player.Message("All bots removed from the server."); return; } else if (option.ToLower() == "move") { string targetBot = cmd.Next(); if (string.IsNullOrEmpty(targetBot)) { CdBot.PrintUsage(player); return; } string targetPlayer = cmd.Next(); if (string.IsNullOrEmpty(targetPlayer)) { CdBot.PrintUsage(player); return; } Bot targetB = player.World.FindBot(targetBot); Player targetP = player.World.FindPlayerExact(targetPlayer); if (targetP == null) { player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetPlayer, player.World); return; } if (targetB == null) { player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetBot, player.World); return; } player.Message("{0} is now moving!", targetB.Name); targetB.isMoving = true; targetB.NewPosition = targetP.Position; targetB.OldPosition = targetB.Position; targetB.timeCheck.Start(); return; } else if (option.ToLower() == "follow") { string targetBot = cmd.Next(); if (string.IsNullOrEmpty(targetBot)) { CdBot.PrintUsage(player); return; } string targetPlayer = cmd.Next(); if (string.IsNullOrEmpty(targetPlayer)) { CdBot.PrintUsage(player); return; } Bot targetB = player.World.FindBot(targetBot); Player targetP = player.World.FindPlayerExact(targetPlayer); if (targetP == null) { player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetPlayer, player.World); return; } if (targetB == null) { player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetBot, player.World); return; } player.Message("{0} is now following {1}!", targetB.Name, targetP.Name); targetB.isMoving = true; targetB.followTarget = targetP; targetB.OldPosition = targetB.Position; targetB.timeCheck.Start(); return; } //finally away from the special cases string botName = cmd.Next(); //take in bot name arg if (string.IsNullOrEmpty(botName)) //null check { CdBot.PrintUsage(player); return; } Bot bot = new Bot(); if (option != "create")//since the bot wouldn't exist for "create", we must check the bot for all cases other than "create" { bot = Server.FindBot(botName.ToLower()); //Find the bot and assign to bot var if (bot == null) //If null, return and yell at user { player.Message("Could not find {0}! Please make sure you spelled the bot's name correctly. To view all the bots, type /Bot list.", botName); return; } } //now to the cases - additional args should be taken in at the individual cases switch (option.ToLower()) { case "create": string requestedModel = cmd.Next(); if (string.IsNullOrEmpty(requestedModel)) { player.Message("Usage is /Bot create <bot name> <bot model>. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie."); return; } if (!validEntities.Contains(requestedModel)) { player.Message("That wasn't a valid bot model! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie."); return; } //if a botname has already been chosen, ask player for a new name var matchingNames = from b in Server.Bots where b.Name.ToLower() == botName.ToLower() select b; if (matchingNames.Count() > 0) { player.Message("A bot with that name already exists! To view all bots, type /bot list."); return; } player.Message("Successfully created a bot."); Bot botCreate = new Bot(); botCreate.setBot(botName, player.World, player.Position, LegendCraft.getNewID()); botCreate.createBot(); botCreate.changeBotModel(requestedModel); break; case "remove": player.Message("{0} was removed from the server.", bot.Name); bot.removeBot(); break; case "fly": if (bot.isFlying) { player.Message("{0} can no longer fly.", bot.Name); bot.isFlying = false; break; } player.Message("{0} can now fly!", bot.Name); bot.isFlying = true; break; case "model": if (bot.Skin != "steve") { player.Message("Bots cannot change model with a skin! Use '/bot clone' to reset a bot's skin."); return; } string model = cmd.Next(); if (string.IsNullOrEmpty(model)) { player.Message("Usage is /Bot model <bot> <model>. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie."); break; } if(model == "human")//lazy parse { model = "humanoid"; } if (!validEntities.Contains(model)) { player.Message("Please use a valid model name! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie."); break; } player.Message("Changed bot model to {0}.", model); bot.changeBotModel(model); break; case "clone": if (bot.Model != "humanoid") { player.Message("A bot must be a human in order to have a skin. Use '/bot model <bot> <model>' to change a bot's model."); return; } string playerToClone = cmd.Next(); if (string.IsNullOrEmpty(playerToClone)) { player.Message("{0}'s skin was reset!", bot.Name); bot.Clone("steve"); break; } PlayerInfo targetPlayer = PlayerDB.FindPlayerInfoExact(playerToClone); if (targetPlayer == null) { player.Message("That player doesn't exists! Please use a valid playername for the skin of the bot."); break; } player.Message("{0}'s skin was updated!", bot.Name); bot.Clone(playerToClone); break; case "explode": Server.Message("{0} exploded!", bot.Name); bot.explodeBot(player); break; case "summon": if (player.World != bot.World) { bot.tempRemoveBot(); //remove the entity bot.World = player.World; //update variables bot.Position = player.Position; bot.updateBotPosition(); //replace the entity } else { bot.Position = player.Position; bot.teleportBot(player.Position); } if (bot.Model != "human") { bot.changeBotModel(bot.Model); //replace the model, if the model is set } if (bot.Skin != "steve") { bot.Clone(bot.Skin); //replace the skin, if a skin is set } break; case "stop": player.Message("{0} is no longer moving.", bot.Name); bot.isMoving = false; bot.timeCheck.Stop(); bot.timeCheck.Reset(); bot.followTarget = null; break; default: CdBot.PrintUsage(player); break; } }