mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-17 03:51:27 +01:00
Don't fully shutdown the plugin when license verification fails
The goal here is to keep the plugin enabled and initialize the Core. This is needed for the `/craftaro license` command to work etc. Sadly this also means other plugins checking for the plugin being the (including the `/plugins` command), report the plugin as enabled and seemingly ready (Although the plugin's API is not).
This commit is contained in:
parent
1998fd7ff9
commit
3f89267e8e
@ -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() + ".");
|
||||
|
@ -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 <br>
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user