> For the complete documentation index, see [llms.txt](https://impoo.gitbook.io/authenticationsystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://impoo.gitbook.io/authenticationsystem/developers/events.md).

# Events

AuthSystem uses Bukkit event listeners to enforce authentication restrictions. This page lists the events and listeners used by the plugin.

## Listeners

### PlayerJoinQuitListener

Handles player join and quit events. On join, it marks the player as unauthenticated and starts the authentication timeout. On quit, it cleans up the player's authentication state.

**Events handled:**

* `PlayerJoinEvent` — starts authentication flow
* `PlayerQuitEvent` — cleans up authentication state

**Key behavior:**

* New players are prompted to register
* Returning players are prompted to log in
* Unauthenticated players have a timeout (default 60 seconds)

### PlayerCommandListener

Intercepts commands issued by unauthenticated players. Only authentication commands are allowed.

**Events handled:**

* `PlayerCommandPreprocessEvent` — blocks unauthorized commands

**Allowed commands for unauthenticated players:**

* `/register`
* `/login`
* `/changepassword`
* `/premium`
* `/auth ...` (subcommands based on permissions)

### PlayerChatListener

Restricts chat for unauthenticated players.

**Events handled:**

* `AsyncPlayerChatEvent` — blocks chat from unauthenticated players

**Key behavior:**

* Unauthenticated players cannot send chat messages
* They receive a message telling them to log in first

## Listening to AuthSystem events

AuthSystem fires standard Bukkit events. You can listen to them in your own plugin:

```java
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class MyListener implements Listener {

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        // AuthSystem marks the player as unauthenticated here
        // You can add your own logic after AuthSystem processes the join
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        // AuthSystem cleans up authentication state here
    }
}
```

Register your listener in your plugin's `onEnable()`:

```java
@Override
public void onEnable() {
    getServer().getPluginManager().registerEvents(new MyListener(), this);
}
```

## Event priority

AuthSystem's listeners run at `EventPriority.NORMAL`. If you need to run logic before or after AuthSystem, use `EventPriority.HIGHEST` (before) or `EventPriority.LOWEST` (after).

## Custom events

AuthSystem does not currently fire custom plugin events. If you need to react to authentication state changes, poll `AuthManager.isAuthenticated(player)` or listen to the standard Bukkit events listed above.

***

> :bulb: **Tip**: If you want to execute code immediately after a player authenticates, listen to `PlayerChatEvent` or `PlayerCommandPreprocessEvent` and check `authManager.isAuthenticated(player)`.
