> ## 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.

# PlayerSidebar vs SharedSidebar: Choosing the Right Type

> VelaBoard provides two sidebar types: PlayerSidebar for individual displays and SharedSidebar for showing identical content to many players at once.

VelaBoard provides two sidebar types that serve different display needs. A `PlayerSidebar` is bound to exactly one player and shows that player individual content. A `SharedSidebar` carries a single set of content that can be displayed to multiple players simultaneously. Both types share the same core `Sidebar` interface for managing lines, titles, and visibility.

<Tabs>
  <Tab title="PlayerSidebar">
    A `PlayerSidebar` is scoped to a single player. Create one through your `Scoreboard`, assign it to the player with `setPlayer(Player)`, and call `show()` to display it.

    ```java theme={null}
    PlayerSidebar sidebar = board.createPlayerSidebar("§6Stats");
    sidebar.setLine(0, "§7Score: §f250");
    sidebar.setLine(1, "§7Level: §f12");
    sidebar.setPlayer(player);
    sidebar.show();
    ```

    To hide the sidebar without destroying it, call `hide()`. You can call `show()` again later to bring it back.

    ```java theme={null}
    sidebar.hide();
    ```

    To check or change which player is assigned:

    ```java theme={null}
    Player assigned = sidebar.getPlayer();
    sidebar.setPlayer(anotherPlayer);
    ```

    Use `removePlayer()` to detach the sidebar from its current player without destroying the sidebar itself.
  </Tab>

  <Tab title="SharedSidebar">
    A `SharedSidebar` has an ID and can be shown to multiple players at once. Create one with an explicit ID or let VelaBoard generate one:

    ```java theme={null}
    // With an explicit ID
    SharedSidebar shared = board.createSharedSidebar("server-info", "§bServer Info");

    // With an auto-generated ID
    SharedSidebar shared = board.createSharedSidebar("§bServer Info");
    ```

    Add players to the sidebar's roster with `addPlayer(Player)`, then call `show()` to display it to all of them at once:

    ```java theme={null}
    shared.addPlayer(player1);
    shared.addPlayer(player2);
    shared.setLine(0, "§7Online: §f" + Bukkit.getOnlinePlayers().size());
    shared.show();
    ```

    To show the sidebar to a specific player by UUID without adding them to the roster:

    ```java theme={null}
    shared.showTo(player.getUniqueId());
    ```

    To hide the sidebar for a specific player:

    ```java theme={null}
    shared.hideFrom(player.getUniqueId());
    ```

    To hide it from all viewers at once:

    ```java theme={null}
    shared.hide();
    ```

    Other useful methods:

    | Method                 | Description                                                       |
    | ---------------------- | ----------------------------------------------------------------- |
    | `getId()`              | Returns the sidebar's unique string ID.                           |
    | `getPlayers()`         | Returns the roster of players added via `addPlayer`.              |
    | `getViewers()`         | Returns the players currently viewing the sidebar.                |
    | `isViewedBy(UUID)`     | Returns `true` if the given player is currently viewing it.       |
    | `isBeingViewedByAll()` | Returns `true` if all roster players are currently viewing it.    |
    | `removePlayer(Player)` | Removes a player from the roster and hides the sidebar from them. |
  </Tab>
</Tabs>

## Sidebar lines

Each sidebar supports up to 15 lines, indexed from `0` (top) to `14` (bottom). Use `setLine(int, String)` to set or update a line, `removeLine(int)` to clear a specific line, and `clearLines()` to remove all lines at once.

```java theme={null}
sidebar.setLine(0, "§7Score: §f100");
sidebar.setLine(1, "§7Level: §f5");

// Read a line back
String line = sidebar.getLine(0); // returns null if not set

// Remove a specific line
sidebar.removeLine(1);

// Remove all lines
sidebar.clearLines();
```

<Note>
  Line indices start at `0` and go up to `14`, giving you 15 lines in total. Passing an index outside this range has no effect.
</Note>

You can also update the title at any time:

```java theme={null}
sidebar.setTitle("§6Updated Title");
String current = sidebar.getTitle();
```

## Visibility control

`canView(boolean)` controls whether the sidebar is allowed to be shown. Set it to `false` to prevent the sidebar from appearing even if `show()` is called, and back to `true` to re-enable display.

```java theme={null}
// Prevent the sidebar from being shown
sidebar.canView(false);

// Re-enable visibility
sidebar.canView(true);

// Check current setting
boolean allowed = sidebar.canView();
```

Use `isBeingViewed()` to check whether the sidebar is currently visible to at least one player:

```java theme={null}
if (sidebar.isBeingViewed()) {
    // sidebar is actively displayed
}
```

## Lifecycle

When you no longer need a sidebar, call `remove()` to destroy it and clean up its resources. You can check whether a sidebar has already been destroyed with `isRemoved()`.

```java theme={null}
sidebar.remove();

if (sidebar.isRemoved()) {
    // sidebar has been destroyed
}
```

To check which type a `Sidebar` reference holds, or to safely cast it:

```java theme={null}
if (sidebar.isPlayerSidebar()) {
    Optional<PlayerSidebar> ps = sidebar.asPlayerSidebar();
}

if (sidebar.isSharedSidebar()) {
    Optional<SharedSidebar> ss = sidebar.asSharedSidebar();
}
```

You can also check whether a particular player is associated with any sidebar type:

```java theme={null}
sidebar.hasPlayer(player); // true if the player is registered with this sidebar
```
