Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Making a command

MrSlimeDiamond edited this page Dec 6, 2021 · 2 revisions

Step 1: make the command class

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
        }
    }

Step 2: Sending messages to the player

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");
        }

Step 3: Register the command

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.

Step 4: Build and test

Build your plugin, put it in your plugins directory, type /test ingame and it should say You look very pretty today in chat.