# Triggering Stop Actions

This guide shows how a feature can request a controlled stop or restart through OMS.

The example extends `HelloWorldFeature` with a command that triggers a stop request.

***

### Overview

Features do not stop the server directly.

Instead, they emit an OMS action event describing:

* the requested operation
* the reason for the request

OMS then processes the request and executes the appropriate stop flow.

***

### 1. Define a stop reason

A stop request must include a `StopReason`.

Minimal example:

```kotlin
object HelloWorldStopReason : StopReason {
    override val addonId: String = HelloWorldMod.MOD_ID
    override val name: String = "manual"
}
```

***

### Recommended pattern

To avoid repeating `addonId`, define a base type:

```kotlin
interface HelloWorldStopReason : StopReason {
    override val addonId: String
        get() = HelloWorldMod.MOD_ID
}
```

Then define reasons:

```kotlin
object HelloWorldManualStop : HelloWorldStopReason {
    override val name: String = "manual"
}
```

***

### Localization

Each stop reason automatically generates a localization key:

```json
<addonId>.stop_reason.<name>
```

Example:

```json
hello_world.stop_reason.manual
```

You can define messages in your language file:

```json
{
  "hello_world.stop_reason.manual": "Server stopped by HelloWorld feature"
}
```

***

### 2. Trigger the stop request

To request a stop, emit an OMS action event:

```kotlin
class HelloWorldStopCommand(
    private val feature: HelloWorldFeature
) : OMSCommandEntry() {

    override fun init(): ArgumentBuilder<CommandSourceStack, *> {
        return Commands.literal("stop")
            .executes { ctx ->
                val server = ctx.source.server

                MinecraftForge.EVENT_BUS.post(
                    OMSActions.StopRequestedEvent(
                        server = server,
                        reason = HelloWorldManualStop
                    )
                )
                1
            }
    }
}
```

***

### 3. Attach the command to the feature

```kotlin
class HelloWorldFeature(
    configProvider: ConfigProvider<CHelloWorldFeature>
) : OmsFeature<CHelloWorldFeature>(configProvider) {

    override val additionalCommands = listOf(
        // ...
        HelloWorldStopCommand(this)
    )

}
```

***

### 4. Use the command

After startup:

```
/oms feature hello_world stop
```

This sends a stop request to OMS.

***

### 5. Example from OMS

OMS itself defines stop reasons using the same pattern:

```kotlin
object ScheduledStop : OmsStopReason {
    override val name: String = "scheduled"
}
```

With localization:

```json
{
  "oms.stop_reason.scheduled": "Server stopping as scheduled"
}
```

***

### Notes

* Features must not stop the server directly
* All stop requests go through OMS action events
* Stop reasons are stable identifiers
* Localization is based on `messageId`
* OMS controls the actual shutdown flow


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conboi.gitbook.io/oms-wiki/developer-guide/implementation-guides/triggering-stop-actions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
