Files
CounterStrikeSharp/managed/CounterStrikeSharp.API/Modules/Commands/CommandInfo.cs
2023-11-10 18:40:20 +10:00

58 lines
2.1 KiB
C#

/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
using System;
using CounterStrikeSharp.API.Core;
namespace CounterStrikeSharp.API.Modules.Commands
{
public class CommandInfo
{
public delegate void CommandCallback(CCSPlayerController? player, CommandInfo commandInfo);
public delegate HookResult CommandListenerCallback(CCSPlayerController? player, CommandInfo commandInfo);
private CCSPlayerController _player;
public IntPtr Handle { get; private set; }
internal CommandInfo(IntPtr pointer, CCSPlayerController player)
{
Handle = pointer;
_player = player;
}
public int ArgCount => NativeAPI.CommandGetArgCount(Handle);
public string ArgString => NativeAPI.CommandGetArgString(Handle);
public string GetCommandString => NativeAPI.CommandGetCommandString(Handle);
public string ArgByIndex(int index) => NativeAPI.CommandGetArgByIndex(Handle, index);
public string GetArg(int index) => NativeAPI.CommandGetArgByIndex(Handle, index);
public void ReplyToCommand(string message, bool console = false) {
if (_player != null)
{
if (console) { _player.PrintToConsole(message); }
else _player.PrintToChat(message);
}
else
{
Server.PrintToConsole(message);
}
}
}
}