[Paper] Your First Command

Learn how to create a simple hello world plugin with Enchanted and the Paper API.

Prerequisites

Creating the Command

Every command must be annotated with @Command. If you get an error, double check that you didn't accidentally use net.jailgens.enchanted.Command.

@Command("hello-world")
public class HelloWorldCommand {}

If you have typed the command name in incorrectly, you should get a warning inside your IDE.

Now, simply create a method annotated with @Command.Default and inside print "Hello, world!"

@Command("hello-world")
public class HelloWorldCommand {
    @Command.Default
    public void sayHelloWorld() {
        System.out.println("Hello, World!");
    }
}

All @Command.Default tells enchanted is that the annotated method should run when the user executes the "hello-world" command without specifying any subcommand.

Register the Command

Command registration is fairly simple, just call CommandManager.registerCommand(Object) with the command you just created:

public class YourPlugin extends JavaPlugin {
    public void onEnable() {
        PaperCommandManager commandManager = PaperCommandManager.create(this);
        commandManager.registerCommand(new HelloWorldCommand());
    }
}

Now, simply start up your server, and see the output on console.

Last updated