Skip to content

Commit

Permalink
add SpigotMC License module
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jan 14, 2024
1 parent 3ee2214 commit 23452e2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hscore-license/hscore-license-spigotmc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-license</artifactId>
<version>4.3.27-SNAPSHOT</version>
</parent>

<artifactId>hscore-license-spigotmc</artifactId>

<dependencies>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-license-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.hsgamer.hscore.license.spigotmc;

import me.hsgamer.hscore.license.common.LicenseChecker;
import me.hsgamer.hscore.license.common.LicenseResult;

public class SpigotLicenseChecker implements LicenseChecker {
private final String resource;
private final SpigotLicenseFetcher fetcher;

public SpigotLicenseChecker(String resource, SpigotLicenseFetcher fetcher) {
this.resource = resource;
this.fetcher = fetcher;
}

public SpigotLicenseChecker(String resource) {
this(resource, SpigotLicenseFetcher.defaultFetcher());
}

@Override
public LicenseResult checkLicense() {
SpigotLicenseEntry entry = fetcher.fetchLicense();
return new LicenseResult(entry.isValid() && resource.equals(entry.getResource()), entry.toProperties());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.hsgamer.hscore.license.spigotmc;

import me.hsgamer.hscore.license.common.CommonLicenseProperty;
import me.hsgamer.hscore.license.common.LicenseProperties;

public class SpigotLicenseEntry {
private final String user;
private final String resource;
private final String nonce;

public SpigotLicenseEntry(String user, String resource, String nonce) {
this.user = user;
this.resource = resource;
this.nonce = nonce;
}

public String getUser() {
return user;
}

public String getResource() {
return resource;
}

public String getNonce() {
return nonce;
}

public boolean isValid() {
return
user != null && !user.contains("__USER__")
&& resource != null && !resource.contains("__RESOURCE__")
&& nonce != null && !nonce.contains("__NONCE__");
}

public LicenseProperties toProperties() {
LicenseProperties properties = new LicenseProperties();
properties.setProperty(CommonLicenseProperty.USER, user);
properties.setProperty(CommonLicenseProperty.RESOURCE, resource);
properties.setProperty(CommonLicenseProperty.NONCE, nonce);
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.hsgamer.hscore.license.spigotmc;

public interface SpigotLicenseFetcher {
static SpigotLicenseFetcher defaultFetcher() {
return () -> {
// Will be replaced by SpigotMC
return new SpigotLicenseEntry(
"%%__USER__%%",
"%%__RESOURCE__%%",
"%%__NONCE__%%"
);
};
}

SpigotLicenseEntry fetchLicense();
}
1 change: 1 addition & 0 deletions hscore-license/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<packaging>pom</packaging>
<modules>
<module>hscore-license-common</module>
<module>hscore-license-spigotmc</module>
</modules>
</project>

0 comments on commit 23452e2

Please sign in to comment.