> For the complete documentation index, see [llms.txt](https://lethium.gitbook.io/lethium-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lethium.gitbook.io/lethium-docs/dev-api/examples.md).

# Examples

Copy-paste recipes: a rank multiplier, a custom stat bonus, a world lock, a mob tweak and a custom reward.

Each example assumes your plugin depends on `ClickEmCore` and the class registers events with `getServer().getPluginManager().registerEvents(this, this)`.

### 1. A permission-based Coins multiplier

```java
@EventHandler
public void onCoins(CurrencyRewardEvent event) {
    if (!event.currency().equals(ClickEmAPI.get().primaryCurrency())) return;
    if (event.player().hasPermission("myserver.coins.x2")) {
        event.setAmount(event.amount() * 2);
    }
}
```

### 2. A stat bonus from your own system

```java
public final class GuildStats implements StatContributor {
    private final GuildManager guilds;

    public GuildStats(GuildManager guilds) { this.guilds = guilds; }

    @Override
    public StatBlock contribution(Player player) {
        int level = guilds.levelOf(player.getUniqueId());   // must be fast, in memory
        if (level <= 0) return StatBlock.ZERO;
        return StatBlock.builder()
                .add(StatType.DAMAGE, level * 3.0)
                .add(StatType.CURRENCY, level * 2.0)
                .build();
    }
}

// in onEnable
ClickEmAPI.get().addStatContributor(this, new GuildStats(guilds));
```

The bonus shows in `/profile`, leaderboards and `%clickem_stat_damage%`. Remember Power and Coins **multiply** with other sources.

### 3. Lock a zone behind an event

```java
@EventHandler
public void onZoneBuy(ZonePurchaseEvent event) {
    if (event.zoneId().startsWith("w5_") && !WorldFiveEvent.isOpen()) {
        event.setCancelled(true);
        event.player().sendMessage(Component.text("World 5 opens on Saturday."));
    }
}
```

For a permanent gate without code use `required-permission` in `zones.yml` instead.

### 4. A discount on eggs during a sale

```java
@EventHandler
public void onHatch(EggHatchEvent event) {
    if (SaleManager.active()) {
        event.setCost(event.cost() * 0.8);
    }
}
```

### 5. Make Shiny-looking mobs worth more

```java
@EventHandler
public void onSpawn(MobPreSpawnEvent event) {
    if (ThreadLocalRandom.current().nextDouble() < 0.02) {
        event.setLevel(event.level() + 5);
    }
}
```

Or after spawning one yourself:

```java
api.spawnMob("W1Z5f2", location, 1, "w1_zona5", "custom_pad").ifPresent(mob -> {
    api.setMobRewardMultiplier(mob, 3.0);
    api.setMobDropBonus(mob, 10.0);
});
```

### 6. Give a pet as a reward from your plugin

```java
ClickEmAPI api = ClickEmAPI.get();
if (api.givePet(player, "Z1_1")) {
    player.sendMessage("You received a pet!");
}
```

### 7. Cap damage on bosses (for a PVE event)

```java
@EventHandler
public void onHit(PlayerDamageMobEvent event) {
    api.mobType(event.mob()).ifPresent(type -> {
        if (type.endsWith("Boss") && event.damage() > 1_000_000) {
            event.setDamage(1_000_000);
        }
    });
}
```

### 8. Log every rebirth

```java
@EventHandler
public void onRebirth(PostRebirthEvent event) {
    getLogger().info(event.player().getName() + " reached rebirth " + event.count());
}
```

### 9. Show a value in your own placeholder

```java
int level = ClickEmAPI.get().level(player);
double coins = ClickEmAPI.get().balance(player);
double power = ClickEmAPI.get().stat(player, StatType.DAMAGE);
```

If you only need to **show** values in another plugin, use the `%clickem_*%` [placeholders](/lethium-docs/placeholders.md). No code needed.

### 10. Optional dependency

```java
if (getServer().getPluginManager().isPluginEnabled("ClickEmCore")) {
    getServer().getPluginManager().registerEvents(new ClickEmHooks(), this);
}
```

Keep every class that mentions a ClickEm type inside `ClickEmHooks`, so your plugin still loads when ClickEm is absent.

### Testing tips

* Grant yourself levels and Coins with `/ceadmin` (see [Admin commands](/lethium-docs/commands/admin-commands.md)) to trigger events quickly.
* Use `/bosskit grant <you> boss3` to get a full test kit.
* Turn on `combat.boss-hit-debug` and `combat.fury.debug` in `mob-rewards.yml` when investigating combat events.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://lethium.gitbook.io/lethium-docs/dev-api/examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
