Reorganize commands into the Commands folder (#2679)

* Reorganize commands into the Commands folder

* RIDER
This commit is contained in:
DrSmugleaf
2020-12-03 03:40:47 +01:00
committed by GitHub
parent 7905d93564
commit 87f9a6e167
69 changed files with 2817 additions and 2293 deletions

View File

@@ -1,16 +1,9 @@
using System;
using Content.Server.Administration;
using Content.Server.Commands;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Administration;
using Content.Shared.Alert;
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Players;
@@ -89,82 +82,4 @@ namespace Content.Server.GameObjects.Components.Mobs
}
}
}
[AdminCommand(AdminFlags.Debug)]
public sealed class ShowAlert : IClientCommand
{
public string Command => "showalert";
public string Description => "Shows an alert for a player, defaulting to current player";
public string Help => "showalert <alertType> <severity, -1 if no severity> <name or userID, omit for current player>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
var attachedEntity = player.AttachedEntity;
if (args.Length > 2)
{
var target = args[2];
if (!Commands.CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
}
if (!CommandUtils.ValidateAttachedEntity(shell, player, attachedEntity)) return;
if (!attachedEntity.TryGetComponent(out ServerAlertsComponent alertsComponent))
{
shell.SendText(player, "user has no alerts component");
return;
}
var alertType = args[0];
var severity = args[1];
var alertMgr = IoCManager.Resolve<AlertManager>();
if (!alertMgr.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
{
shell.SendText(player, "unrecognized alertType " + alertType);
return;
}
if (!short.TryParse(severity, out var sevint))
{
shell.SendText(player, "invalid severity " + sevint);
return;
}
alertsComponent.ShowAlert(alert.AlertType, sevint == -1 ? (short?) null : sevint);
}
}
[AdminCommand(AdminFlags.Debug)]
public sealed class ClearAlert : IClientCommand
{
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, IPlayerSession player, string[] args)
{
var attachedEntity = player.AttachedEntity;
if (args.Length > 1)
{
var target = args[1];
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
}
if (!CommandUtils.ValidateAttachedEntity(shell, player, attachedEntity)) return;
if (!attachedEntity.TryGetComponent(out ServerAlertsComponent alertsComponent))
{
shell.SendText(player, "user has no alerts component");
return;
}
var alertType = args[0];
var alertMgr = IoCManager.Resolve<AlertManager>();
if (!alertMgr.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
{
shell.SendText(player, "unrecognized alertType " + alertType);
return;
}
alertsComponent.ClearAlert(alert.AlertType);
}
}
}

View File

@@ -1,13 +1,4 @@
using System;
using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.Components.Mobs.Speech
namespace Content.Server.GameObjects.Components.Mobs.Speech
{
internal interface IAccentComponent
{
@@ -18,79 +9,4 @@ namespace Content.Server.GameObjects.Components.Mobs.Speech
/// <returns>The message after the transformation</returns>
public string Accentuate(string message);
}
[AdminCommand(AdminFlags.Fun)]
public class AddAccent : IClientCommand
{
public string Command => "addaccent";
public string Description => "Add a speech component to the current player";
public string Help => $"{Command} <component>/?";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (args.Length == 0)
{
shell.SendText(player, Help);
return;
}
if (player.AttachedEntity == null)
{
shell.SendText(player, "You don't have a player!");
return;
}
var compFactory = IoCManager.Resolve<IComponentFactory>();
if (args[0] == "?")
{
// Get all components that implement the ISpeechComponent except
var speeches = compFactory.GetAllRefTypes()
.Where(c => typeof(IAccentComponent).IsAssignableFrom(c) && c.IsClass);
var msg = "";
foreach(var s in speeches)
{
msg += $"{compFactory.GetRegistration(s).Name}\n";
}
shell.SendText(player, msg);
}
else
{
var name = args[0];
// Try to get the Component
Type type;
try
{
var comp = compFactory.GetComponent(name);
type = comp.GetType();
}
catch (Exception)
{
shell.SendText(player, $"Accent {name} not found. Try {Command} ? to get a list of all appliable accents.");
return;
}
// Check if that already exists
try
{
var comp = player.AttachedEntity.GetComponent(type);
shell.SendText(player, "You already have this accent!");
return;
}
catch (Exception)
{
// Accent not found
}
// Generic fuckery
var ensure = typeof(IEntity).GetMethod("AddComponent");
if (ensure == null)
return;
var method = ensure.MakeGenericMethod(type);
method.Invoke(player.AttachedEntity, null);
}
}
}
}