> 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/recording-integration.md).

# Recording a match

Start a bounded match recording and handle asynchronous persistence outcomes.

**Runtime:** recorder · **Use it for:** match start/end hooks

Follow the [recording guide](/api-how-to-guides/recording.md) for the lifecycle and selection rules behind this example.

Declare `depend: [reverse-recorder]` in this integration's plugin descriptor. Call `startMatch` and `finishMatch` from your own main-thread match lifecycle, and store the returned session UUID with your match. Adjust the bounds, owners, and participants to your arena.

This example only publishes a normal replay-ready notification after event persistence and terrain have succeeded. A degraded save retains events but needs separate handling.

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

```java
package example;

import com.marioded.reverse.api.RecordSession;
import com.marioded.reverse.api.RecordingBounds;
import com.marioded.reverse.api.ReplayText;
import com.marioded.reverse.api.catalog.ReplayCatalog;
import com.marioded.reverse.api.recorder.spi.ReverseRecorder;
import com.marioded.reverse.api.recorder.spi.service.StopResult;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletionStage;
import java.util.logging.Level;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;

/** Example match hooks; invoke start/finish from your own main-thread match lifecycle. */
public final class RecordingIntegration extends JavaPlugin {
  private ReverseRecorder recorder;

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

  public UUID startMatch(World world, UUID ownerId, Set<UUID> participants) {
    ReplayCatalog.validateMetadata("Arena final", "Best of three");
    RecordSession session = recorder.getRecorderService().startRecording(
        world, null, List.of(ownerId), new ReplayText("Arena final", "Best of three"),
        new RecordingBounds(-64, 0, -64, 64, 255, 64), Set.copyOf(participants));
    return session.getUniqueId(); // Store this in your match object.
  }

  public CompletionStage<StopResult> finishMatch(UUID sessionId) {
    CompletionStage<StopResult> saving = recorder.getRecorderService().stopSession(sessionId);
    saving.whenComplete((result, failure) -> {
      if (failure != null) {
        getLogger().log(Level.SEVERE, "Could not save recording " + sessionId, failure);
        return;
      }
      if (result.replayId() == null) {
        getLogger().warning("Recording was already stopped: " + sessionId);
        return;
      }
      if (result.degraded()) {
        getLogger().log(Level.WARNING, "Events saved without usable terrain: " + result.replayId(),
            result.terrainFailure());
        return;
      }
      // Publish the UUID to your match database or application here.
      // Schedule onto the main thread before touching Bukkit player/world state.
      getLogger().info("Replay ready: " + result.replayId());
    });
    return saving;
  }
}
```

{% endcode %}

Copy this class into your integration and connect its methods to your match lifecycle.


---

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