Minecraft Mods
Integrate abystrixLicense into your Forge or Fabric mod for Minecraft.
Forge (MultiLoader)
build.gradle
gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
}License Check
java
package com.example.mymod;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ModLicenseClient {
private static final String API_URL = "https://your-server.com/api/v1/validate";
private static final HttpClient client = HttpClient.newHttpClient();
public static boolean checkLicense(String licenseKey, int productId, String hwid) {
try {
JsonObject body = new JsonObject();
body.addProperty("licenseKey", licenseKey);
body.addProperty("productId", productId);
body.addProperty("hwid", hwid);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(API_URL))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body.toString()))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
JsonObject json = JsonParser.parseString(response.body()).getAsJsonObject();
return json.get("valid").getAsBoolean();
} catch (Exception e) {
return false;
}
}
}Fabric
fabric.mod.json
Add the abystrixLicense dependency in your fabric mod metadata.
Mixin-based Validation
java
@Mixin(MinecraftServer.class)
public class LicenseMixin {
private static boolean licenseValidated = false;
@Inject(at = @At("HEAD"), method = "runServer")
private void onServerStart(CallbackInfo info) {
if (!licenseValidated) {
String key = System.getProperty("abystrix.license.key");
int productId = Integer.getInteger("abystrix.license.product", 1);
String hwid = getHardwareId();
if (!ModLicenseClient.checkLicense(key, productId, hwid)) {
throw new RuntimeException("Invalid abystrixLicense license key!");
}
licenseValidated = true;
}
}
private static String getHardwareId() {
return System.getProperty("os.name") + "-" + System.getProperty("user.name");
}
}