İçeriğe geç

Paper / Spigot eklentisi

Java eklentisinde açılışta lisans doğrulama.

Son güncelleme 12 Ekim 2026v1

Örnek

import java.net.URI;
import java.net.http.*;

public final class LicenseCheck {
    private static final HttpClient HTTP = HttpClient.newHttpClient();

    public static boolean verify(String key, String product, String hwid) {
        String body = String.format("{\"key\":\"%s\",\"product\":\"%s\",\"hwid\":\"%s\"}", key, product, hwid);
        HttpRequest request = HttpRequest.newBuilder(URI.create("https://sorvia.net/api/v1/license/verify"))
            .header("content-type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build();
        try {
            String response = HTTP.send(request, HttpResponse.BodyHandlers.ofString()).body();
            return response.contains("\"valid\":true");
        } catch (Exception e) {
            return false;
        }
    }
}

onEnable içinde çağrıyı ana iş parçacığını bloklamamak için asenkron yapın; doğrulama başarısızsa getServer().getPluginManager().disablePlugin(this) ile kapatın. Gerçek projede yanıtı bir JSON kütüphanesiyle ayrıştırın.