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
Marker Component
Create marker components (boolean flags) using singleton pattern for entities without data.
Example Code
public class PoisonedComponent implements Component<EntityStore> {
// Singleton instance - no data needed
public static final PoisonedComponent INSTANCE = new PoisonedComponent();
// Private constructor prevents external instantiation
private PoisonedComponent() {}
@Override
public PoisonedComponent clone() {
return INSTANCE; // Same instance is fine for markers
}
}
// Usage:
// Add marker
store.addComponent(ref, PoisonedComponent.getComponentType(), PoisonedComponent.INSTANCE);
// Check if entity has marker
boolean isPoisoned = store.getComponent(ref, PoisonedComponent.getComponentType()) != null;
// Remove marker
store.removeComponent(ref, PoisonedComponent.getComponentType());