Files
tbd-station-14/Content.Server/Alert/Commands/ClearAlert.cs
Kara 993eef1e7c Resolve 'EntitySystem.Get<T>()' is obsolete in content (#27936)
* PROJECT 0 WARNINGS: Resolve `'EntitySystem.Get<T>()' is obsolete` in content

* pass entman

* dog ass test

* webeditor
2024-05-12 20:34:52 -04:00

53 lines
1.8 KiB
C#

using Content.Server.Administration;
using Content.Server.Commands;
using Content.Shared.Administration;
using Content.Shared.Alert;
using Robust.Shared.Console;
namespace Content.Server.Alert.Commands
{
[AdminCommand(AdminFlags.Debug)]
public sealed class ClearAlert : IConsoleCommand
{
[Dependency] private readonly IEntityManager _e = default!;
public string Command => "clearalert";
public string Description => "Clears an alert for a player, defaulting to current player";
public string Help => "clearalert <alertType> <name or userID, omit for current player>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player;
if (player?.AttachedEntity == null)
{
shell.WriteLine("You don't have an entity.");
return;
}
var attachedEntity = player.AttachedEntity.Value;
if (args.Length > 1)
{
var target = args[1];
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
}
if (!_e.TryGetComponent(attachedEntity, out AlertsComponent? alertsComponent))
{
shell.WriteLine("user has no alerts component");
return;
}
var alertType = args[0];
var alertsSystem = _e.System<AlertsSystem>();
if (!alertsSystem.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
{
shell.WriteLine("unrecognized alertType " + alertType);
return;
}
alertsSystem.ClearAlert(attachedEntity, alert.AlertType);
}
}
}