# Events

### `ModuleTriggerEvent`

`com.kixmc.csapi.api.ModuleTriggerEvent`

This event is fired by ChatSentry when a module triggers.

```java
// get the violation/detection type
APIViolationType getType()

// get the context in which this event was triggered from (chat, command, etc)
APITriggerContext getContext()

// get the player who triggered this event
Player getPlayer()

// get the message before running through the module
String getOldContent()

// get the message after ran through the module
String getNewContent()

// get return the blocked content
String getBlockedContent()

// sets whether the event is cancelled
void setCancelled(boolean)

// returns whether the event is cancelled
boolean isCancelled()
```

### Violation types / supported modules

Any modules that have a violation/detection (`APIViolationType`) type associated with them are supported by this event. The below are valid detection types:

* **`ON_COOLDOWN`**
* **`LINK_OR_AD_BLOCK`**
* **`MESSAGE_FILTER_BLOCK`**
* **`WORD_REPLACER_REPLACE`** (legacy)
* **`SPAM_BLOCK`**
* **`UNICODE_CHARACTER_BLOCK`**
* **`CAP_LIMITER_BLOCK`**
* **`ANTI_PARROT_BLOCK`**
* **`ANTI_CHAT_FLOOD_BLOCK`**
* **`ANTI_STATUE_SPAMBOT_BLOCK`**
* **`ANTI_JOIN_FLOOD_BLOCK`**
* **`CHAT_MODIFIER_MODIFY`** (legacy)
* **`CHAT_EXECUTOR_MATCH`**

### Context types

Below are the valid `APITriggerContext` types:

* **`CHAT`**
* **`COMMAND`**
* **`ANVIL`**
* **`BOOK`**
* **`SIGN`**
* **`JOIN`**
* **`OTHER`** (currently unused)

### Code examples

For testing if everything is working properly

```java
@EventHandler
public void onModuleTrigger(ModuleTriggerEvent e) {
    Bukkit.broadcastMessage("Module trigger event fired! Details:");
    Bukkit.broadcastMessage("Trigger player: " + e.getPlayer().getName());
    Bukkit.broadcastMessage("Trigger type: " + e.getType().toString());
    Bukkit.broadcastMessage("Trigger context: " + e.getContext());
    Bukkit.broadcastMessage("Original msg: " + e.getOldContent());
    Bukkit.broadcastMessage("New msg: " + e.getNewContent());
    Bukkit.broadcastMessage("Blocked content: " + e.getBlockedContent());
    Bukkit.broadcastMessage("Event cancelled: " + e.isCancelled());
}
```

Checking contexts and types

```java
@EventHandler
public void onModuleTrigger(ModuleTriggerEvent e) {
    if (e.getContext() == APITriggerContext.BOOK && e.getType() == APIViolationType.UNICODE_CHARACTER_BLOCK) {
        // do something only if context was a book and detection type was from the unicode remover
    }
}
```

Cancelling under custom conditions

```java
@EventHandler
public void onModuleTrigger(ModuleTriggerEvent e) {
    if(e.getPlayer().getStatistic(Statistic.PLAY_ONE_MINUTE) >= 60) e.setCancelled(true); // allow players who have played 1+ hours to bypass filters
}
```


---

# 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://wiki.chatsentry.xyz/api/api-documentation/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.
