From 94879791a8681080f44c54fd7c653d54e4d8fc16 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 10 Sep 2016 10:57:04 +1000 Subject: [PATCH] Bot changes shouldn't be global (Thanks goodlyay) --- Bots/PlayerBot.cs | 5 +---- Commands/Bots/CmdBotSet.cs | 25 +++++++++++-------------- Commands/CPE/CmdModel.cs | 2 +- Commands/CPE/CmdSkin.cs | 2 +- Commands/Chat/CmdColor.cs | 5 +++-- Commands/Chat/CmdNick.cs | 4 ++-- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Bots/PlayerBot.cs b/Bots/PlayerBot.cs index 4f4f4969f..a0c5c448d 100644 --- a/Bots/PlayerBot.cs +++ b/Bots/PlayerBot.cs @@ -76,10 +76,7 @@ namespace MCGalaxy { bot.GlobalSpawn(); Player[] players = PlayerInfo.Online.Items; - foreach (Player p in players) { - if (p.level == bot.level) - Player.Message(p, bot.color + bot.name + "%S, the bot, has been added."); - } + Chat.MessageLevel(bot.level, bot.ColoredName + " %S, the bot, has been added."); if (save) BotsFile.UpdateBot(bot); } diff --git a/Commands/Bots/CmdBotSet.cs b/Commands/Bots/CmdBotSet.cs index bd31dc1b4..ed7996d2f 100644 --- a/Commands/Bots/CmdBotSet.cs +++ b/Commands/Bots/CmdBotSet.cs @@ -37,41 +37,38 @@ namespace MCGalaxy.Commands { if (bot == null) return; if (args.Length == 1) { - try { bot.Instructions.Clear(); } catch { } + bot.Instructions.Clear(); bot.kill = false; bot.hunt = false; bot.AIName = ""; - Player.Message(p, bot.ColoredName + "%S's AI was turned off."); - Server.s.Log(bot.name + "'s AI was turned off."); + UpdateBot(bot, "'s AI was turned off."); return; } else if (args.Length != 2) { Help(p); return; } string ai = args[1].ToLower(); - if (ai == "hunt") { bot.hunt = !bot.hunt; - try { bot.Instructions.Clear(); } - catch { } + bot.Instructions.Clear(); bot.AIName = ""; - if (p != null) Chat.GlobalChatLevel(p, bot.ColoredName + "%S's hunt instinct: " + bot.hunt, false); - Server.s.Log(bot.name + "'s hunt instinct: " + bot.hunt); - BotsFile.UpdateBot(bot); + UpdateBot(bot, "'s hunt instinct: " + bot.hunt); return; } else if (ai == "kill") { if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "toggle a bot's killer instinct."); return; } bot.kill = !bot.kill; - if (p != null) Chat.GlobalChatLevel(p, bot.ColoredName + "%S's kill instinct: " + bot.kill, false); - Server.s.Log(bot.name + "'s kill instinct: " + bot.kill); - BotsFile.UpdateBot(bot); + UpdateBot(bot, "'s kill instinct: " + bot.kill); return; } if (!ScriptFile.Parse(p, bot, "bots/" + ai)) return; bot.AIName = ai; - if (p != null) Chat.GlobalChatLevel(p, bot.ColoredName + "%S's AI is now set to " + ai, false); - Server.s.Log(bot.name + "'s AI was set to " + ai); + UpdateBot(bot, "'s AI was set to " + ai); + } + + static void UpdateBot(PlayerBot bot, string msg) { + Chat.MessageLevel(bot.level, bot.ColoredName + "%S" + msg); + Server.s.Log(bot.name + msg); BotsFile.UpdateBot(bot); } diff --git a/Commands/CPE/CmdModel.cs b/Commands/CPE/CmdModel.cs index caf1cce5f..af4fc2f12 100644 --- a/Commands/CPE/CmdModel.cs +++ b/Commands/CPE/CmdModel.cs @@ -76,7 +76,7 @@ namespace MCGalaxy.Commands.CPE { if (isBot) { bot.model = model; Entities.UpdateModel(bot.id, model, bot.level, null); - Chat.MessageAll("Bot {0}'s %Smodel was changed to a &c{1}", bot.ColoredName, model); + Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + "'s %Smodel was changed to a &c" + model); BotsFile.UpdateBot(bot); } else { who.model = model; diff --git a/Commands/CPE/CmdSkin.cs b/Commands/CPE/CmdSkin.cs index 3fa4814d7..110f29243 100644 --- a/Commands/CPE/CmdSkin.cs +++ b/Commands/CPE/CmdSkin.cs @@ -69,7 +69,7 @@ namespace MCGalaxy.Commands.CPE { bot.SkinName = skin; bot.GlobalDespawn(); bot.GlobalSpawn(); - Chat.MessageAll("Bot {0}'s %Sskin was changed to &c{1}", bot.ColoredName, skin); + Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + "'s %Sskin was changed to &c" + skin); BotsFile.UpdateBot(bot); } else { who.skinName = skin; diff --git a/Commands/Chat/CmdColor.cs b/Commands/Chat/CmdColor.cs index 73cc3f28b..5edca73ca 100644 --- a/Commands/Chat/CmdColor.cs +++ b/Commands/Chat/CmdColor.cs @@ -58,8 +58,9 @@ namespace MCGalaxy.Commands { static void SetBotColor(Player p, PlayerBot bot, string[] args) { string color = args.Length == 2 ? "&1" : Colors.Parse(args[2]); if (color == "") { Player.Message(p, "There is no color \"" + args[2] + "\"."); return; } - Chat.MessageAll("Bot {0}'s %Scolor was changed to {1}{2}", bot.DisplayName, color, Colors.Name(color)); - + Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + "'s %Scolor was set to " + + color + Colors.Name(color)); + bot.color = color; bot.GlobalDespawn(); bot.GlobalSpawn(); diff --git a/Commands/Chat/CmdNick.cs b/Commands/Chat/CmdNick.cs index d3075d591..71f520837 100644 --- a/Commands/Chat/CmdNick.cs +++ b/Commands/Chat/CmdNick.cs @@ -60,11 +60,11 @@ namespace MCGalaxy.Commands { string newName = args.Length > 2 ? args[2] : ""; if (newName == "") { bot.DisplayName = bot.name; - Chat.MessageAll("Bot {0}'s %Sreverted to their original name.", bot.ColoredName); + Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + " %Sreverted to their original name."); } else { string nameTag = newName.CaselessEq("empty") ? "" : newName; if (newName.Length >= 30) { Player.Message(p, "Name must be under 30 letters."); return; } - Chat.MessageAll("Bot {0}'s %Sname was set to {1}%S.", bot.ColoredName, nameTag); + Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + "'s %Sname was set to " + nameTag + "%S."); bot.DisplayName = newName; }