3
0
Fork 0

Bumped to v2.1 BETA

This commit is contained in:
stijnb1234 2020-08-11 10:17:53 +02:00
parent 5accb3cd0d
commit d5c8f8597a
7 changed files with 238 additions and 143 deletions

View file

@ -6,7 +6,7 @@
<groupId>nl.SBDeveloper</groupId> <groupId>nl.SBDeveloper</groupId>
<artifactId>ThemeParkPlus</artifactId> <artifactId>ThemeParkPlus</artifactId>
<version>2.0</version> <version>2.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ThemeParkPlus</name> <name>ThemeParkPlus</name>
@ -33,7 +33,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.2.1</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -51,6 +51,10 @@
<pattern>org.codemc.worldguardwrapper</pattern> <pattern>org.codemc.worldguardwrapper</pattern>
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.worldguardwrapper</shadedPattern> <shadedPattern>nl.sbdeveloper.themeparkplus.libs.worldguardwrapper</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>nl.sbdeveloper.themeparkplus.libs.bstats</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
</execution> </execution>

View file

@ -296,19 +296,19 @@ public class TPPCMD implements CommandExecutor {
if (secOn == 0) { if (secOn == 0) {
if (!LGUtil.zetLampAan(block)) { if (!LGUtil.zetLampAan(block)) {
sender.sendMessage(ConfigUtil.getMessage("Lamps.ErrorOn")); sender.sendMessage(ConfigUtil.getMessage("Lamp.ErrorOn"));
return true; return true;
} }
if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOn")); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamp.TurnedOn"));
} else { } else {
if (!LGUtil.zetLampAan(block)) { if (!LGUtil.zetLampAan(block)) {
sender.sendMessage(ConfigUtil.getMessage("Lamps.ErrorOn")); sender.sendMessage(ConfigUtil.getMessage("Lamp.ErrorOn"));
return true; return true;
} }
Bukkit.getScheduler().runTaskLater(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block), secOn * 20); Bukkit.getScheduler().runTaskLater(ThemeParkPlus.getInstance(), () -> LGUtil.zetLampUit(block), secOn * 20);
if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOnSec", Collections.singletonMap("%sec%", String.valueOf(secOn)))); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamp.TurnedOnSec", Collections.singletonMap("%sec%", String.valueOf(secOn))));
} }
return true; return true;
} }
@ -321,11 +321,11 @@ public class TPPCMD implements CommandExecutor {
Location loc = new Location(bworld, bx, by, bz); Location loc = new Location(bworld, bx, by, bz);
if (!LGUtil.zetLampUit(loc.getBlock())) { if (!LGUtil.zetLampUit(loc.getBlock())) {
sender.sendMessage(ConfigUtil.getMessage("Lamps.ErrorOn")); sender.sendMessage(ConfigUtil.getMessage("Lamp.ErrorOff"));
return true; return true;
} }
if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamps.TurnedOff")); if (ConfigUtil.sendConsole(sender)) sender.sendMessage(ConfigUtil.getMessage("Lamp.TurnedOff"));
return true; return true;
} }

View file

