From 852079983380ff83707fbc69f55313d4ff4a051a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 21 Sep 2017 17:36:46 +1000 Subject: [PATCH] actually fix #435 --- MCGalaxy/Commands/Bots/CmdBot.cs | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/MCGalaxy/Commands/Bots/CmdBot.cs b/MCGalaxy/Commands/Bots/CmdBot.cs index afc5a24aa..44b206b71 100644 --- a/MCGalaxy/Commands/Bots/CmdBot.cs +++ b/MCGalaxy/Commands/Bots/CmdBot.cs @@ -45,7 +45,10 @@ namespace MCGalaxy.Commands.Bots { } else if (args[0].CaselessEq("deathmsg") || args[0].CaselessEq("deathmessage")) { string text = args.Length > 2 ? args[2] : null; SetDeathMessage(p, args[1], text); - } else { + } else if (args[0].CaselessEq("rename")) { + string newName = args.Length > 2 ? args[2] : null; + RenameBot(p, args[1], newName); + } else { Help(p); } } @@ -53,7 +56,7 @@ namespace MCGalaxy.Commands.Bots { void AddBot(Player p, string botName) { if (!LevelInfo.ValidateAction(p, p.level.name, "add bots to this level")) return; - if (BotExists(p.level, botName)) { + if (BotExists(p.level, botName, null)) { Player.Message(p, "A bot with that name already exists."); return; } if (p.level.Bots.Count >= ServerConfig.MaxBotsPerLevel) { @@ -68,9 +71,10 @@ namespace MCGalaxy.Commands.Bots { PlayerBot.Add(bot); } - static bool BotExists(Level lvl, string name) { + static bool BotExists(Level lvl, string name, PlayerBot skip) { PlayerBot[] bots = lvl.Bots.Items; foreach (PlayerBot bot in bots) { + if (bot == skip) continue; if (bot.name.CaselessEq(name)) return true; } return false; @@ -91,6 +95,28 @@ namespace MCGalaxy.Commands.Bots { } } + void RenameBot(Player p, string botName, string newName) { + if (!LevelInfo.ValidateAction(p, p.level.name, "rename bots on this level")) return; + if (newName == null) { Player.Message(p, "New name of bot required."); return; } + if (!Formatter.ValidName(p, newName, "bot")) return; + + PlayerBot bot = Matcher.FindBots(p, botName); + if (bot == null) return; + if (BotExists(p.level, newName, bot)) { + Player.Message(p, "A bot with the new name already exists."); return; + } + + Player.Message(p, "Renamed bot {0}", bot.ColoredName); + if (bot.DisplayName == bot.name) { + bot.DisplayName = newName; + bot.GlobalDespawn(); + bot.GlobalSpawn(); + } + + bot.name = newName; + BotsFile.Save(bot.level); + } + void SetBotText(Player p, string botName, string text) { PlayerBot bot = Matcher.FindBots(p, botName); if (bot == null) return; @@ -133,7 +159,7 @@ namespace MCGalaxy.Commands.Bots { Player.Message(p, "%T/Bot deathmessage [name] "); Player.Message(p, "%HSets the message shown when this bot kills a player"); Player.Message(p, "%T/Bot rename [name] [new name] %H- Renames a bot"); - Player.Message(p, "%H Note: To change name tag of a bot, use %T/nick bot"); + Player.Message(p, "%H Note: To only change name tag of a bot, use %T/nick bot"); } } }