Compare commits

...

2 Commits

Author SHA1 Message Date
Dawson Hessler cc289f41ff Instead of deleting old files, make new one 2022-08-29 07:34:53 -04:00
Dawson Hessler bf5b81b750 1.8.2.1, fixed H2 and removed debug 2022-08-29 07:19:42 -04:00
11 changed files with 70 additions and 20 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Assembly</artifactId>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+2 -2
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Bukkit</artifactId>
@@ -56,7 +56,7 @@
<dependency>
<groupId>dev.brighten.antivpn</groupId>
<artifactId>Common</artifactId>
<version>1.8.2</version>
<version>1.8.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -69,7 +69,7 @@
<dependency>
<groupId>dev.brighten.antivpn</groupId>
<artifactId>Common</artifactId>
<version>1.8.2</version>
<version>1.8.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -68,7 +68,6 @@ public class BukkitListener extends VPNExecutor implements Listener {
@EventHandler
public void onListener(final PlayerLoginEvent event) {
//If they're exempt, don't check.
System.out.println(event.getAddress().getHostAddress() + ";" + event.getPlayer().getUniqueId() + ";" + event.getPlayer().getName());
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
+2 -2
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Bungee</artifactId>
@@ -50,7 +50,7 @@
<dependency>
<groupId>dev.brighten.antivpn</groupId>
<artifactId>Common</artifactId>
<version>1.8.2</version>
<version>1.8.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -63,7 +63,7 @@
<dependency>
<groupId>dev.brighten.antivpn</groupId>
<artifactId>Common</artifactId>
<version>1.8.2</version>
<version>1.8.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -1,11 +1,17 @@
package dev.brighten.antivpn.database.sql.utils;
import dev.brighten.antivpn.AntiVPN;
import org.h2.jdbc.JdbcSQLNonTransientConnectionException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class MySQL {
private static Connection conn;
@@ -36,13 +42,17 @@ public class MySQL {
}
}
private static boolean attemptedTwice = false;
public static void initH2() {
File dataFolder = new File(AntiVPN.getInstance().getPluginFolder(), "databases" + File.separator + "database");
File dataFolder = new File(AntiVPN.getInstance().getPluginFolder(), "databases");
File databaseFile = new File(dataFolder, "database");
try {
Class.forName("org.h2.Driver");
conn = new NonClosableConnection(DriverManager.getConnection ("jdbc:h2:file:" +
dataFolder.getAbsolutePath(),
AntiVPN.getInstance().getVpnConfig().getUsername(),AntiVPN.getInstance().getVpnConfig().getPassword()));
Constructor jdbcConnection = Class.forName("org.h2.jdbc.JdbcConnection")
.getConstructor(String.class, Properties.class, String.class, Object.class, boolean.class);
conn = new NonClosableConnection((Connection)jdbcConnection.newInstance("jdbc:h2:file:" +
databaseFile.getAbsolutePath(),
new Properties(), AntiVPN.getInstance().getVpnConfig().getUsername(),
AntiVPN.getInstance().getVpnConfig().getPassword(), false));
conn.setAutoCommit(true);
Query.use(conn);
AntiVPN.getInstance().getExecutor().log("Connection to H2 has been established.");
@@ -51,7 +61,47 @@ public class MySQL {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
AntiVPN.getInstance().getExecutor().log("No H2 library found!");
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) {
AntiVPN.getInstance().getExecutor().log("Java exception on initialize");
e.printStackTrace();
} catch(InvocationTargetException e) {
if(attemptedTwice) return;
if(e.getCause() instanceof JdbcSQLNonTransientConnectionException) {
File[] files = dataFolder.listFiles();
if(files == null) {
e.printStackTrace();
return;
}
File oldDbs = new File(dataFolder, "old");
boolean made = false;
if(!oldDbs.isDirectory()) {
made = oldDbs.mkdir();
} else made = true;
if(!made) {
throw new RuntimeException(String.format("Unable to upgrade H2 files since this application " +
"was unable to create a new directory %s (insufficient permissions?)!", oldDbs.getPath()));
}
AntiVPN.getInstance().getExecutor().log("Upgrading h2 files...");
for (File file : files) {
if(file.getName().endsWith(".db")) {
try {
Files.copy(file.toPath(), new File(oldDbs, file.getName()).toPath());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
if(file.delete()) {
AntiVPN.getInstance().getExecutor().log("Successfully deleted old " + file.getName());
} else throw new RuntimeException("Unable to delete old database file " + file.getName());
}
}
initH2();
} else e.printStackTrace();
}
attemptedTwice = true;
}
public static void use() {
@@ -70,6 +120,7 @@ public class MySQL {
} else conn.close();
conn = null;
}
attemptedTwice = false;
} catch (Exception e) {
e.printStackTrace();
}
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>AntiVPN</artifactId>
<groupId>dev.brighten.antivpn</groupId>
<version>1.8.2</version>
<version>1.8.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -33,7 +33,7 @@
<dependency>
<groupId>dev.brighten.antivpn</groupId>
<artifactId>Common</artifactId>
<version>1.8.2</version>
<version>1.8.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
+1 -1
View File
@@ -7,7 +7,7 @@
<groupId>dev.brighten.antivpn</groupId>
<artifactId>AntiVPN</artifactId>
<packaging>pom</packaging>
<version>1.8.2</version>
<version>1.8.2.1</version>
<modules>
<module>Common</module>