Added DB Version

This commit is contained in:
netbenix 2020-11-20 11:31:01 +01:00
parent f985f543b4
commit f8c3d40786
2 changed files with 47 additions and 3 deletions

View file

@ -44,6 +44,7 @@ implements Listener
FileConfiguration cfg = this.getConfig();
NamespacedKey Nkey = new NamespacedKey(this, this.getDescription().getName());
public SQLHandler sql = new SQLHandler();
public static int DB_VER = 1;
public void onEnable() {
this.saveDefaultConfig();
registerEvents();
@ -195,7 +196,7 @@ implements Listener
return true;
}
//SQL REWORK
if(args[0].equalsIgnoreCase("settings")) {
if(!(sender instanceof Player)) {
sender.sendMessage("Command is only for Players!");
@ -233,7 +234,6 @@ implements Listener
try {
player_stat.save(PlayerStat);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

View file

@ -4,8 +4,11 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
import ml.codenoodles.lmve.Main;
import ml.codenoodles.lmve.other.ConsoleColor;
public class SQLHandler {
@ -152,13 +155,54 @@ public class SQLHandler {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
try { //Create PlayerSettings
String query = "CREATE TABLE tblPlayerSettings("
+ "ID INTEGER PRIMARY KEY," + "UUID TEXT NOT NULL,"
+ "ChatNotify INTEGER NOT NULL);";
Statement stmt = conn.createStatement();
stmt.execute(query);
System.out.println(ConsoleColor.PURPLE + "[LMVE]Player Settings Table created!" + ConsoleColor.RESET);
successfullQuerys++;
}catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
try { //Create Database Info
String query = "CREATE TABLE tblDatabaseInfo("
+ "ID INTEGER PRIMARY KEY,"
+ "CREATION_DATE TEXT NOT NULL,"
+ "VERSION INTEGER NOT NULL);";
Statement stmt = conn.createStatement();
stmt.execute(query);
System.out.println(ConsoleColor.PURPLE + "[LMVE]Database info table created!" + ConsoleColor.RESET);
successfullQuerys++;
}catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
try {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDateTime today = LocalDateTime.now();
String query = "INSERT INTO tblDatabaseInfo VALUES ("
+ "1,"
+ "'" + dtf.format(today) + "',"
+ Main.DB_VER + ");";
Statement stmt = conn.createStatement();
stmt.execute(query);
System.out.println(ConsoleColor.PURPLE + "[LMVE]Database info entry inserted!" + ConsoleColor.RESET);
successfullQuerys++;
}catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
try { //Close Connection
conn.close();
}catch(SQLException sqlEx) {
System.out.println("[LMVE]" + sqlEx.getMessage());
}
if(successfullQuerys == 5) {
if(successfullQuerys == 8) {
System.out.println(ConsoleColor.GREEN + "[LMVE]Default Database successfully created!" + ConsoleColor.RESET);
} else {
System.out.println(ConsoleColor.RED + "[LMVE]Oops.. Something went wrong during the creation of the Default Database." + ConsoleColor.RESET);