Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Changes -> Added auto-updater
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Jul 20, 2023
1 parent f3f4d87 commit 295e28a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.cubeattack</groupId>
<artifactId>neoprotect</artifactId>
<version>1.1.9-Beta</version>
<version>1.2.0-Beta</version>
<packaging>jar</packaging>

<name>NeoProtect</name>
Expand All @@ -22,7 +22,7 @@
</scm>

<build>
<finalName>NeoProtect-v${version}</finalName>
<finalName>NeoProtect-v${project.version}</finalName>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
Expand Down Expand Up @@ -119,7 +119,7 @@
<dependency>
<groupId>com.github.CubeAttack</groupId>
<artifactId>EasyAPI</artifactId>
<version>7e81bb1c4d</version>
<version>b64df4e161</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/de/cubeattack/neoprotect/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}


10 changes: 1 addition & 9 deletions src/main/java/de/cubeattack/neoprotect/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,7 +31,6 @@ public class Core {
private final ConcurrentHashMap<KeepAliveResponseKey, Long> pingMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, Timestamp> timestampsMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, ArrayList<DebugPingResponse>> debugPingResponses = new ConcurrentHashMap<>();
private final ExecutorService executorService;

private VersionUtils.Result versionResult;
private boolean isDebugRunning = false;
Expand All @@ -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);
Expand Down Expand Up @@ -85,10 +81,6 @@ public NeoProtectPlugin getPlugin() {
return plugin;
}

public ExecutorService getExecutorService() {
return executorService;
}

public UUID[] getMaintainerUUID() {
return maintainerUUID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -99,6 +103,8 @@ public void testCredentials(){

this.setup = true;
setProxyProtocol(Config.isProxyProtocol());

Config.addAutoUpdater(!getPlan().equalsIgnoreCase("Basic"));
}

public boolean togglePanicMode(){
Expand Down Expand Up @@ -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(){
Expand Down

0 comments on commit 295e28a

Please sign in to comment.