Synapse
Search…
Commands
If you want to create a custom command, that's easy!
You only need to create a new class in your project, let this Class inherit from ISynapseCommand and add the needed CommandInformation and you are done.
In the method Execute(), you can then use Synapse as normal.
Example.cs
using Synapse.Command;
using System.Linq;
namespace CommandPlugin
{
[CommandInformation(
Name = "hello", // The main name and parameter for your command
Aliases = new string[] {"helloworld"}, // Aliases you can use instead of main command name
Description = "A Hello World Command", // A Description for the Commad
Permission = "commandplugin.hello", // The permission which the player needs to execute the Command
Platforms = new[] {Platform.RemoteAdmin,Platform.ServerConsole}, // The platforms the command can be used
Usage = "Just type hello or helloworld in the Console!" // A message how to use the command
Arguments = new[] { "Test" } //The Arguments that the will be displayed in the
//RemoteAdmin(only) to help the user to understand how to execute the command
)]
public class HelloWorldCommand : ISynapseCommand
{
public CommandResult Execute(CommandContext context)
{
var result = new CommandResult();
result.Message = "Hello World";
result.State = CommandResultState.Ok;
return result;
}
}
}
Synapse will check for you if the Player is authorized to use the Command.
If everyone should be able to use the command just set the permission in the CommandInformation to an empty string.
You can also get your PluginClass in the constructor of the Command so that you don't have to store it somewhere static
using Synapse.Command;
using System.Linq;
namespace CommandPlugin
{
[CommandInformation(
Name = "hello", // The main name and parameter for your command
Aliases = new string[] {"helloworld"}, // Aliases you can use instead of main command
Description = "A Hello World Command", // A Description for the Commad
Permission = "commandplugin.hello", // The permission which the player needs to execute the Command
Platforms = new[] {Platform.RemoteAdmin,Platform.ServerConsole}, // The platforms the command can be used
Usage = "Just type hello or helloworld in the Console!" // A message how to use the command
Arguments = new[] { "Test" } //The Arguments that the will be displayed in the
//RemoteAdmin(only) to help the user to understand how to execute the command
)]
public class HelloWorldCommand : ISynapseCommand
{
private PluginClass Plugin { get; }
public HelloWorldCommand(PluginClass plugin) => Plugin = plugin;
public CommandResult Execute(CommandContext context)
{
//Some code that should be executed
}
}
}
Copy link