# 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
