From 0d80d86b54368c6806b63399fe85445720b76b2a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 12 Aug 2017 16:12:51 +1000 Subject: [PATCH] Don't allow adding two bots to map with same name, fixes #308. As if multiple bots have same name, all but 1 bots are lost on map unload then load again. They also can't be targeted individually in commands. --- MCGalaxy/Commands/Bots/CmdBotAdd.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MCGalaxy/Commands/Bots/CmdBotAdd.cs b/MCGalaxy/Commands/Bots/CmdBotAdd.cs index 0ed18dac5..72743b5e3 100644 --- a/MCGalaxy/Commands/Bots/CmdBotAdd.cs +++ b/MCGalaxy/Commands/Bots/CmdBotAdd.cs @@ -32,6 +32,10 @@ namespace MCGalaxy.Commands.Bots { } if (!Formatter.ValidName(p, message, "bot")) return; + if (BotExists(p.level, message)) { + Player.Message(p, "A bot with that name already exists."); return; + } + PlayerBot bot = new PlayerBot(message, p.level); bot.Pos = p.Pos; bot.SetYawPitch(p.Rot.RotY, 0); @@ -39,6 +43,14 @@ namespace MCGalaxy.Commands.Bots { Player.Message(p, "You added the bot " + bot.ColoredName + "%S."); PlayerBot.Add(bot); } + + static bool BotExists(Level lvl, string name) { + PlayerBot[] bots = lvl.Bots.Items; + foreach (PlayerBot bot in bots) { + if (bot.name.CaselessEq(name)) return true; + } + return false; + } public override void Help(Player p) { Player.Message(p, "%T/BotAdd [name]");