diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index aa69adc1..4e7ec863 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -233,10 +233,12 @@ public class SongodaCore { private void register(JavaPlugin plugin, int pluginID, String icon, String libraryVersion) { ProductVerificationStatus verificationStatus = ProductVerificationStatus.VERIFIED; - try { - verificationStatus = CraftaroProductVerification.getProductVerificationStatus(pluginID); - } catch (IOException ex) { - logger.log(Level.WARNING, "Error verifying plugin " + plugin.getName(), ex); + if (pluginID > 0) { + try { + verificationStatus = CraftaroProductVerification.getProductVerificationStatus(pluginID); + } catch (IOException ex) { + logger.log(Level.WARNING, "Error verifying plugin " + plugin.getName(), ex); + } } logger.info(getPrefix() + "Hooked " + plugin.getName() + "."); diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 18ebb42d..48e1b37e 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -1,10 +1,10 @@ package com.songoda.core; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.configuration.Config; import com.songoda.core.database.DataManagerAbstract; import com.songoda.core.locale.Locale; import com.songoda.core.utils.Metrics; -import com.songoda.core.utils.SongodaAuth; import com.songoda.core.verification.CraftaroProductVerification; import com.songoda.core.verification.ProductVerificationStatus; import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; @@ -18,15 +18,12 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -/** - * REMINDER: When converting plugins to use this, REMOVE METRICS
- * Must not have two instances of Metrics enabled! - */ public abstract class SongodaPlugin extends JavaPlugin { protected Locale locale; protected Config config = new Config(this); protected long dataLoadDelay = 20L; + private boolean licensePreventedPluginLoad = false; private boolean emergencyStop = false; static { @@ -101,19 +98,18 @@ public abstract class SongodaPlugin extends JavaPlugin { ChatColor.RED + "You do not have access to the " + getDescription().getName() + " plugin.\n" + ChatColor.YELLOW + "Please purchase a license at https://craftaro.com/\n" + ChatColor.YELLOW + "or set up your license\n" + - ChatColor.YELLOW + "License setup steps:\n" + - ChatColor.YELLOW + "Run the command '" + ChatColor.GOLD + "/craftaro license" + ChatColor.YELLOW + "' and follow the instructions\n" + + ChatColor.YELLOW + "And setup it up:\n" + + ChatColor.YELLOW + "Run the command " + ChatColor.GOLD + "/craftaro license" + ChatColor.YELLOW + " and follow the instructions\n" + ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - emergencyStop(); + this.licensePreventedPluginLoad = true; + SongodaCore.registerPlugin(this, CraftaroProductVerification.getProductId(), (CompatibleMaterial) null); return; } console.sendMessage(" "); // blank line to separate chatter console.sendMessage(ChatColor.GREEN + "============================="); - console.sendMessage(String.format("%s%s %s by %sCraftaro <3!", ChatColor.GRAY, - getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE)); - console.sendMessage(String.format("%sAction: %s%s%s...", ChatColor.GRAY, - ChatColor.GREEN, "Enabling", ChatColor.GRAY)); + console.sendMessage(String.format("%s%s %s by %sCraftaro <3!", ChatColor.GRAY, getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE)); + console.sendMessage(String.format("%sAction: %s%s%s...", ChatColor.GRAY, ChatColor.GREEN, "Enabling", ChatColor.GRAY)); try { this.locale = Locale.loadDefaultLocale(this, "en_US"); @@ -151,7 +147,7 @@ public abstract class SongodaPlugin extends JavaPlugin { @Override public final void onDisable() { - if (this.emergencyStop) { + if (this.emergencyStop || this.licensePreventedPluginLoad) { return; } diff --git a/Core/src/main/java/com/songoda/core/verification/CraftaroProductVerification.java b/Core/src/main/java/com/songoda/core/verification/CraftaroProductVerification.java index 649b9026..c2943ede 100644 --- a/Core/src/main/java/com/songoda/core/verification/CraftaroProductVerification.java +++ b/Core/src/main/java/com/songoda/core/verification/CraftaroProductVerification.java @@ -28,13 +28,13 @@ public final class CraftaroProductVerification { private static @Nullable VerificationRequest verificationRequest; public static ProductVerificationStatus getOwnProductVerificationStatus() { - final String productId = "%%__PRODUCT_ID__%%"; - if (!productId.matches("[0-9]+")) { + final int productId = getProductId(); + if (productId <= 0) { return ProductVerificationStatus.VERIFIED; } try { - return getProductVerificationStatus(Integer.parseInt(productId)); + return getProductVerificationStatus(productId); } catch (IOException ex) { SongodaCore.getLogger().log(Level.WARNING, "Failed to fetch product verification status", ex); return ProductVerificationStatus.VERIFIED; @@ -147,6 +147,15 @@ public final class CraftaroProductVerification { return new AsyncTokenAcquisitionFlow(uri, asyncTokenRefreshWorkflowFuture); } + public static int getProductId() { + final String productId = "%%__PRODUCT_ID__%%"; + if (!productId.matches("[0-9]+")) { + return -1; + } + + return Integer.parseInt(productId); + } + private static @Nullable VerificationToken refreshVerificationToken(VerificationToken token) throws IOException { JsonObject reqBody = new JsonObject(); reqBody.addProperty("access_token", token.accessToken); @@ -179,7 +188,6 @@ public final class CraftaroProductVerification { } private static void tryDeleteTokenFile() { - try { VerificationTokenFileManager.deleteVerificationTokenFile(); } catch (IOException ex) {