1.5.1 KauriVPN plugin.yml rename and System print fix

This commit is contained in:
Dawson Hessler
2021-11-04 08:27:32 -04:00
parent 2082ad6d8e
commit 5ba19b42f9
18 changed files with 49 additions and 32 deletions
@@ -50,7 +50,7 @@ public class AntiVPN {
switch(INSTANCE.config.getDatabaseType().toLowerCase()) {
case "mysql":
case "sql":{
System.out.println("Using databaseType MySQL...");
AntiVPN.getInstance().getExecutor().log("Using databaseType MySQL...");
INSTANCE.database = new MySqlVPN();
INSTANCE.database.init();
break;
@@ -58,11 +58,11 @@ public class AntiVPN {
case "mongo":
case "mongodb":
case "mongod": {
System.out.println("We currently do not support Mongo, but this is coming in future updates.");
AntiVPN.getInstance().getExecutor().log("We currently do not support Mongo, but this is coming in future updates.");
break;
}
default: {
System.out.println("Could not find database type \"" + INSTANCE.config.getDatabaseType() + "\". " +
AntiVPN.getInstance().getExecutor().log("Could not find database type \"" + INSTANCE.config.getDatabaseType() + "\". " +
"Options: [MySQL]");
break;
}
@@ -29,6 +29,8 @@ public abstract class VPNExecutor {
public abstract void shutdown();
public abstract void log(String log, Object... objects);
public boolean isWhitelisted(UUID uuid) {
return whitelisted.contains(uuid);
}
@@ -47,12 +49,12 @@ public abstract class VPNExecutor {
if(response.isSuccess()) {
AntiVPN.getInstance().getDatabase().cacheResponse(response);
} else {
System.out.println("Query to VPN API failed! Reason: " + response.getFailureReason());
log("Query to VPN API failed! Reason: " + response.getFailureReason());
}
return response;
} catch (JSONException | IOException e) {
System.out.println("Query to VPN API failed! Reason: Java Exception");
log("Query to VPN API failed! Reason: Java Exception");
e.printStackTrace();
}
}
@@ -76,12 +78,12 @@ public abstract class VPNExecutor {
if(response.isSuccess()) {
threadExecutor.execute(() -> AntiVPN.getInstance().getDatabase().cacheResponse(response));
} else {
System.out.println("Query to VPN API failed! Reason: " + response.getFailureReason());
log("Query to VPN API failed! Reason: " + response.getFailureReason());
}
return response;
} catch (JSONException | IOException e) {
System.out.println("Query to VPN API failed! Reason: Java Exception");
log("Query to VPN API failed! Reason: Java Exception");
e.printStackTrace();
}
}
@@ -188,20 +188,20 @@ public class MySqlVPN implements VPNDatabase {
public void init() {
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled())
return;
System.out.println("Initializing MySQL...");
AntiVPN.getInstance().getExecutor().log("Initializing MySQL...");
MySQL.init();
System.out.println("Creating tables...");
AntiVPN.getInstance().getExecutor().log("Creating tables...");
//Running check for old table types to update
oldTableCheck: {
Query.prepare("select `DATA_TYPE` from INFORMATION_SCHEMA.COLUMNS " +
"WHERE table_name = 'responses' AND COLUMN_NAME = 'isp';").execute(set -> {
if(set.getObject("DATA_TYPE").toString().contains("varchar")) {
System.out.println("Using old database format for storing responses! " +
AntiVPN.getInstance().getExecutor().log("Using old database format for storing responses! " +
"Dropping table and creating a new one...");
if(Query.prepare("drop table `responses`").execute() > 0) {
System.out.println("Successfully dropped table!");
AntiVPN.getInstance().getExecutor().log("Successfully dropped table!");
}
}
});
@@ -214,7 +214,7 @@ public class MySqlVPN implements VPNDatabase {
+ "`latitude` double, `longitude` double)").execute();
Query.prepare("create table if not exists `alerts` (`uuid` varchar(36) not null)").execute();
System.out.println("Creating indexes...");
AntiVPN.getInstance().getExecutor().log("Creating indexes...");
try {
// Ref:
// https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
@@ -22,10 +22,10 @@ public class MySQL {
Query.prepare("CREATE DATABASE IF NOT EXISTS `"
+ AntiVPN.getInstance().getConfig().getDatabaseName() + "`").execute();
Query.prepare("USE `" + AntiVPN.getInstance().getConfig().getDatabaseName() + "`").execute();
System.out.println("Connection to MySQL has been established.");
AntiVPN.getInstance().getExecutor().log("Connection to MySQL has been established.");
}
} catch (Exception e) {
System.out.println("Failed to load mysql: " + e.getMessage());
AntiVPN.getInstance().getExecutor().log("Failed to load mysql: " + e.getMessage());
e.printStackTrace();
}
}