From 295e28a5cc9881a032b02dc68692781d5bf647e5 Mon Sep 17 00:00:00 2001 From: EinfacheSache Date: Fri, 21 Jul 2023 01:51:15 +0200 Subject: [PATCH] Changes -> Added auto-updater --- pom.xml | 6 +++--- .../de/cubeattack/neoprotect/core/Config.java | 19 +++++++++++++++++++ .../de/cubeattack/neoprotect/core/Core.java | 10 +--------- .../core/request/RestAPIRequests.java | 10 ++++++++-- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 9e5bd40..3f11d87 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.cubeattack neoprotect - 1.1.9-Beta + 1.2.0-Beta jar NeoProtect @@ -22,7 +22,7 @@ - NeoProtect-v${version} + NeoProtect-v${project.version} clean package @@ -119,7 +119,7 @@ com.github.CubeAttack EasyAPI - 7e81bb1c4d + b64df4e161 io.netty diff --git a/src/main/java/de/cubeattack/neoprotect/core/Config.java b/src/main/java/de/cubeattack/neoprotect/core/Config.java index 8d3e924..5fc4bb0 100644 --- a/src/main/java/de/cubeattack/neoprotect/core/Config.java +++ b/src/main/java/de/cubeattack/neoprotect/core/Config.java @@ -12,11 +12,14 @@ public class Config { private static String BackendID; private static boolean updateIP; private static boolean debugMode; + private static boolean autoUpdater = true; + private static Core core; private static FileUtils fileUtils; public static void loadConfig(Core core, FileUtils config) { + Config.core = core; fileUtils = config; APIKey = config.getString("APIKey", ""); @@ -73,6 +76,10 @@ public static boolean isDebugMode() { return debugMode; } + public static boolean isAutoUpdater() { + return autoUpdater; + } + public static void setAPIKey(String key) { fileUtils.set("APIKey", key); fileUtils.save(); @@ -90,6 +97,18 @@ public static void setBackendID(String id) { fileUtils.save(); BackendID = id; } + + public static void addAutoUpdater(boolean activate) { + + if(!activate){ + fileUtils.remove("AutoUpdater"); + }else if (!fileUtils.getConfig().isSet("AutoUpdater")) { + fileUtils.getConfig().set("AutoUpdater", true); + } + + fileUtils.save(); + autoUpdater = fileUtils.getBoolean("AutoUpdater", true); + } } diff --git a/src/main/java/de/cubeattack/neoprotect/core/Core.java b/src/main/java/de/cubeattack/neoprotect/core/Core.java index 8792429..fac03d2 100644 --- a/src/main/java/de/cubeattack/neoprotect/core/Core.java +++ b/src/main/java/de/cubeattack/neoprotect/core/Core.java @@ -15,8 +15,6 @@ import java.util.Locale; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; @@ -33,7 +31,6 @@ public class Core { private final ConcurrentHashMap pingMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap timestampsMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap> debugPingResponses = new ConcurrentHashMap<>(); - private final ExecutorService executorService; private VersionUtils.Result versionResult; private boolean isDebugRunning = false; @@ -42,8 +39,7 @@ public Core(NeoProtectPlugin plugin) { LogManager.getLogger().setLogger(plugin.getLogger()); this.plugin = plugin; - this.executorService = Executors.newSingleThreadExecutor(); - this.versionResult = VersionUtils.checkVersion("NeoProtect", "NeoPlugin", "v" + plugin.getVersion()).message(); + this.versionResult = VersionUtils.checkVersion("NeoProtect", "NeoPlugin", "v" + plugin.getVersion(), false, null).message(); FileUtils config = new FileUtils(Core.class.getResourceAsStream("/config.yml"), "plugins/NeoProtect", "config.yml", false); FileUtils languageEN = new FileUtils(Core.class.getResourceAsStream("/language_en.properties"), "plugins/NeoProtect/languages", "language_en.properties", true); @@ -85,10 +81,6 @@ public NeoProtectPlugin getPlugin() { return plugin; } - public ExecutorService getExecutorService() { - return executorService; - } - public UUID[] getMaintainerUUID() { return maintainerUUID; } diff --git a/src/main/java/de/cubeattack/neoprotect/core/request/RestAPIRequests.java b/src/main/java/de/cubeattack/neoprotect/core/request/RestAPIRequests.java index 2dffacf..7d30eb8 100644 --- a/src/main/java/de/cubeattack/neoprotect/core/request/RestAPIRequests.java +++ b/src/main/java/de/cubeattack/neoprotect/core/request/RestAPIRequests.java @@ -65,6 +65,10 @@ private boolean isAttack(){ return rest.request(RequestType.GET_GAMESHIELD_ISUNDERATTACK, null, Config.getGameShieldID()).getResponseBody().equals("true"); } + public String getPlan(){ + return rest.request(RequestType.GET_GAMESHIELD_PLAN, null, Config.getGameShieldID()).getResponseBodyObject().getJSONObject("gameShieldPlan").getJSONObject("options").getString("name"); + } + private boolean updateBackend(RequestBody formBody){ return rest.request(RequestType.POST_GAMESHIELD_BACKEND_UPDATE, formBody, Config.getGameShieldID(), Config.getBackendID()).checkCode(200); } @@ -99,6 +103,8 @@ public void testCredentials(){ this.setup = true; setProxyProtocol(Config.isProxyProtocol()); + + Config.addAutoUpdater(!getPlan().equalsIgnoreCase("Basic")); } public boolean togglePanicMode(){ @@ -181,9 +187,9 @@ private void versionCheckSchedule(){ new Timer().schedule(new TimerTask() { @Override public void run() { - core.setVersionResult(VersionUtils.checkVersion("NeoProtect", "NeoPlugin", "v" + core.getPlugin().getVersion())); + core.setVersionResult(VersionUtils.checkVersion("NeoProtect", "NeoPlugin", "v" + core.getPlugin().getVersion(), Config.isAutoUpdater(), core.getPlugin().getPluginFile())); } - }, 1000 * 60 * 3, 1000 * 60 * 3); + }, 1000 * 15, 1000 * 60 * 3); } private void attackCheckSchedule(){