mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
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.
This commit is contained in:
parent
bc14e5e242
commit
0d80d86b54
@ -32,6 +32,10 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Formatter.ValidName(p, message, "bot")) return;
|
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);
|
PlayerBot bot = new PlayerBot(message, p.level);
|
||||||
bot.Pos = p.Pos;
|
bot.Pos = p.Pos;
|
||||||
bot.SetYawPitch(p.Rot.RotY, 0);
|
bot.SetYawPitch(p.Rot.RotY, 0);
|
||||||
@ -40,6 +44,14 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
PlayerBot.Add(bot);
|
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) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/BotAdd [name]");
|
Player.Message(p, "%T/BotAdd [name]");
|
||||||
Player.Message(p, "%HAdds a new bot at your position.");
|
Player.Message(p, "%HAdds a new bot at your position.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user