> For the complete documentation index, see [llms.txt](https://docs.marioded.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.marioded.com/api-how-to-guides/examples/playback-integration.md).

# Starting local playback

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

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

Follow the [playback guide](/api-how-to-guides/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.

{% code title="PlaybackIntegration.java" %}

```java
package example;

import com.marioded.reverse.api.catalog.ReplayCatalog;
import com.marioded.reverse.api.player.spi.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("reverse.admin"));
  }

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

{% endcode %}

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.marioded.com/api-how-to-guides/examples/playback-integration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
