From f8c3d40786303aa8607163def2c7565063165f15 Mon Sep 17 00:00:00 2001 From: netbenix Date: Fri, 20 Nov 2020 11:31:01 +0100 Subject: [PATCH] Added DB Version --- src/ml/codenoodles/lmve/Main.java | 4 +- .../codenoodles/lmve/modules/SQLHandler.java | 46 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/ml/codenoodles/lmve/Main.java b/src/ml/codenoodles/lmve/Main.java index 95479db..0be2740 100644 --- a/src/ml/codenoodles/lmve/Main.java +++ b/src/ml/codenoodles/lmve/Main.java @@ -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(); } } diff --git a/src/ml/codenoodles/lmve/modules/SQLHandler.java b/src/ml/codenoodles/lmve/modules/SQLHandler.java index c1c7606..b54e869 100644 --- a/src/ml/codenoodles/lmve/modules/SQLHandler.java +++ b/src/ml/codenoodles/lmve/modules/SQLHandler.java @@ -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);