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
ecs
RefSystem - Entity Lifecycle
React to entity creation and removal events.
Example Code
public class EntityTrackingSystem extends RefSystem<EntityStore> {
@Override
public Query<EntityStore> getQuery() {
// Track all entities with Player component
return Archetype.of(Player.getComponentType());
}
@Override
public void onEntityAdded(Ref<EntityStore> ref, AddReason reason,
Store<EntityStore> store, CommandBuffer<EntityStore> buffer) {
Player player = store.getComponent(ref, Player.getComponentType());
if (reason == AddReason.SPAWN) {
// New player joined
broadcastJoinMessage(player);
} else if (reason == AddReason.LOAD) {
// Player loaded from save
restorePlayerState(player);
}
}
@Override
public void onEntityRemove(Ref<EntityStore> ref, RemoveReason reason,
Store<EntityStore> store, CommandBuffer<EntityStore> buffer) {
Player player = store.getComponent(ref, Player.getComponentType());
if (reason == RemoveReason.REMOVE) {
// Permanent removal
broadcastLeaveMessage(player);
} else if (reason == RemoveReason.UNLOAD) {
// Saving and unloading
savePlayerState(player);
}
}
}