Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
command
Player Command
Create a command that requires a player context. Extends AbstractPlayerCommand for automatic ECS parameter injection.
Example Code
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).