@ -59,9 +59,13 @@ public class SignListeners implements Listener {
} else if (lines[1].equalsIgnoreCase("Scanner") && !lines[2].isEmpty() && !lines[3].isEmpty()) { } else if (lines[1].equalsIgnoreCase("Scanner") && !lines[2].isEmpty() && !lines[3].isEmpty()) {
e.setLine(0, sLineOne); e.setLine(0, sLineOne);
e.setLine(1, sLineTwo); e.setLine(1, sLineTwo);
} else if (lines[1].equalsIgnoreCase("WaitingRow") && !lines[2].isEmpty() && !lines[3].isEmpty()) { } else if (lines[1].equalsIgnoreCase("WaitingRow") && !lines[2].isEmpty()) {
WaitingRow foundRow = PlusAPI.getRow(lines[2]); WaitingRow foundRow = PlusAPI.getRow(lines[2]);
if (foundRow == null) { if (foundRow == null) {
if (lines[3].isEmpty()) {
p.sendMessage(ConfigUtil.getMessage("General.IncorrectSign"));
return;
}
foundRow = new WaitingRow(lines[2], lines[3]); foundRow = new WaitingRow(lines[2], lines[3]);
PlusAPI.addRow(foundRow); PlusAPI.addRow(foundRow);
} }

View file

@ -7,6 +7,7 @@ import nl.sbdeveloper.themeparkplus.api.objects.Gate;
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer; import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer;
import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB; import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB;
import nl.sbdeveloper.themeparkplus.util.License;
import nl.sbdeveloper.themeparkplus.util.LocationGsonAdapter; import nl.sbdeveloper.themeparkplus.util.LocationGsonAdapter;
import org.bukkit.Location; import org.bukkit.Location;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -76,6 +77,8 @@ public class DBManager {
} }
public void save() { public void save() {
if (License.isValid() == null || !License.isValid()) return;
for (Map.Entry<Location, Gate> entry : PlusAPI.getGates().entrySet()) { for (Map.Entry<Location, Gate> entry : PlusAPI.getGates().entrySet()) {
Gson gson = getGson(); Gson gson = getGson();
byte[] blob = gson.toJson(entry.getValue()).getBytes(); byte[] blob = gson.toJson(entry.getValue()).getBytes();

View file

@ -1,6 +1,5 @@
package nl.sbdeveloper.themeparkplus.sbutils; package nl.sbdeveloper.themeparkplus.sbutils;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -22,7 +21,7 @@ import java.util.function.BiConsumer;
* Update class for SBDevelopment * Update class for SBDevelopment
* @author Stijn [SBDeveloper] * @author Stijn [SBDeveloper]
* @since 05-03-2020 * @since 05-03-2020
* @version 1.2 * @version 1.4
* *
* © Stijn Bannink <stijnbannink23@gmail.com> - All rights reserved. * © Stijn Bannink <stijnbannink23@gmail.com> - All rights reserved.
*/ */
@ -37,10 +36,10 @@ public class UpdateManager {
private static final String RESOURCE_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download"; private static final String RESOURCE_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download";
private Plugin plugin; private Plugin plugin;
private double currentVersion; private Version currentVersion;
private int resourceID; private int resourceID;
private CheckType type; private CheckType type;
private BiConsumer<VersionResponse, Double> versionResponse; private BiConsumer<VersionResponse, Version> versionResponse;
private BiConsumer<DownloadResponse, String> downloadResponse; private BiConsumer<DownloadResponse, String> downloadResponse;
/** /**
@ -52,7 +51,7 @@ public class UpdateManager {
*/ */
public UpdateManager(@NotNull Plugin plugin, int resourceID, CheckType type) { public UpdateManager(@NotNull Plugin plugin, int resourceID, CheckType type) {
this.plugin = plugin; this.plugin = plugin;
this.currentVersion = Double.parseDouble(plugin.getDescription().getVersion()); this.currentVersion = new Version(plugin.getDescription().getVersion());
this.resourceID = resourceID; this.resourceID = resourceID;
this.type = type; this.type = type;
} }
@ -62,7 +61,7 @@ public class UpdateManager {
* @param versionResponse The response * @param versionResponse The response
* @return The updatemanager * @return The updatemanager
*/ */
public UpdateManager handleResponse(BiConsumer<VersionResponse, Double> versionResponse) { public UpdateManager handleResponse(BiConsumer<VersionResponse, Version> versionResponse) {
this.versionResponse = versionResponse; this.versionResponse = versionResponse;
return this; return this;
} }
@ -104,13 +103,10 @@ public class UpdateManager {
} }
in.close(); in.close();
JsonParser parser = new JsonParser();
if (type == CheckType.SPIGOT) { if (type == CheckType.SPIGOT) {
JsonArray array = parser.parse(response.toString()).getAsJsonArray(); version = response.toString();
version = array.get(0).getAsJsonObject().get("name").getAsString();
} else if (type == CheckType.SBDPLUGINS) { } else if (type == CheckType.SBDPLUGINS) {
JsonParser parser = new JsonParser();
JsonObject object = parser.parse(response.toString()).getAsJsonObject(); JsonObject object = parser.parse(response.toString()).getAsJsonObject();
version = object.get("data").getAsJsonObject().get("version").getAsString(); version = object.get("data").getAsJsonObject().get("version").getAsString();
@ -118,11 +114,11 @@ public class UpdateManager {
if (version == null) return; if (version == null) return;
boolean latestVersion = Double.parseDouble(version) >= this.currentVersion; Version onlineVersion = new Version(version);
double versionDouble = Double.parseDouble(version); boolean latestVersion = this.currentVersion.compareTo(onlineVersion) < 0;
Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(latestVersion ? VersionResponse.LATEST : VersionResponse.FOUND_NEW, latestVersion ? this.currentVersion : versionDouble)); Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(latestVersion ? VersionResponse.LATEST : VersionResponse.FOUND_NEW, latestVersion ? this.currentVersion : onlineVersion));
} catch (IOException | NullPointerException e) { } catch (IOException | NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(VersionResponse.UNAVAILABLE, null)); Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(VersionResponse.UNAVAILABLE, null));
@ -202,4 +198,45 @@ public class UpdateManager {
DONE, ERROR, UNAVAILABLE DONE, ERROR, UNAVAILABLE
} }
public static class Version implements Comparable<Version> {
private String version;
public final String get() {
return this.version;
}
public Version(String version) {
if(version == null)
throw new IllegalArgumentException("Version can not be null");
if(!version.matches("[0-9]+(\\.[0-9]+)*"))
throw new IllegalArgumentException("Invalid version format");
this.version = version;
}
@Override
public int compareTo(@NotNull Version that) {
String[] thisParts = this.get().split("\\.");
String[] thatParts = that.get().split("\\.");
int length = Math.max(thisParts.length, thatParts.length);
for (int i = 0; i < length; i++) {
int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0;
int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0;
if(thisPart < thatPart)
return -1;
if(thisPart > thatPart)
return 1;
}
return 0;
}
@Override
public boolean equals(Object that) {
if (this == that) return true;
if (that == null) return false;
if (this.getClass() != that.getClass()) return false;
return this.compareTo((UpdateManager.Version) that) == 0;
}
}
} }

View file

@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -58,6 +59,7 @@ public class LGUtil {
} }
return false; return false;
} }
if (!isAan(lampBlock)) { if (!isAan(lampBlock)) {
final Block neighbor = getNeighbor(lampBlock); final Block neighbor = getNeighbor(lampBlock);
if (neighbor != null) { if (neighbor != null) {
@ -97,8 +99,9 @@ public class LGUtil {
} }
return false; return false;
} }
if (isAan(lampBlock)) { if (isAan(lampBlock)) {
lampBlock.setType(Objects.requireNonNull(Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[0]))); lampBlock.setType(Objects.requireNonNull(Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[1])));
return true; return true;
} }
return false; return false;
@ -250,15 +253,18 @@ public class LGUtil {
} }
private static boolean isAan(Block lamp) { private static boolean isAan(Block lamp) {
return ((nieuweVersie) && (Objects.requireNonNull(getAsString(getBlockData(lamp))).contains("lit=true"))) || ((!nieuweVersie) && (lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[1]))); if (nieuweVersie) {
return getAsString(getBlockData(lamp)).contains("lit=true");
} else {
return lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[0]);
}
} }
private static boolean isLamp(Block lamp) { private static boolean isLamp(Block lamp) {
if (nieuweVersie) { if (nieuweVersie) {
return lamp.getType() == XMaterial.REDSTONE_LAMP.parseMaterial(); return lamp.getType() == XMaterial.REDSTONE_LAMP.parseMaterial();
} else { } else {
return lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[1]) return Arrays.asList(XMaterial.REDSTONE_LAMP.getLegacy()).contains(lamp.getType().name());
|| lamp.getType() == Material.matchMaterial(XMaterial.REDSTONE_LAMP.getLegacy()[0]);
} }
} }

