Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
command

Sync Command

Create a synchronous command using CommandBase. Runs on main thread, good for simple commands that need immediate world access.

Example Code

java
public class TestCommand extends CommandBase {

    public TestCommand() {
        super("test", "A test command");
        this.setPermissionGroup(GameMode.Adventure); // Anyone can use
    }

    @Override
    protected void executeSync(@Nonnull CommandContext ctx) {
        ctx.sendMessage(Message.raw("Hello from sync command!"));
    }
}

Thread Safety

executeSync runs on main thread - safe for direct world/entity access without world.execute().

Common Mistakes

Using executeSync for long operations - this blocks the main thread.