-
Notifications
You must be signed in to change notification settings - Fork 1
Modular Commands
The first thing you have do understand in order to create a modular Command is that 3 types of Commands exist:
- ClientCommands: They are command used by the Players in the normal Console with a
.
.Example:.help
- RemoteAdminCommands: They are used by Admins of the Server in the RemoteAdmin or in the normal console with a
/
Example: Console:/forceclass 1 1
RemoteAdmin:forceclass 1 1
- GameConsoleCommands: They are used by the Server Console without any prefixes. Example:
help
In order to create a Modular command now you have to create a new class which inherit from the Interface CommandSystem.ICommand
(Is inside the CommandSystem.Core.dll
which you can find in the same directory than the assembly csharp in your Server files ... or just install the Nuget (Why do you hate the Nuget so much?))
The Class also need the Attribute [CommandHandler(typeof(x))]
and in x you had to fill in one of the command types:
RemoteAdminCommandHandler
GameConsoleCommandHandler
ClientCommandHandler
In these class you need 4 fields:
-
string Command { get; }
: The Main command name of your Command -
string[] Aliases { get; }
: Aliases for your command -
string Description { get; }
: A Description of your Command -
bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
: The Method which will be called when the command is executed an it returned a bool which defines if the execution was successfully or not (if it is not the respone Message will be displayed red)
The Execute method gives you a Array of arguments so as example if someone use the command broadcast 5 Hello
and your command name (or any allias) is broadcast you get the Arrays { 5,Hello }
The sender is the person which sends the command. You can use sender.GetPlayer()
to get the Player object of the person.
You have to define the string respone
before returning true or false and it is the Message the player will get.
Example:
using CommandSystem;
using System;
namespace Synapse.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class MyCommand : ICommand
{
public string Command { get; } = "mycommand";
public string[] Aliases { get; } = new string[]
{
"mc",
};
public string Description { get; } = "My First Command";
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string respone)
{
//Here you can do all the stuff which should happen when someone use the Command
resopne = $"Your Name is {sender.GetPlayer().NickName}";
return true;
}
}
}
You dont have todo anymore! if this class is in your Plugin Synapse will find it and activate it for you!