Merge remote-tracking branch 'upstream/master' into 20-10-30-admins
This commit is contained in:
66
Content.Server/Commands/CommandUtils.cs
Normal file
66
Content.Server/Commands/CommandUtils.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Server.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilities for writing commands
|
||||
/// </summary>
|
||||
public static class CommandUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player session for the player with the indicated id,
|
||||
/// sending a failure to the performer if unable to.
|
||||
/// </summary>
|
||||
public static bool TryGetSessionByUsernameOrId(IConsoleShell shell,
|
||||
string usernameOrId, IPlayerSession performer, out IPlayerSession session)
|
||||
{
|
||||
var plyMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
if (plyMgr.TryGetSessionByUsername(usernameOrId, out session)) return true;
|
||||
if (Guid.TryParse(usernameOrId, out var targetGuid))
|
||||
{
|
||||
if (plyMgr.TryGetSessionById(new NetUserId(targetGuid), out session)) return true;
|
||||
shell.SendText(performer, "Unable to find user with that name/id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
shell.SendText(performer, "Unable to find user with that name/id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attached entity for the player session with the indicated id,
|
||||
/// sending a failure to the performer if unable to.
|
||||
/// </summary>
|
||||
public static bool TryGetAttachedEntityByUsernameOrId(IConsoleShell shell,
|
||||
string usernameOrId, IPlayerSession performer, out IEntity attachedEntity)
|
||||
{
|
||||
attachedEntity = null;
|
||||
if (!TryGetSessionByUsernameOrId(shell, usernameOrId, performer, out var session)) return false;
|
||||
if (session.AttachedEntity == null)
|
||||
{
|
||||
shell.SendText(performer, "User has no attached entity.");
|
||||
return false;
|
||||
}
|
||||
|
||||
attachedEntity = session.AttachedEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if attached entity is null, returning false and sending a message
|
||||
/// to performer if not.
|
||||
/// </summary>
|
||||
public static bool ValidateAttachedEntity(IConsoleShell shell, IPlayerSession performer, IEntity attachedEntity)
|
||||
{
|
||||
if (attachedEntity != null) return true;
|
||||
shell.SendText(performer, "User has no attached entity.");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
Content.Server/Commands/Hungry.cs
Normal file
39
Content.Server/Commands/Hungry.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Shared.GameObjects.Components.Nutrition;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
|
||||
namespace Content.Server.Commands
|
||||
{
|
||||
public class Hungry : IClientCommand
|
||||
{
|
||||
public string Command => "hungry";
|
||||
public string Description => "Makes you hungry.";
|
||||
public string Help => $"{Command}";
|
||||
|
||||
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
shell.SendText(player, "You cannot use this command unless you are a player.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.AttachedEntity == null)
|
||||
{
|
||||
shell.SendText(player, "You cannot use this command without an entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.AttachedEntity.TryGetComponent(out HungerComponent? hunger))
|
||||
{
|
||||
shell.SendText(player, $"Your entity does not have a {nameof(HungerComponent)} component.");
|
||||
return;
|
||||
}
|
||||
|
||||
var hungryThreshold = hunger.HungerThresholds[HungerThreshold.Starving];
|
||||
hunger.CurrentHunger = hungryThreshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user