Code Patterns

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

← Back to Patterns
command

Player Command

Create a command that requires a player context. Extends AbstractPlayerCommand for automatic ECS parameter injection.

Example Code

java
public class MyCommand extends AbstractPlayerCommand {

    public MyCommand() {
        super("mycommand", "Description of my command");
    }

    @Override
    protected void execute(
            @Nonnull CommandContext context,
            @Nonnull Store<EntityStore> store,
            @Nonnull Ref<EntityStore> ref,
            @Nonnull PlayerRef playerRef,
            @Nonnull World world
    ) {
        Player player = store.getComponent(ref, Player.getComponentType());
        player.sendMessage(Message.raw("Command executed!"));
    }
}

Thread Safety

Component access in execute() is safe since you are already on the correct thread.

Common Mistakes

Forgetting @Nonnull annotations. Using wrong import for Ref/Store (use com.hypixel.hytale.component).