ForAll command! (#4982)
* ForAll command! Implements "Bad Query Language", which has a few specifiers you can use for badminning, namely: named <regex> prototyped <prototype name> with <component name> tagged <tag name> parented_to <parent entity uid> For example: forall prototyped MobHuman parented_to 855 do explode $WX $WY 1 1 1 1; addcomp $ID Item * oops * fix a silent parsing bug, make parser louder. * cleanup * rename shit
This commit is contained in:
38
Content.Server/Administration/Commands/BQL/ForAllCommand.cs
Normal file
38
Content.Server/Administration/Commands/BQL/ForAllCommand.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Server.Commands;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.Commands.BQL
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class ForAllCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "forall";
|
||||
public string Description => "Runs a command over all entities with a given component";
|
||||
public string Help => "Usage: forall <comp> <command...>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var (command, entities) = BqlParser.DoEntityQuery(argStr[6..], entityManager);
|
||||
|
||||
foreach (var ent in entities.ToList())
|
||||
{
|
||||
var cmds = CommandUtils.SubstituteEntityDetails(shell, ent, command).Split(";");
|
||||
foreach (var cmd in cmds)
|
||||
{
|
||||
shell.ExecuteCommand(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user