From cdaa0b7f5f943d40ddd973935cb55eef474282af Mon Sep 17 00:00:00 2001 From: hsgamer Date: Mon, 15 Jan 2024 23:43:54 +0700 Subject: [PATCH] comments for license modules --- .../license/common/CommonLicenseProperty.java | 20 +++++++++++++ .../hscore/license/common/LicenseChecker.java | 8 ++++++ .../license/common/LicenseProperties.java | 24 ++++++++++++++++ .../hscore/license/common/LicenseResult.java | 19 +++++++++++++ .../hscore/license/common/LicenseStatus.java | 15 ++++++++++ .../hscore/license/common/package-info.java | 4 +++ .../polymart/PolymartLicenseChecker.java | 28 +++++++++++++++++++ .../polymart/PolymartLicenseEntry.java | 15 ++++++++++ .../polymart/PolymartLicenseFetcher.java | 14 ++++++++++ .../hscore/license/polymart/package-info.java | 4 +++ .../spigotmc/SpigotLicenseChecker.java | 14 ++++++++++ .../license/spigotmc/SpigotLicenseEntry.java | 13 +++++++++ .../spigotmc/SpigotLicenseFetcher.java | 14 ++++++++++ .../hscore/license/spigotmc/package-info.java | 4 +++ 14 files changed, 196 insertions(+) create mode 100644 hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/package-info.java create mode 100644 hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/package-info.java create mode 100644 hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/package-info.java diff --git a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/CommonLicenseProperty.java b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/CommonLicenseProperty.java index b3e99558b3..e3ecd6615e 100644 --- a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/CommonLicenseProperty.java +++ b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/CommonLicenseProperty.java @@ -1,9 +1,24 @@ package me.hsgamer.hscore.license.common; +/** + * The common license properties for {@link LicenseProperties} + */ public enum CommonLicenseProperty { + /** + * The identifier of the user + */ USER("user"), + /** + * The identifier of the resource + */ RESOURCE("resource"), + /** + * The unique identifier of the license + */ NONCE("nonce"), + /** + * The type of the license + */ TYPE("type"), ; private final String key; @@ -12,6 +27,11 @@ public enum CommonLicenseProperty { this.key = key; } + /** + * Get the key + * + * @return the key + */ public String getKey() { return key; } diff --git a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseChecker.java b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseChecker.java index 6ed7575c18..9ee22a5070 100644 --- a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseChecker.java +++ b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseChecker.java @@ -1,5 +1,13 @@ package me.hsgamer.hscore.license.common; +/** + * The license checker + */ public interface LicenseChecker { + /** + * Check the license + * + * @return the result + */ LicenseResult checkLicense(); } diff --git a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseProperties.java b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseProperties.java index c44093efd2..31406cd4d9 100644 --- a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseProperties.java +++ b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseProperties.java @@ -2,19 +2,43 @@ import java.util.Properties; +/** + * The license properties + */ public class LicenseProperties extends Properties { + /** + * Create a new instance + */ public LicenseProperties() { super(); } + /** + * Create a new instance + * + * @param defaults the default properties + */ public LicenseProperties(Properties defaults) { super(defaults); } + /** + * Get the property + * + * @param key the key + * + * @return the property + */ public String getProperty(CommonLicenseProperty key) { return getProperty(key.getKey()); } + /** + * Set the property + * + * @param key the key + * @param value the value + */ public void setProperty(CommonLicenseProperty key, String value) { setProperty(key.getKey(), value); } diff --git a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseResult.java b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseResult.java index e0cb8c8a01..d52c2f383f 100644 --- a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseResult.java +++ b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseResult.java @@ -1,18 +1,37 @@ package me.hsgamer.hscore.license.common; +/** + * The result from {@link LicenseChecker} + */ public class LicenseResult { private final LicenseStatus status; private final LicenseProperties properties; + /** + * Create a new result + * + * @param status the status + * @param properties the properties + */ public LicenseResult(LicenseStatus status, LicenseProperties properties) { this.status = status; this.properties = properties; } + /** + * Get the status + * + * @return the status + */ public LicenseStatus getStatus() { return status; } + /** + * Get the properties + * + * @return the properties + */ public LicenseProperties getProperties() { return properties; } diff --git a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseStatus.java b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseStatus.java index 0ef017fe88..e337d167d1 100644 --- a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseStatus.java +++ b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/LicenseStatus.java @@ -1,8 +1,23 @@ package me.hsgamer.hscore.license.common; +/** + * The status of the license + */ public enum LicenseStatus { + /** + * The license is valid + */ VALID, + /** + * The license is invalid + */ INVALID, + /** + * The checker is offline + */ OFFLINE, + /** + * Unknown status + */ UNKNOWN } diff --git a/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/package-info.java b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/package-info.java new file mode 100644 index 0000000000..389ad4d496 --- /dev/null +++ b/hscore-license/hscore-license-common/src/main/java/me/hsgamer/hscore/license/common/package-info.java @@ -0,0 +1,4 @@ +/** + * Contains the base classes for the license checker + */ +package me.hsgamer.hscore.license.common; \ No newline at end of file diff --git a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseChecker.java b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseChecker.java index 0e63611f55..0f1e81d11f 100644 --- a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseChecker.java +++ b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseChecker.java @@ -4,26 +4,54 @@ import me.hsgamer.hscore.license.common.LicenseResult; import me.hsgamer.hscore.license.common.LicenseStatus; +/** + * The license checker for Polymart + */ // TODO: Use Polymart API to check the license public class PolymartLicenseChecker implements LicenseChecker { private final String resource; private final boolean isPaid; private final PolymartLicenseFetcher fetcher; + /** + * Create a new license checker + * + * @param resource the resource id + * @param isPaid whether the resource is paid + * @param fetcher the license fetcher + */ public PolymartLicenseChecker(String resource, boolean isPaid, PolymartLicenseFetcher fetcher) { this.resource = resource; this.isPaid = isPaid; this.fetcher = fetcher; } + /** + * Create a new license checker with the default fetcher + * + * @param resource the resource id + * @param isPaid whether the resource is paid + */ public PolymartLicenseChecker(String resource, boolean isPaid) { this(resource, isPaid, PolymartLicenseFetcher.defaultFetcher()); } + /** + * Check whether the checker can be used + * + * @param identifier the identifier + * + * @return true if it can be used + */ public static boolean isAvailable(String identifier) { return "1".equals(identifier); } + /** + * Check whether the checker can be used + * + * @return true if it can be used + */ public static boolean isAvailable() { return isAvailable("%%__POLYMART__%%"); } diff --git a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseEntry.java b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseEntry.java index f25db94499..5193e823a8 100644 --- a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseEntry.java +++ b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseEntry.java @@ -3,6 +3,9 @@ import me.hsgamer.hscore.license.common.CommonLicenseProperty; import me.hsgamer.hscore.license.common.LicenseProperties; +/** + * The license entry for Polymart + */ public class PolymartLicenseEntry { public final String user; public final String username; @@ -26,6 +29,13 @@ public PolymartLicenseEntry(String user, String username, String resource, Strin this.timestamp = timestamp; } + /** + * Check if the entry is valid + * + * @param isPaid if the resource is paid + * + * @return true if it is + */ public boolean isValid(boolean isPaid) { boolean valid = user != null && !user.isEmpty() && !user.contains("__USER__") @@ -44,6 +54,11 @@ public boolean isValid(boolean isPaid) { return valid; } + /** + * Convert to properties + * + * @return the properties + */ public LicenseProperties toProperties() { LicenseProperties properties = new LicenseProperties(); properties.put(CommonLicenseProperty.TYPE, "polymart"); diff --git a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseFetcher.java b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseFetcher.java index 3b94ce44a7..5b7304e315 100644 --- a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseFetcher.java +++ b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/PolymartLicenseFetcher.java @@ -1,6 +1,15 @@ package me.hsgamer.hscore.license.polymart; +/** + * Fetch the {@link PolymartLicenseEntry} + */ public interface PolymartLicenseFetcher { + /** + * The default fetcher. + * The values will be replaced by Polymart when uploading the resource. + * + * @return the default fetcher + */ static PolymartLicenseFetcher defaultFetcher() { return () -> { // Will be replaced by Polymart @@ -18,5 +27,10 @@ static PolymartLicenseFetcher defaultFetcher() { }; } + /** + * Fetch the license entry + * + * @return the license entry + */ PolymartLicenseEntry fetchLicense(); } diff --git a/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/package-info.java b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/package-info.java new file mode 100644 index 0000000000..af329ec23c --- /dev/null +++ b/hscore-license/hscore-license-polymart/src/main/java/me/hsgamer/hscore/license/polymart/package-info.java @@ -0,0 +1,4 @@ +/** + * Contains the implementation of {@link me.hsgamer.hscore.license.common.LicenseChecker} for Polymart + */ +package me.hsgamer.hscore.license.polymart; \ No newline at end of file diff --git a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseChecker.java b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseChecker.java index f741c193ca..ca8d889e7c 100644 --- a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseChecker.java +++ b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseChecker.java @@ -4,15 +4,29 @@ import me.hsgamer.hscore.license.common.LicenseResult; import me.hsgamer.hscore.license.common.LicenseStatus; +/** + * The license checker for SpigotMC + */ public class SpigotLicenseChecker implements LicenseChecker { private final String resource; private final SpigotLicenseFetcher fetcher; + /** + * Create a new license checker + * + * @param resource the resource id + * @param fetcher the fetcher + */ public SpigotLicenseChecker(String resource, SpigotLicenseFetcher fetcher) { this.resource = resource; this.fetcher = fetcher; } + /** + * Create a new license checker with the default fetcher + * + * @param resource the resource id + */ public SpigotLicenseChecker(String resource) { this(resource, SpigotLicenseFetcher.defaultFetcher()); } diff --git a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseEntry.java b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseEntry.java index 121565b2ff..4492438714 100644 --- a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseEntry.java +++ b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseEntry.java @@ -3,6 +3,9 @@ import me.hsgamer.hscore.license.common.CommonLicenseProperty; import me.hsgamer.hscore.license.common.LicenseProperties; +/** + * The license entry for SpigotMC + */ public class SpigotLicenseEntry { public final String user; public final String resource; @@ -14,6 +17,11 @@ public SpigotLicenseEntry(String user, String resource, String nonce) { this.nonce = nonce; } + /** + * Check if the entry is valid + * + * @return true if it is + */ public boolean isValid() { return user != null && !user.contains("__USER__") @@ -21,6 +29,11 @@ public boolean isValid() { && nonce != null && !nonce.contains("__NONCE__"); } + /** + * Convert to properties + * + * @return the properties + */ public LicenseProperties toProperties() { LicenseProperties properties = new LicenseProperties(); properties.setProperty(CommonLicenseProperty.TYPE, "spigotmc"); diff --git a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseFetcher.java b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseFetcher.java index 0e2346058f..01bb8e63fe 100644 --- a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseFetcher.java +++ b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/SpigotLicenseFetcher.java @@ -1,6 +1,15 @@ package me.hsgamer.hscore.license.spigotmc; +/** + * Fetch the {@link SpigotLicenseEntry} + */ public interface SpigotLicenseFetcher { + /** + * The default fetcher. + * The values will be replaced by SpigotMC when uploading the resource. + * + * @return the default fetcher + */ static SpigotLicenseFetcher defaultFetcher() { return () -> { // Will be replaced by SpigotMC @@ -12,5 +21,10 @@ static SpigotLicenseFetcher defaultFetcher() { }; } + /** + * Fetch the license entry + * + * @return the license entry + */ SpigotLicenseEntry fetchLicense(); } diff --git a/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/package-info.java b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/package-info.java new file mode 100644 index 0000000000..c7307882fb --- /dev/null +++ b/hscore-license/hscore-license-spigotmc/src/main/java/me/hsgamer/hscore/license/spigotmc/package-info.java @@ -0,0 +1,4 @@ +/** + * Contains the implementation of {@link me.hsgamer.hscore.license.common.LicenseChecker} for SpigotMC + */ +package me.hsgamer.hscore.license.spigotmc; \ No newline at end of file