From dd54ff1944d3db9eb8f2157da401cb5371a06e91 Mon Sep 17 00:00:00 2001 From: Patrick <147879351+WinniePatGG@users.noreply.github.com> Date: Fri, 5 Jun 2026 23:58:33 +0200 Subject: [PATCH] Javadoc --- .gitignore | 1 + src/main/java/licenselib/LicenseClient.java | 35 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index d7ba5a3..1b00d98 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build gradle run +pierre.md # VERY IMPORTANT gradle.properties \ No newline at end of file diff --git a/src/main/java/licenselib/LicenseClient.java b/src/main/java/licenselib/LicenseClient.java index af51977..3634876 100644 --- a/src/main/java/licenselib/LicenseClient.java +++ b/src/main/java/licenselib/LicenseClient.java @@ -74,6 +74,14 @@ public class LicenseClient { */ public sealed interface LicenseResult permits LicenseSuccess, LicenseError {} + /** + * Creates an HttpRequest that will be used for sync and async checking + * @param apiUrl Server API url + * @param plugin Plugin id matching the one on the backend api + * @param licenseKey License key issued by the api + * @param serverId Server id matching the one on the backend api + * @return HttpRequest ready to be sent to the backend + */ private static HttpRequest createRequest( String apiUrl, String plugin, @@ -98,17 +106,34 @@ public class LicenseClient { .build(); } + /** + * Builds a LicenseError from a Throwable + * @param throwable The Throwable to extract the error message from + * @return LicenseError containing the error message extracted from the Throwable + */ private static LicenseResult errorResult(Throwable throwable) { String message = buildErrorMessage(throwable); return new LicenseError(message); } + /** + * Extracts a String from a Json Object passed in with a key and a fallback + * @param json The JsonObject to extract the value from + * @param key The key to look for in the JsonObject + * @param def The default value to return if the key is not present or is null in the JsonObject + * @return The String value associated with the key in the JsonObject, or the default value if the key is not present or is null + */ private static String getString(JsonObject json, String key, String def) { return json.has(key) && !json.get(key).isJsonNull() ? json.get(key).getAsString() : def; } + /** + * Parses the HttpResponse from the license server API and constructs a LicenseResult based on the response status code and body content. + * @param response The HttpResponse received from the license server API after sending the license check request + * @return LicenseResult representing either a successful license check with details or an error if the response indicates a failure or cannot be parsed correctly + */ private static LicenseResult fromHttpResponse(HttpResponse response) { if (response.statusCode() != 200) { return errorResult(new RuntimeException( @@ -130,6 +155,11 @@ public class LicenseClient { ); } + /** + * Validates if a url is valid with the http or https protocol + * @param apiUrl The url to validate + * @return URI object if the url is valid + */ private static URI validateUrl(String apiUrl) { URI uri = URI.create(apiUrl); @@ -144,6 +174,11 @@ public class LicenseClient { return uri; } + /** + * Helper method to build an error message from a Throwable + * @param t Throwable to get the cause from + * @return A string containing the class name and message of the root cause of the Throwable, or just the class name if the message is null or blank + */ private static String buildErrorMessage(Throwable t) { Throwable root = t;