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
component-type-pattern
ComponentType<T> provides type-safe access to components. Every component class has a static getComponentType() method that returns its ComponentType for Store operations.
Example Code
// ComponentType<T> is a type descriptor for compile-time safety
// It tells the Store which type of component you want
// Getting ComponentTypes:
ComponentType<Player> playerType = Player.getComponentType();
ComponentType<TransformComponent> transformType = TransformComponent.getComponentType();
ComponentType<Teleport> teleportType = Teleport.getComponentType();
// Using with Store:
Player player = store.getComponent(ref, Player.getComponentType());
TransformComponent transform = store.getComponent(ref, TransformComponent.getComponentType());
// Adding components:
store.addComponent(ref, Teleport.getComponentType(), teleportInstance);
// Checking for components:
boolean hasHealth = store.hasComponent(ref, HealthComponent.getComponentType());
// Why ComponentType exists:
// 1. Type safety at compile time
// 2. Runtime efficiency for component lookup
// 3. Enables the archetype system to organize components
// Pattern: Always use the static getComponentType() method
// GOOD:
Player player = store.getComponent(ref, Player.getComponentType());
// BAD (would not compile):
// Player player = store.getComponent(ref, Player.class);
Common Mistakes
Trying to use Class<T> instead of ComponentType<T> for store operations.