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
CommandContext Helpers
Useful helper methods on CommandContext for player commands.
Example Code
// Check if sender is a player
if (!context.isPlayer()) {
context.sendMessage(Message.raw("Players only!"));
return;
}
// Get player entity reference directly
Ref<EntityStore> ref = context.senderAsPlayerRef();
if (ref == null || !ref.isValid()) {
context.sendMessage(Message.raw("Could not find player!"));
return;
}
// Get store and world from ref
Store<EntityStore> store = ref.getStore();
EntityStore entityStore = (EntityStore) store.getExternalData();
World world = entityStore.getWorld();
// Now you can use world.execute() for ECS operations
Thread Safety
context.isPlayer() and context.senderAsPlayerRef() are thread-safe checks
Common Mistakes
Not checking isPlayer() before senderAsPlayerRef(). Not checking ref.isValid() before using ref.