# Minecraft Plugins

### Prerequisites

* Spigot/Paper development environment
* Maven or Gradle build system
* SunLicense API credentials
* Your product ID and license key

### Integration Steps

#### 1. Add Repository and Dependency

**For Maven (plugin.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 Manager Class

```java
public class LicenseManager {
    private final JavaPlugin plugin;
    private SunLicenseAPI licenseApi;

    public LicenseManager(JavaPlugin plugin) {
        this.plugin = plugin;
        setupLicense();
    }

    private void setupLicense() {
        // Save default config if it doesn't exist
        plugin.saveDefaultConfig();
        
        // Initialize license API
        licenseApi = SunLicenseAPI.getLicense(
            plugin.getConfig().getString("license.key"),
            602, // Your Product Id
            "1.1.0", // Your Product Version (Plugin Version)
            "YOUR_API_URL"
        );

    }

    public void validateLicense() {
        try {
            licenseApi.validate();
            plugin.getLogger().info("License validated successfully!");
        } catch (IOException e) {
            plugin.getLogger().severe("License validation failed: " + e.getMessage());
            Bukkit.getPluginManager().disablePlugin(plugin);
        }
    }
}
```

#### 3. Implement in Main Plugin Class

```java
public class YourPlugin extends JavaPlugin {
    private LicenseManager licenseManager;

    @Override
    public void onEnable() {
        // Initialize license manager
        licenseManager = new LicenseManager(this);
        
        // Validate license
        licenseManager.validateLicense();
        
        // Continue with plugin initialization if license is valid
        if (isEnabled()) {
            // Your plugin initialization code
        }
    }
}
```

#### 4. Create Default Config

Create `config.yml` in your plugin's resources folder:

```yaml
license:
  key: "YOUR-LICENSE-KEY"
```

#### 5. License Command Implementation (Optional)

```java
public class LicenseCommand implements CommandExecutor {
    private final LicenseManager licenseManager;

    public LicenseCommand(LicenseManager licenseManager) {
        this.licenseManager = licenseManager;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("yourplugin.license")) {
            sender.sendMessage("§cNo permission!");
            return true;
        }

        if (args.length != 1) {
            sender.sendMessage("§cUsage: /license <key>");
            return true;
        }

        // Update license logic here
        return true;
    }
}
```

### Common Issues and Solutions

1. **Plugin Won't Enable**
   * Check if license key is properly configured
   * Verify product ID matches
   * Check server connectivity to license API
2. **License Validation Fails**
   * Confirm license key hasn't expired
   * Check if HWID matches
   * Verify IP restrictions
3. **Configuration Issues**
   * Ensure config.yml is properly formatted
   * Check if all required fields are present
   * Verify encoding is UTF-8

Need additional help? Contact support or check the [Java API Documentation](/api-documentation/java-api.md) for more details.


---

# 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/minecraft-plugins.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.
