Add uplink command minor revision and cleanup (#38532)
* commit * Update AddUplinkCommand.cs
This commit is contained in:
@@ -1,39 +1,20 @@
|
|||||||
using Content.Server.Administration;
|
using Content.Server.Administration;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.CCVar;
|
|
||||||
using Content.Shared.FixedPoint;
|
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Configuration;
|
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
|
|
||||||
namespace Content.Server.Traitor.Uplink.Commands
|
namespace Content.Server.Traitor.Uplink.Commands;
|
||||||
|
|
||||||
|
[AdminCommand(AdminFlags.Admin)]
|
||||||
|
public sealed class AddUplinkCommand : LocalizedEntityCommands
|
||||||
{
|
{
|
||||||
[AdminCommand(AdminFlags.Admin)]
|
[Dependency] private readonly UplinkSystem _uplinkSystem = default!;
|
||||||
public sealed class AddUplinkCommand : IConsoleCommand
|
|
||||||
{
|
|
||||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
|
||||||
public string Command => "adduplink";
|
public override string Command => "adduplink";
|
||||||
|
|
||||||
public string Description => Loc.GetString("add-uplink-command-description");
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
|
||||||
public string Help => Loc.GetString("add-uplink-command-help");
|
|
||||||
|
|
||||||
|
|
||||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
||||||
{
|
|
||||||
return args.Length switch
|
|
||||||
{
|
|
||||||
1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), Loc.GetString("add-uplink-command-completion-1")),
|
|
||||||
2 => CompletionResult.FromHint(Loc.GetString("add-uplink-command-completion-2")),
|
|
||||||
3 => CompletionResult.FromHint(Loc.GetString("add-uplink-command-completion-3")),
|
|
||||||
_ => CompletionResult.Empty
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
||||||
{
|
{
|
||||||
if (args.Length > 3)
|
if (args.Length > 3)
|
||||||
{
|
{
|
||||||
@@ -52,9 +33,7 @@ namespace Content.Server.Traitor.Uplink.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
session = shell.Player;
|
session = shell.Player;
|
||||||
}
|
|
||||||
|
|
||||||
if (session?.AttachedEntity is not { } user)
|
if (session?.AttachedEntity is not { } user)
|
||||||
{
|
{
|
||||||
@@ -66,15 +45,15 @@ namespace Content.Server.Traitor.Uplink.Commands
|
|||||||
EntityUid? uplinkEntity = null;
|
EntityUid? uplinkEntity = null;
|
||||||
if (args.Length >= 2)
|
if (args.Length >= 2)
|
||||||
{
|
{
|
||||||
if (!int.TryParse(args[1], out var itemID))
|
if (!int.TryParse(args[1], out var itemId))
|
||||||
{
|
{
|
||||||
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
|
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var eNet = new NetEntity(itemID);
|
var eNet = new NetEntity(itemId);
|
||||||
|
|
||||||
if (!_entManager.TryGetEntity(eNet, out var eUid))
|
if (!EntityManager.TryGetEntity(eNet, out var eUid))
|
||||||
{
|
{
|
||||||
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
||||||
return;
|
return;
|
||||||
@@ -83,7 +62,7 @@ namespace Content.Server.Traitor.Uplink.Commands
|
|||||||
uplinkEntity = eUid;
|
uplinkEntity = eUid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isDiscounted = false;
|
var isDiscounted = false;
|
||||||
if (args.Length >= 3)
|
if (args.Length >= 3)
|
||||||
{
|
{
|
||||||
if (!bool.TryParse(args[2], out isDiscounted))
|
if (!bool.TryParse(args[2], out isDiscounted))
|
||||||
@@ -94,11 +73,18 @@ namespace Content.Server.Traitor.Uplink.Commands
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally add uplink
|
// Finally add uplink
|
||||||
var uplinkSys = _entManager.System<UplinkSystem>();
|
if (!_uplinkSystem.AddUplink(user, 20, uplinkEntity: uplinkEntity, giveDiscounts: isDiscounted))
|
||||||
if (!uplinkSys.AddUplink(user, 20, uplinkEntity: uplinkEntity, giveDiscounts: isDiscounted))
|
|
||||||
{
|
|
||||||
shell.WriteLine(Loc.GetString("add-uplink-command-error-2"));
|
shell.WriteLine(Loc.GetString("add-uplink-command-error-2"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||||
|
{
|
||||||
|
return args.Length switch
|
||||||
|
{
|
||||||
|
1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), Loc.GetString("add-uplink-command-completion-1")),
|
||||||
|
2 => CompletionResult.FromHint(Loc.GetString("add-uplink-command-completion-2")),
|
||||||
|
3 => CompletionResult.FromHint(Loc.GetString("add-uplink-command-completion-3")),
|
||||||
|
_ => CompletionResult.Empty,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
add-uplink-command-description = Creates uplink on selected item and link it to users account
|
cmd-adduplink-desc = Creates uplink on selected item and link it to users account
|
||||||
add-uplink-command-help = Usage: adduplink [username] [item-id]
|
cmd-adduplink-help = Usage: adduplink [username] [item-id] [discountEnabled]
|
||||||
|
|
||||||
add-uplink-command-completion-1 = Username (defaults to self)
|
add-uplink-command-completion-1 = Username (defaults to self)
|
||||||
add-uplink-command-completion-2 = Uplink uid (default to PDA)
|
add-uplink-command-completion-2 = Uplink uid (default to PDA)
|
||||||
|
|||||||
Reference in New Issue
Block a user