diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0d5a12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +.idea/ +little-minecraft-vanilla-extension.iml \ No newline at end of file diff --git a/bin/ml/codenoodles/lmve/Main.class b/bin/ml/codenoodles/lmve/Main.class deleted file mode 100644 index 58b9af3..0000000 Binary files a/bin/ml/codenoodles/lmve/Main.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/CustomRecipes.class b/bin/ml/codenoodles/lmve/modules/CustomRecipes.class deleted file mode 100644 index 6ba81cf..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/CustomRecipes.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/EnragedMobs.class b/bin/ml/codenoodles/lmve/modules/EnragedMobs.class deleted file mode 100644 index d76870d..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/EnragedMobs.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/Hardcore.class b/bin/ml/codenoodles/lmve/modules/Hardcore.class deleted file mode 100644 index 7fbc2f2..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/Hardcore.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/Leaderboard.class b/bin/ml/codenoodles/lmve/modules/Leaderboard.class deleted file mode 100644 index 604032a..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/Leaderboard.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/Messages.class b/bin/ml/codenoodles/lmve/modules/Messages.class deleted file mode 100644 index bcb978a..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/Messages.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/NetherPortal.class b/bin/ml/codenoodles/lmve/modules/NetherPortal.class deleted file mode 100644 index f93cd3d..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/NetherPortal.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/PlayerHeads.class b/bin/ml/codenoodles/lmve/modules/PlayerHeads.class deleted file mode 100644 index 5765b56..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/PlayerHeads.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/PlayerList.class b/bin/ml/codenoodles/lmve/modules/PlayerList.class deleted file mode 100644 index 7866517..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/PlayerList.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class b/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class deleted file mode 100644 index b9871bc..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class b/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class deleted file mode 100644 index 41065f1..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/SQLHandler.class b/bin/ml/codenoodles/lmve/modules/SQLHandler.class deleted file mode 100644 index 4cc8978..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/SQLHandler.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/SleepVoteSystem.class b/bin/ml/codenoodles/lmve/modules/SleepVoteSystem.class deleted file mode 100644 index 41766d9..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/SleepVoteSystem.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/StatCounter.class b/bin/ml/codenoodles/lmve/modules/StatCounter.class deleted file mode 100644 index f5b9110..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/StatCounter.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/modules/UUIDReference.class b/bin/ml/codenoodles/lmve/modules/UUIDReference.class deleted file mode 100644 index 61a4989..0000000 Binary files a/bin/ml/codenoodles/lmve/modules/UUIDReference.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/other/ConsoleColor.class b/bin/ml/codenoodles/lmve/other/ConsoleColor.class deleted file mode 100644 index af096ed..0000000 Binary files a/bin/ml/codenoodles/lmve/other/ConsoleColor.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/other/GlobalMute.class b/bin/ml/codenoodles/lmve/other/GlobalMute.class deleted file mode 100644 index 2610277..0000000 Binary files a/bin/ml/codenoodles/lmve/other/GlobalMute.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/other/RemoveVanillaRecipes.class b/bin/ml/codenoodles/lmve/other/RemoveVanillaRecipes.class deleted file mode 100644 index 41d86b9..0000000 Binary files a/bin/ml/codenoodles/lmve/other/RemoveVanillaRecipes.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/other/WelcomeBossBar$1.class b/bin/ml/codenoodles/lmve/other/WelcomeBossBar$1.class deleted file mode 100644 index 9fe22bc..0000000 Binary files a/bin/ml/codenoodles/lmve/other/WelcomeBossBar$1.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/other/WelcomeBossBar.class b/bin/ml/codenoodles/lmve/other/WelcomeBossBar.class deleted file mode 100644 index d915526..0000000 Binary files a/bin/ml/codenoodles/lmve/other/WelcomeBossBar.class and /dev/null differ diff --git a/bin/ml/codenoodles/lmve/sounds/ChatNotification.class b/bin/ml/codenoodles/lmve/sounds/ChatNotification.class deleted file mode 100644 index 45052f9..0000000 Binary files a/bin/ml/codenoodles/lmve/sounds/ChatNotification.class and /dev/null differ diff --git a/src/ml/codenoodles/lmve/Main.java b/src/ml/codenoodles/lmve/Main.java index a0f7287..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(); @@ -175,7 +176,7 @@ implements Listener sender.sendMessage(ChatColor.GRAY + "================"); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "LMVE LEADERBOARD INFO"); sender.sendMessage(ChatColor.YELLOW + "Usage : " + ChatColor.AQUA + "/lmve leaderboard "); - sender.sendMessage(ChatColor.YELLOW + "Categorys: "); + sender.sendMessage(ChatColor.YELLOW + "Categories: "); sender.sendMessage(ChatColor.RED + "time-played"); sender.sendMessage(ChatColor.RED + "deaths"); sender.sendMessage(ChatColor.RED + "damage-taken"); @@ -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/Leaderboard.java b/src/ml/codenoodles/lmve/modules/Leaderboard.java index 30bdccc..4d43abe 100644 --- a/src/ml/codenoodles/lmve/modules/Leaderboard.java +++ b/src/ml/codenoodles/lmve/modules/Leaderboard.java @@ -1,6 +1,5 @@ package ml.codenoodles.lmve.modules; -import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -10,8 +9,6 @@ import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import ml.codenoodles.lmve.Main; import ml.codenoodles.lmve.other.ConsoleColor; @@ -40,7 +37,7 @@ public class Leaderboard { } for(int i = 1; i <= totalPlayers; i++) { try { //Get Players - String query = "SELECT Name AS playerName, UUID AS uuid FROM tblPlayers WHERE ID = ?"; + String query = "SELECT Name AS playerName, UUID AS uuid FROM tblPlayerStats WHERE ID = ?"; PreparedStatement pst = conn.prepareStatement(query); pst.setLong(1, i); ResultSet rs = pst.executeQuery(); @@ -57,15 +54,6 @@ public class Leaderboard { float value[] = new float[playerAmount]; sender.sendMessage(ChatColor.GRAY + "=====[ LEADERBOARD ]====="); switch(args[1]){ - case "time-played":{ - sender.sendMessage(ChatColor.GRAY + "Category: " + ChatColor.AQUA + "Time Played" + ChatColor.GRAY + "(in hours)"); - for(int i = 1; i < playerAmount; i++) { - File playerFile = new File(main.getDataFolder() + "/Players", uuid[i] + ".yml"); - FileConfiguration playerStat = YamlConfiguration.loadConfiguration(playerFile); - value[i] = playerStat.getInt(uuid[i] + ".TimePlayed"); - } - break; - } case "deaths":{ sender.sendMessage(ChatColor.GRAY + "Category: " + ChatColor.AQUA + "Deaths"); for(int i = 1; i <= playerAmount; i++) { diff --git a/src/ml/codenoodles/lmve/modules/PlayerList.java b/src/ml/codenoodles/lmve/modules/PlayerList.java index d27526a..a7a2eca 100644 --- a/src/ml/codenoodles/lmve/modules/PlayerList.java +++ b/src/ml/codenoodles/lmve/modules/PlayerList.java @@ -20,7 +20,7 @@ public class PlayerList implements Listener{ public int getAmount() { int totalPlayers; Connection conn; - String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "\\" + "Players.db"; + String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; try { //Try Connection conn = DriverManager.getConnection(path); }catch(SQLException sqlEx) { diff --git a/src/ml/codenoodles/lmve/modules/PlayerStatistics.java b/src/ml/codenoodles/lmve/modules/PlayerStatistics.java index 0676223..ed4711c 100644 --- a/src/ml/codenoodles/lmve/modules/PlayerStatistics.java +++ b/src/ml/codenoodles/lmve/modules/PlayerStatistics.java @@ -1,7 +1,5 @@ package ml.codenoodles.lmve.modules; -import java.io.File; -import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -14,10 +12,7 @@ import java.time.format.DateTimeFormatter; import java.util.UUID; import org.bukkit.ChatColor; -import org.bukkit.Statistic; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -111,7 +106,7 @@ public class PlayerStatistics implements Listener{ System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } - + // TODO Add Entry for PlayerSettings if(!existsPlayerStats) { try { //Create default entry for tblPlayerStats String query = "INSERT INTO tblPlayerStats VALUES (" @@ -171,7 +166,7 @@ public class PlayerStatistics implements Listener{ if(!existsPlayerFKills) { try { //Create default entry for tblPlayerFKills - String query = "INSERT InTO tblPlayerFKills VALUES (" + String query = "INSERT INTO tblPlayerFKills VALUES (" + (totalPlayers + 1) + "," + "'" + uuid.toString() + "',"; for(int i = 0; i < 23; i++) { @@ -201,18 +196,18 @@ public class PlayerStatistics implements Listener{ UUID player_uuid = e.getPlayer().getUniqueId(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); - File playerStats = new File(main.getDataFolder() + "/Players", player_uuid + ".yml"); - FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats); Connection conn = null; String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; - String query; - player_stat.set(player_uuid + ".LastJoined", dtf.format(now)); + String query = "UPDATE tblPlayerStats SET LastJoined = '" + dtf.format(now) + "' WHERE UUID ='" + player_uuid.toString() + "';"; + try { - player_stat.save(playerStats); - } catch (IOException ex) { - // TODO Auto-generated catch block - ex.printStackTrace(); - } + conn = DriverManager.getConnection(dbPath); + Statement stmt = conn.createStatement(); + stmt.execute(query); + conn.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } } @EventHandler @@ -223,51 +218,20 @@ public class PlayerStatistics implements Listener{ Connection conn = null; String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; String query = "UPDATE tblPlayerStats SET " - + "(DisplayName = " + p.getName() + ")," - + "(Health = " + p.getHealth() + ")," - + "(World = " + p.getWorld().getName() + "),"; + + "Displayname = '" + p.getName() + "'," + + "Health = '" + p.getHealth() + "'," + + "World = '" + p.getWorld().getName() + "' WHERE UUID = '" + uuid.toString() + "';"; try { conn = DriverManager.getConnection(dbPath); Statement stmt = conn.createStatement(); stmt.execute(query); + conn.close(); }catch(SQLException sqlEx) { System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } } - - //NEEDS UPDATE TO SQL - /*@EventHandler(priority = EventPriority.LOW) - private void checkName(PlayerJoinEvent e) throws IOException { - UUID uuid = e.getPlayer().getUniqueId(); - File pStatFile = new File(main.getDataFolder() + "/Players", uuid + ".yml"); - FileConfiguration pStat = YamlConfiguration.loadConfiguration(pStatFile); - if(pStat.getString(uuid + ".DisplayName") != e.getPlayer().getName()) { - String oldName = pStat.getString(uuid + ".DisplayName"); - String newName = e.getPlayer().getName(); - pStat.set(uuid + ".DisplayName", newName); - - File uRefFile = new File(main.getDataFolder(), "uuid_reference.yml"); - FileConfiguration uRef = YamlConfiguration.loadConfiguration(uRefFile); - uRef.set(oldName, null); - uRef.set(newName, uuid.toString()); - try { - pStat.save(pStatFile); - uRef.save(uRefFile); - } catch (IOException ex) { - // TODO Auto-generated catch block - ex.printStackTrace(); - } - - Path pListPath = Paths.get(main.getDataFolder() + "/playerList.txt"); - Charset charset = StandardCharsets.UTF_8; - String content = new String(Files.readAllBytes(pListPath), charset); - content = content.replaceAll(("\\b" + oldName + "\\b"), newName); - Files.write(pListPath, content.getBytes(charset)); - } - }*/ - - + public void outputStats(CommandSender sender, UUID uuid) { Connection conn; @@ -395,6 +359,11 @@ public class PlayerStatistics implements Listener{ }catch(SQLException sqlEx) { System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } + try { + conn.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } sender.sendMessage(ChatColor.GRAY + "================"); } diff --git a/src/ml/codenoodles/lmve/modules/SQLHandler.java b/src/ml/codenoodles/lmve/modules/SQLHandler.java index 6e308d5..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 { @@ -39,16 +42,20 @@ public class SQLHandler { break; } } - - String path = "jdbc:sqlite:" + dbPath + "/" + "Players.db"; String query = "UPDATE " + tableName + " SET " + entity + " = ( " + entity + " + 1) WHERE UUID ='" + uuid.toString() + "';"; try { //Try connection and exec query - conn = DriverManager.getConnection(path); + conn = DriverManager.getConnection(dbPath); Statement stmt = conn.createStatement(); stmt.execute(query); }catch(SQLException sqlEx) { System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } + + try { //Try connection close + conn.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } } @@ -148,18 +155,60 @@ 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); } } + //TODO Add DB Update Queries } diff --git a/src/ml/codenoodles/lmve/modules/StatCounter.java b/src/ml/codenoodles/lmve/modules/StatCounter.java index ba2f5a6..d60daf5 100644 --- a/src/ml/codenoodles/lmve/modules/StatCounter.java +++ b/src/ml/codenoodles/lmve/modules/StatCounter.java @@ -37,7 +37,6 @@ public class StatCounter implements Listener{ Player p = (Player) e.getEntity(); if(p.getGameMode() == GameMode.SURVIVAL || p.getGameMode() == GameMode.ADVENTURE) { UUID uuid = p.getUniqueId(); - Connection conn = null; String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; String query = "UPDATE tblPlayerStats SET DamageTaken = (DamageTaken + " + e.getDamage() + ") WHERE UUID = " + uuid.toString() + "';"; @@ -49,6 +48,11 @@ public class StatCounter implements Listener{ System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } + try { + conn.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } } } } @@ -65,7 +69,6 @@ public class StatCounter implements Listener{ try { player_stat.save(playerStats); } catch (IOException ex) { - // TODO Auto-generated catch block ex.printStackTrace(); } }