Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
damage

Make Entity Invulnerable

Make an entity immune to damage using Invulnerable component.

Example Code

java
world.execute(() -> {
    if (!ref.isValid()) return;

    // Make invulnerable - use the singleton INSTANCE
    store.putComponent(ref, Invulnerable.getComponentType(), Invulnerable.INSTANCE);

    // Remove invulnerability
    // store.removeComponent(ref, Invulnerable.getComponentType());
});

Thread Safety

Must run inside world.execute() for ECS safety.

Common Mistakes

Creating new Invulnerable() instead of using Invulnerable.INSTANCE singleton.