Files
crystall-punk-14/Content.Server/Verbs/Commands/ListVerbsCommand.cs

78 lines
2.6 KiB
C#
Raw Permalink Normal View History

using Content.Server.Administration;
using Content.Server.Database;
2021-11-04 23:48:30 -07:00
using Content.Shared.Administration;
using Content.Shared.Verbs;
using Robust.Shared.Console;
namespace Content.Server.Verbs.Commands
{
[AdminCommand(AdminFlags.Moderator)]
public sealed class ListVerbsCommand : IConsoleCommand
2021-11-04 23:48:30 -07:00
{
[Dependency] private readonly IEntityManager _entManager = default!;
2021-11-04 23:48:30 -07:00
public string Command => "listverbs";
public string Description => Loc.GetString("list-verbs-command-description");
public string Help => Loc.GetString("list-verbs-command-help");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteLine(Loc.GetString("list-verbs-command-invalid-args"));
return;
}
var verbSystem = _entManager.System<SharedVerbSystem>();
2021-11-04 23:48:30 -07:00
// get the 'player' entity (defaulting to command user, otherwise uses a uid)
2021-12-06 00:52:58 +01:00
EntityUid? playerEntity = null;
2021-11-04 23:48:30 -07:00
if (!int.TryParse(args[0], out var intPlayerUid))
{
if (args[0] == "self" && shell.Player?.AttachedEntity != null)
{
playerEntity = shell.Player.AttachedEntity;
}
else
{
shell.WriteError(Loc.GetString("list-verbs-command-invalid-player-uid"));
return;
}
}
2023-11-26 14:20:07 +11:00
else
{
_entManager.TryGetEntity(new NetEntity(intPlayerUid), out playerEntity);
2023-11-26 14:20:07 +11:00
}
2021-11-04 23:48:30 -07:00
// gets the target entity
if (!int.TryParse(args[1], out var intUid))
{
shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-uid"));
return;
}
if (playerEntity == null)
{
shell.WriteError(Loc.GetString("list-verbs-command-invalid-player-entity"));
return;
}
var targetNet = new NetEntity(intUid);
if (!_entManager.TryGetEntity(targetNet, out var target))
2021-11-04 23:48:30 -07:00
{
shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-entity"));
return;
}
var verbs = verbSystem.GetLocalVerbs(target.Value, playerEntity.Value, Verb.VerbTypes);
2021-11-04 23:48:30 -07:00
foreach (var verb in verbs)
2021-11-04 23:48:30 -07:00
{
shell.WriteLine(Loc.GetString("list-verbs-verb-listing", ("type", verb.GetType().Name), ("verb", verb.Text)));
2021-11-04 23:48:30 -07:00
}
}
}
}