Files
Torch/Torch/Commands/CommandContext.cs
2018-01-25 18:34:21 -08:00

64 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Sandbox.Engine.Networking;
using Sandbox.Game.Multiplayer;
using Torch.API;
using Torch.API.Managers;
using Torch.API.Plugins;
using VRage.Game;
using VRage.Game.ModAPI;
namespace Torch.Commands
{
public class CommandContext
{
/// <summary>
/// The plugin that added this command.
/// </summary>
public ITorchPlugin Plugin { get; }
/// <summary>
/// The current Torch instance.
/// </summary>
public ITorchBase Torch { get; }
/// <summary>
/// The player who ran the command, or null if the server sent it.
/// </summary>
public IMyPlayer Player => Torch.CurrentSession.KeenSession.Players.TryGetPlayerBySteamId(_steamIdSender);
/// <summary>
/// Was this message sent by this program.
/// </summary>
public bool SentBySelf => _steamIdSender == Sync.MyId;
private ulong _steamIdSender;
/// <summary>
/// The command arguments split by spaces and quotes. Ex. "this is" a command -> {this is, a, command}
/// </summary>
public List<string> Args { get; }
/// <summary>
/// The non-split argument string.
/// </summary>
public string RawArgs { get; }
public CommandContext(ITorchBase torch, ITorchPlugin plugin, ulong steamIdSender, string rawArgs = null,
List<string> args = null)
{
Torch = torch;
Plugin = plugin;
_steamIdSender = steamIdSender;
RawArgs = rawArgs;
Args = args ?? new List<string>();
}
public virtual void Respond(string message, string sender = "Server", string font = MyFontEnum.Blue)
{
Torch.CurrentSession.Managers.GetManager<IChatManagerServer>()
?.SendMessageAsOther(sender, message, font, _steamIdSender);
}
}
}