This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Making a command
MrSlimeDiamond edited this page Dec 6, 2021
·
2 revisions
Make your command class, in this example, we'll use ExampleCommand
. It should implement the CommandExecutor
class. Consider the example below
import ml.glucosedev.glucoselib.command.CommandCaller;
import ml.glucosedev.glucoselib.command.CommandContext;
import ml.glucosedev.glucoselib.command.CommandExecutor;
import org.jetbrains.annotations.NotNull;
public class TestCommand implements CommandExecutor {
@Override
public void execute(@NotNull CommandContext commandContext) {
// Code goes here
}
}
In this example, I am going to send a message to the sender. Using CommandContext
we can get the sender with commandContext.getCaller();
Example:
@Override
public void execute(@NotNull CommandContext commandContext) {
CommandCaller caller = commandContext.getCaller();
}
Then we can use the caller.send();
method to send them a nice message
@Override
public void execute(@NotNull CommandContext commandContext) {
CommandCaller caller = commandContext.getCaller();
caller.send("You look very pretty today");
}
In your serverStartEvent()
, add something that looks a bit like this
public void serverStartEvent() {
CommandManager.registerCommand(new TestCommand(), "test");
}
The first argument is the CommandExecutor, the second argument is the alias for the command.
Build your plugin, put it in your plugins
directory, type /test
ingame and it should say You look very pretty today
in chat.