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
1
using Synapse.Command;
2
using System.Linq;
3
4
namespace CommandPlugin
5
{
6
[CommandInformation(
7
Name = "hello", // The main name and parameter for your command
8
Aliases = new string[] {"helloworld"}, // Aliases you can use instead of main command name
9
Description = "A Hello World Command", // A Description for the Commad
10
Permission = "commandplugin.hello", // The permission which the player needs to execute the Command
11
Platforms = new[] {Platform.RemoteAdmin,Platform.ServerConsole}, // The platforms the command can be used
12
Usage = "Just type hello or helloworld in the Console!" // A message how to use the command
13
Arguments = new[] { "Test" } //The Arguments that the will be displayed in the
14
//RemoteAdmin(only) to help the user to understand how to execute the command
15
)]
16
public class HelloWorldCommand : ISynapseCommand
17
{
18
public CommandResult Execute(CommandContext context)
19
{
20
var result = new CommandResult();
21
22
result.Message = "Hello World";
23
result.State = CommandResultState.Ok;
24
25
return result;
26
}
27
}
28
}
Copied!
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
1
using Synapse.Command;
2
using System.Linq;
3
4
namespace CommandPlugin
5
{
6
[CommandInformation(
7
Name = "hello", // The main name and parameter for your command
8
Aliases = new string[] {"helloworld"}, // Aliases you can use instead of main command
9
Description = "A Hello World Command", // A Description for the Commad
10
Permission = "commandplugin.hello", // The permission which the player needs to execute the Command
11
Platforms = new[] {Platform.RemoteAdmin,Platform.ServerConsole}, // The platforms the command can be used
12
Usage = "Just type hello or helloworld in the Console!" // A message how to use the command
13
Arguments = new[] { "Test" } //The Arguments that the will be displayed in the
14
//RemoteAdmin(only) to help the user to understand how to execute the command
15
)]
16
public class HelloWorldCommand : ISynapseCommand
17
{
18
private PluginClass Plugin { get; }
19
20
public HelloWorldCommand(PluginClass plugin) => Plugin = plugin;
21
22
public CommandResult Execute(CommandContext context)
23
{
24
//Some code that should be executed
25
}
26
}
27
}
Copied!
Copy link