Minecraft Mods

SunLicense Integration Guide for Minecraft Mods

Prerequisites

  • Forge/Fabric mod development environment

  • Gradle

  • SunLicense API credentials

Integration Steps

1. Add Repository and Dependency

In your build.gradle:

repositories {
    maven {
        url "https://repo.hapangama.com/releases"
    }
}

dependencies {
    implementation 'com.hapangama:SunLicenseAPI:1.0.3'
}

2. Create License Manager

public class ModLicenseManager {
    private final SunLicenseAPI licenseApi;
    private static final Logger LOGGER = LogManager.getLogger();

    public ModLicenseManager() {
        this.licenseApi = SunLicenseAPI.getLicense(
            "YOUR-LICENSE-KEY",
            YOUR_PRODUCT_ID,
            "1.0.0",
            "YOUR_API_URL"
        );
    }

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

3. Implement in Mod Main Class

public class YourMod {
    private ModLicenseManager licenseManager;

    public void onInitialize() { // For Fabric
    // OR
    public void init(FMLCommonSetupEvent event) { // For Forge
        licenseManager = new ModLicenseManager();
        
        if (!licenseManager.validateLicense()) {
            LOGGER.error("Invalid license - Mod will not function!");
            // Disable mod functionality
            return;
        }
        
        // Continue with mod initialization
    }
}

Best Practices

  1. Mod Loading

    • Validate before initializing features

    • Provide clear feedback to users

    • Handle offline mode gracefully

  2. Feature Management

    • Graceful feature disabling

    • Clear user communication

    • Cache validation results

Common Issues

  1. Mod Loading Failures

    • Verify license key

    • Check network connectivity

    • Confirm dependency inclusion

  2. Runtime Problems

    • Monitor mod logs

    • Check for network issues

    • Verify license status

Last updated