> ## Documentation Index
> Fetch the complete documentation index at: https://velas.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Listening to and Cancelling VelaBoard Bukkit Events

> Listen to SidebarShowEvent and AddMemberToTeamEvent to intercept and optionally cancel scoreboard actions before they take effect in your plugin.

VelaBoard fires Bukkit events when key actions occur — you can listen to them and optionally cancel them before they take effect. This lets you enforce permissions, apply conditional logic, or integrate with other systems. Both events extend Bukkit's `Event` and implement `Cancellable`; register your listener the standard Bukkit way.

## SidebarShowEvent

`SidebarShowEvent` fires when a sidebar is about to be shown to a player. Cancelling it prevents the sidebar from appearing.

| Method               | Description                                                            |
| -------------------- | ---------------------------------------------------------------------- |
| `getPlayer()`        | The player about to see the sidebar.                                   |
| `getSidebar()`       | The `Sidebar` being shown.                                             |
| `getReason()`        | Why the sidebar is being shown: `PLAYER_JOIN`, `MANUALLY`, or `OTHER`. |
| `setCancelled(true)` | Prevents the sidebar from being displayed.                             |

Use `getSidebar().isPlayerSidebar()` or `getSidebar().isSharedSidebar()` to determine which type is being shown before acting on it.

```java theme={null}
@EventHandler
public void onSidebarShow(SidebarShowEvent event) {
    if (event.getReason() == SidebarShowEvent.Reason.PLAYER_JOIN) {
        // Allow join sidebars only for players with a permission
        if (!event.getPlayer().hasPermission("myplugin.sidebar")) {
            event.setCancelled(true);
        }
    }
}
```

## AddMemberToTeamEvent

`AddMemberToTeamEvent` fires when a player or entity is about to be added to a team. Cancelling it prevents the member from being added.

| Method                  | Description                                                                           |
| ----------------------- | ------------------------------------------------------------------------------------- |
| `getUniqueIdOfMember()` | UUID of the player or entity being added.                                             |
| `getTeam()`             | The `Team` they are being added to.                                                   |
| `getReason()`           | Why the member is being added: `PLAYER_JOIN`, `PLAYER_ADD`, `ENTITY_ADD`, or `OTHER`. |
| `setCancelled(true)`    | Prevents the member from joining the team.                                            |

```java theme={null}
@EventHandler
public void onTeamAdd(AddMemberToTeamEvent event) {
    // Prevent players from joining the "admin" team programmatically
    if (event.getTeam().getName().equals("admin") 
            && event.getReason() != AddMemberToTeamEvent.Reason.PLAYER_JOIN) {
        event.setCancelled(true);
    }
}
```
