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

# Starting local playback

> Authorize a replay selection and start local playback without blocking the server thread.

# Starting local playback

**Runtime:** player · **Use it for:** a Watch command or local menu button

Follow the [playback guide](https://docs.marioded.com/api/playback.md) for the session and threading rules behind this example.

Declare `depend: [reverse-player]`. Invoke `watch` from a main-thread command or menu handler. The catalog check uses the authenticated player's UUID and an explicit administrator policy before starting playback.

For a production Watch UI, also track request identity/cancellation so an old asynchronous completion cannot supersede a newer request. For cross-server watching, prefer the lobby's dispatch service.

The method takes a replay UUID, as do the shipped command arguments. Parsing a UUID does not authorize access, so keep this catalogue check. Use readable names and clickable actions for presentation; do not resolve a replay by its name. On the main thread, current membership is `playerApi.getSession(viewer.getUniqueId())` or `getPlaybackService().getSessionByViewer(viewer.getUniqueId())`; control it with the returned session's `getSessionId()`, not the viewer or replay UUID.

```java theme={null}
package example;

import com.marioded.reverse.api.catalog.ReplayCatalog;
import com.marioded.reverse.api.permission.ReversePermissions;
import com.marioded.reverse.api.player.ReversePlayer;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

/** Example local Watch hook. Real command UIs should also track overlapping request identities. */
public final class PlaybackIntegration extends JavaPlugin {
  private ReversePlayer playerApi;

  @Override
  public void onEnable() {
    playerApi = ReversePlayer.get().orElseThrow(
        () -> new IllegalStateException("Reverse player is not available"));
  }

  public void watch(Player viewer, UUID replayId) {
    ReplayCatalog catalog = playerApi.getCatalog();
    if (catalog == null) {
      viewer.sendMessage("Replay catalog is unavailable.");
      return;
    }
    ReplayCatalog.Viewer actor = actor(viewer);
    catalog.find(replayId, actor).whenComplete((found, failure) -> {
      if (!isEnabled()) return;
      Bukkit.getScheduler().runTask(this, () -> {
        if (!isCurrent(viewer) || !actor.equals(actor(viewer))) return;
        if (failure != null) {
          getLogger().log(Level.WARNING, "Could not authorize replay " + replayId, failure);
          viewer.sendMessage("Could not load the replay catalog.");
          return;
        }
        if (found.isEmpty()) {
          viewer.sendMessage("Replay is missing or you may not watch it.");
          return;
        }
        playerApi.play(replayId, viewer).whenComplete((session, startFailure) -> {
          if (!isEnabled()) return;
          Bukkit.getScheduler().runTask(this, () -> {
            if (!isCurrent(viewer)) return;
            if (startFailure != null) {
              getLogger().log(Level.WARNING, "Could not play replay " + replayId, startFailure);
              viewer.sendMessage("Could not start the replay.");
            } else if (session == null) {
              viewer.sendMessage("No playback session could be started.");
            }
          });
        });
      });
    });
  }

  private ReplayCatalog.Viewer actor(Player viewer) {
    return new ReplayCatalog.Viewer(
        viewer.getUniqueId(), viewer.hasPermission(ReversePermissions.ADMIN));
  }

  private boolean isCurrent(Player viewer) {
    return viewer.isOnline() && Bukkit.getPlayer(viewer.getUniqueId()) == viewer;
  }
}
```

Copy this class into your integration and invoke `watch` from your own command or menu handler.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.