View file

@ -3,7 +3,13 @@ package nl.sbdeveloper.themeparkplus.util;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -14,28 +20,29 @@ import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Objects;
/** /**
* License class for SBDevelopment * License class for SBDevelopment
* *
* v1.3 - Changed in 03-03-2020 * v1.6 - Changed on 06-08-2020
* *
* @author Stijn [SBDeveloper] * @author Stijn [SBDeveloper]
* @since 23-12-2019 * @since 23-12-2019
*/ */
public class License { public class License implements Listener {
/* /*
This file is part of ActionFoto. This file is part of ThemeParkRidecountAddon.
Copyright (c) 2018-2020 SBDevelopment - All Rights Reserved Copyright (c) 2018-2020 SBDevelopment - All Rights Reserved
Unauthorized copying of this file, via any medium is strictly prohibited Unauthorized copying of this file, via any medium is strictly prohibited
Proprietary and confidential Proprietary and confidential
Written by Stijn Bannink <stijnbannink23@gmail.com>, January 2020 Written by Stijn Bannink <stijnbannink23@gmail.com>, January 2020
*/ */
private Plugin plugin; private JavaPlugin plugin; // The plugin instance
private String license; private String license; // The license code
private String prefix; private String prefix; // The correct prefix for this plugin
@Nullable private String invalidReason; // The reason the license is invalid, if null it's not invalid!
@Nullable private static Boolean valid; // If true, it's valid, if false, it's not valid, if null it's not checked!
/** /**
* Construct a new license * Construct a new license
@ -43,176 +50,158 @@ public class License {
* @param prefix The prefix, like TPP or AF * @param prefix The prefix, like TPP or AF
* @param license The license from the config * @param license The license from the config
*/ */
public License(Plugin plugin, String prefix, String license) { public License(JavaPlugin plugin, String prefix, String license) {
this.prefix = prefix; this.prefix = prefix;
this.plugin = plugin; this.plugin = plugin;
this.license = license; this.license = license;
startTimer(); Bukkit.getPluginManager().registerEvents(this, plugin);
validateLicense();
} }
private void startTimer() { @EventHandler
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> { public void onJoin(PlayerJoinEvent e) {
if (!validateLicense()) { if (this.invalidReason == null) return;
Bukkit.getLogger().severe("[" + prefix + "] License is incorrect!");
} Player p = e.getPlayer();
}, 0, 20 * 60 * 60); if (p.isOp() || p.hasPermission("sbd.licensemessages")) {
Bukkit.getScheduler().runTaskLater(this.plugin, () -> p.sendMessage(ChatColor.GOLD + "[" + ChatColor.RED + this.plugin.getName() + ChatColor.GOLD + "] " + ChatColor.RED + "The license is incorrect! Reason: " + ChatColor.GOLD + this.invalidReason), 3 * 20L /* 3 sec */);
}
} }
/** /**
* Check a license * Check a license
* *
* @return true/false
*/ */
private boolean validateLicense() { private void validateLicense() {
//STEP 1: Check prefix
if (!this.license.split("-")[0].contains(this.prefix)) {
disable("You used the wrong license for this product.");
return;
}
//STEP 2: Send license request
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/" + this.license; String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/" + this.license;
@Nullable JsonObject response;
@Nullable JsonObject res;
try { try {
res = sendGETRequestJSON(url); response = sendGETRequestJSON(url);
} catch (IOException e) { } catch (IOException e) {
disable("GET_request_error"); disable("Couldn't send the request.");
return false; return;
} }
if (res == null) { if (response == null) {
disable("GET_request_error_2"); disable("Couldn't send the request.");
return false; return;
} }
JsonObject dat = res.get("data").getAsJsonObject(); JsonObject dataObject = response.get("data").getAsJsonObject();
int stat = dat.get("status").getAsInt(); //STEP 3: Check status
if (stat == 404) { switch(dataObject.get("status").getAsString()) {
disable("status_404_error");
return false;
}
if (dat.get("licenseKey").isJsonNull()) {
disable("license_null_error");
return false;
}
if (!dat.get("licenseKey").getAsString().split("-")[0].contains(prefix)) {
disable("prefix_error");
return false;
}
switch(dat.get("status").getAsString()) {
case "2": case "2":
//activate? //Delivered -> Try to activate (double check timesActivated)
break; break;
case "3": case "3":
//it's good //Activated!
break; break;
default: default:
disable("status_error"); disable("Your license has a wrong status.");
return false; return;
} }
//Not activated? Activate it! //STEP 4: Check times activated, and if not activated, activate.
if (dat.get("timesActivated").isJsonNull() || dat.get("timesActivated").getAsString().equalsIgnoreCase("0")) { if (dataObject.get("timesActivated").isJsonNull() || dataObject.get("timesActivated").getAsString().equalsIgnoreCase("0")) {
return activate(); activate();
return;
} }
if (dat.get("expiresAt").isJsonNull()) { //STEP 5: Check expire date
disable("null_error"); if (dataObject.get("expiresAt").isJsonNull()) {
return false; disable("Your license has no expire date.");
return;
} }
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date; Date date;
try { try {
date = format.parse(dat.get("expiresAt").getAsString()); date = format.parse(dataObject.get("expiresAt").getAsString());
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
disable("null_error"); disable("Your license has a wrong expire date.");
return false; return;
} }
if (!(Objects.requireNonNull(date).after(new Date()))) { if (date == null) {
disable("expired_error"); disable("Your license has a wrong expire date.");
return false; return;
} }
if (!dat.get("ipcheck").getAsBoolean()) { if (!(date.after(new Date()))) {
disable("ip_error"); disable("Your license has expired.");
return false; return;
} }
if (dat.get("port").isJsonNull()) { //STEP 6: Check IP and port.
disable("null_error"); if (!dataObject.get("ipcheck").getAsBoolean()) {
return false; disable("Your license has been used with another IP. Update it in our Discord.");
return;
} }
try { if (dataObject.get("port").isJsonNull()) {
int por = dat.get("port").getAsInt(); disable("Your license has no port.");
if (por != Bukkit.getServer().getPort()) { return;
disable("port_error");
return false;
}
} catch(NumberFormatException e) {
disable("null_error");
return false;
} }
return true; String por = dataObject.get("port").getAsString();
if (!checkPortValue(Bukkit.getServer().getPort(), por)) {
disable("Your license has been used with another Port. Update it in our Discord.");
return;
}
valid = true;
} }
/** /**
* Activate the license (private) * Activate the license
* *
* @return true/false
*/ */
private boolean activate() { private void activate() {
//STEP 1: Send license activate request
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort(); String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort();
@Nullable JsonObject response;
@Nullable JsonObject res;
try { try {
res = sendGETRequestJSON(url); response = sendGETRequestJSON(url);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); disable("Couldn't send the activate request.");
disable("GET_request_error"); return;
return false;
} }
if (res == null) { if (response == null) {
disable("GET_request_error_2"); disable("Couldn't send the activate request.");
return false; return;
} }
JsonObject dat = res.get("data").getAsJsonObject(); JsonObject dataObject = response.get("data").getAsJsonObject();
int stat = dat.get("status").getAsInt(); //STEP 2: Check status
if (stat == 404) { switch(dataObject.get("status").getAsString()) {
disable("status_404_error");
return false;
}
if (dat.get("licenseKey").isJsonNull()) {
disable("license_null_error");
return false;
}
if (!dat.get("licenseKey").getAsString().split("-")[0].contains(prefix)) {
disable("prefix_error");
return false;
}
switch(dat.get("status").getAsString()) {
case "2": case "2":
//activate? //Delivered -> STILL NOT ACTIVATED?! -> Double check
break; break;
case "3": case "3":
//it's good //Activated!
break; break;
default: default:
disable("status_error"); disable("Your license has a wrong status.");
return false; return;
} }
//Still not activated? Something is wrong... //STEP 3: Check times activated, and if still not activated, disable.
return !dat.get("timesActivated").isJsonNull() && !dat.get("timesActivated").getAsString().equalsIgnoreCase("0"); if (dataObject.get("timesActivated").isJsonNull() || dataObject.get("timesActivated").getAsString().equalsIgnoreCase("0")) {
disable("Couldn't activate the license.");
}
} }
/** /**
@ -221,10 +210,15 @@ public class License {
* @param reason The disabling reason * @param reason The disabling reason
*/ */
private void disable(String reason) { private void disable(String reason) {
Bukkit.getScheduler().runTask(plugin, () -> { this.invalidReason = reason;
Bukkit.getLogger().severe("[" + plugin.getName() + "] " + "Stopping plugin because licensing system check failed.");
Bukkit.getLogger().severe("[" + plugin.getName() + "] " + "Reason: " + reason); Bukkit.getScheduler().runTask(this.plugin, () -> {
Bukkit.getPluginManager().disablePlugin(plugin); valid = false;
Bukkit.getLogger().severe("[" + this.plugin.getName() + "] Stopping plugin because licensing system check failed.");
Bukkit.getLogger().severe("[" + this.plugin.getName() + "] Reason: " + reason);
Bukkit.getLogger().severe("[" + this.plugin.getName() + "] Contact the developer if you believe something is wrong on their side.");
Bukkit.getPluginManager().disablePlugin(this.plugin);
}); });
} }
@ -261,4 +255,51 @@ public class License {
return parser.parse(response.toString()).getAsJsonObject(); return parser.parse(response.toString()).getAsJsonObject();
} }
private boolean checkPortValue(int input, @NotNull String dataValue) {
//STEP 1: Check wildcard
if (dataValue.equals("*")) return true;
//STEP 2: Check if equals
try {
int dataVal = Integer.parseInt(dataValue);
return input == dataVal;
} catch (NumberFormatException ignored) {}
//STEP 3: Check if range
if (dataValue.contains("-")) {
String[] dataSplit = dataValue.split("-");
//STEP 3.1: Check if min or max is wildcard
if (dataSplit[0].equals("*") && !dataSplit[1].equals("*")) {
int max = Integer.parseInt(dataSplit[1]);
return input <= max;
} else if (dataSplit[1].equals("*") && !dataSplit[0].equals("*")) {
int min = Integer.parseInt(dataSplit[0]);
return min <= input;
} else {
try {
int min = Integer.parseInt(dataSplit[0]);
int max = Integer.parseInt(dataSplit[1]);
return (min <= input) && (input <= max);
} catch (NumberFormatException ex) {
return false;
}
}
}
//Else, invalid value
return false;
}
/**
* Check if the license is valid
*
* @return true -> VALID, false -> INVALID, null -> UNCHECKED
*/
@Nullable
public static Boolean isValid() {
return valid;
}
} }