# Custom Events

## [MobCoinsReceiveEvent](https://github.com/aglerr/TheOnly-MobCoins/blob/master/src/main/java/me/aglerr/mobcoins/api/events/MobCoinsReceiveEvent.java)

This event is called when players receive mobcoins from killing mobs that are specified or configured in mobs.yml and this event is cancellable.

{% code title="Example Usage" %}

```java
@EventHandler
public void onCoinsReceived(MobCoinsReceiveEvent event){
    // Get the player that's involved in this event
    Player player = event.getPlayer();
    // We want to multiply the coins received if the
    // player has 'mobcoins.multiply.2' permissions.
    if(player.hasPermission("mobcoins.multiply.2")){
        // Get the amount player receives
        double coinsReceived = event.getAmountReceived();
        event.setAmountReceived((coinsReceived * 2));
    }
    // Get the amount received after being multiply
    double finalAmount = event.getAmountReceived();
    // We want to cancel the event if player recevies
    // mobcoins greather than 3000
    if(finalAmount > 3000){
        // If cancelled, player will not receives
        // the mobcoins
        event.setCancelled(true);
    }
}
```

{% endcode %}

## [MobCoinsRedeemEvent](https://github.com/aglerr/TheOnly-MobCoins/blob/master/src/main/java/me/aglerr/mobcoins/api/events/MobCoinsRedeemEvent.java)

This event is called when players redeem physical mobcoins.

{% code title="Example Usage" %}

```java
@EventHandler
public void onCoinsRedeemed(MobCoinsRedeemEvent event){
    // Get the player that's involved in this event
    Player player = event.getPlayer();
    // We want to multiply the coins received if the
    // player has 'mobcoins.multiply.2' permissions.
    if(player.hasPermission("mobcoins.multiply.2")){
        // Get the amount player receives
        double coinsReceived = event.getAmount();
        event.setAmount((coinsReceived * 2));
    }
    // Get the amount received after being multiply
    double finalAmount = event.getAmountReceived();
    // We want to cancel the event if player recevies
    // mobcoins greather than 3000
    if(finalAmount > 3000){
        // If cancelled, player will not receives
        // the mobcoins
        event.setCancelled(true);
    }
}
```

{% endcode %}

## [MobCoinsSpawnEvent](https://github.com/aglerr/TheOnly-MobCoins/blob/master/src/main/java/me/aglerr/mobcoins/api/events/MobCoinsSpawnEvent.java)

This event is called when player kills a mobs and the mobs dropped a physical mobcoins.

{% code title="Example Usage" %}

```java
@EventHandler
public void onCoinsSpawned(MobCoinsSpawnEvent event){
    // In this example, there is 50% chance that the drop
    // amount will be multiplied by 2
    // First we generate the random number
    int random = ThreadLocalRandom.current().nextInt(101);
    // We check if the random number is below or equals to 50
    if(random <= 50){
        // Get the drop amount
        double coinsDropped = event.getAmountToDrop();
        // Multiply the drop amount
        event.setAmountToDrop(coinsDropped * 2);
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aglerr.gitbook.io/wiki/theonly-series/the-only-mobcoins/developer-api/custom-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
