# Server Software

### Prerequisites

* Java Development Environment
* Maven/Gradle
* Your Minecraft server project
* SunLicense API credentials

### Integration Steps

#### 1. Add Dependencies

Add this to your `pom.xml`:

```xml
<repositories>
    <repository>
        <id>sundevs</id>
        <name>Sundevs Repository</name>
        <url>https://repo.hapangama.com/releases</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.hapangama</groupId>
        <artifactId>SunLicenseAPI</artifactId>
        <version>1.0.3</version>
    </dependency>
</dependencies>
```

#### 2. Create License Validator

```java
public class ServerLicenseManager {
    private final SunLicenseAPI licenseApi;
    private final Server server;

    public ServerLicenseManager(Server server, String licenseKey, int productId) {
        this.server = server;
        this.licenseApi = SunLicenseAPI.getLicense(
            licenseKey,
            productId,
            "1.0.0",
            "YOUR_API_URL"
        );
    }

    public boolean validateLicense() {
        try {
            licenseApi.validate();
            return true;
        } catch (IOException e) {
            server.getLogger().severe("License validation failed: " + e.getMessage());
            return false;
        }
    }
}
```

#### 3. Implement in Server Startup

```java
public class CustomServer {
    private ServerLicenseManager licenseManager;

    public void startServer() {
        // Initialize license manager
        licenseManager = new ServerLicenseManager(
            this,
            "YOUR-LICENSE-KEY",
            YOUR_PRODUCT_ID
        );

        // Validate license before server starts
        if (!licenseManager.validateLicense()) {
            System.err.println("Invalid license - Server startup aborted");
            System.exit(1);
        }

        // Continue with server startup
        initializeServer();
    }
}
```

### Best Practices

1. **Startup Validation**
   * Validate license before server initialization
   * Implement graceful shutdown on validation failure
   * Log validation status
2. **Regular Validation**
   * Implement periodic checks
   * Handle network issues gracefully
   * Cache validation results
3. **Error Handling**
   * Clear error messages
   * Proper logging
   * Graceful shutdown procedures

### Troubleshooting

1. **Startup Failures**
   * Check license key validity
   * Verify network connectivity
   * Confirm product ID
2. **Runtime Issues**
   * Monitor validation logs
   * Check for network problems
   * Verify license hasn't expired


---

# 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://docs.sunlicense.hapangama.com/product-integrations/server-software.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.
