> 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/ui-extensions.md).

# Extending the UI

Register a catalog action and a playback hotbar item using the public UI contracts.

**Runtime:** player · **Use it for:** a custom catalog action and restart control

Follow the [UI extension guide](/api-how-to-guides/ui-extensions.md) for registration, slot validation, and cleanup rules.

Declare `depend: [reverse-player]`. This example adds a menu action that shows the replay ID and a hotbar button that restarts playback. Reserve a free hotbar slot before registering: slot 8 is free in the defaults, but may be used by customized layouts.

The player menu registry is nullable in network-worker mode. The hotbar remains a separate service. Add `action: example:show_id` to an appropriate replay-bearing menu item if you want to expose the menu action.

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

```java
package example;

import com.marioded.reverse.api.gui.action.MenuActionRegistry;
import com.marioded.reverse.api.player.spi.ReversePlayer;
import com.marioded.reverse.api.player.spi.layout.LayoutItem;
import com.marioded.reverse.api.player.spi.service.LayoutService;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

/** Example player extension. Declare depend: [reverse-player] and reserve a free slot. */
public final class UiExtensions extends JavaPlugin {
  private LayoutService layout;
  private MenuActionRegistry menus;
  private boolean installed;

  @Override
  public void onEnable() {
    ReversePlayer api = ReversePlayer.get().orElseThrow();
    layout = api.getLayoutService();
    menus = api.getActionRegistry();
    if (menus != null) {
      menus.register("example:show_id", (context, parameters) -> {
        if (context.isActive() && context.hasReplay()) {
          context.player().sendMessage(context.requireReplay().getUniqueId().toString());
        }
      });
    }
    layout.registerAction("example:restart", (context, parameters) -> {
      context.playbackService().seekTo(context.session(), 0);
      context.playbackService().resume(context.session());
    });
    layout.setItem(new LayoutItem(
        "example:restart_item", 8,
        context -> new ItemStack(Material.ARROW),
        Map.of(LayoutItem.Click.LEFT,
            new LayoutItem.Binding("example:restart", Map.of()))));
    installed = true;
  }

  @Override
  public void onDisable() {
    if (menus != null) menus.unregister("example:show_id");
    if (layout != null) {
      if (installed) layout.removeItem("example:restart_item");
      // LayoutService has no unregisterAction. Retire our noncapturing callback explicitly.
      layout.registerAction("example:restart", (context, parameters) -> {});
    }
  }
}
```

{% endcode %}

Copy this class into your integration. Programmatic registrations require explicit cleanup; they are not automatically owned by the registering plugin.


---

# 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/ui-extensions.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.
