Merge branch 'dev'

This commit is contained in:
netbenix 2020-11-20 11:36:07 +01:00
commit 50a0d5941a
28 changed files with 87 additions and 75 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
bin/
.idea/
little-minecraft-vanilla-extension.iml

Binary file not shown.

View file

@ -44,6 +44,7 @@ implements Listener
FileConfiguration cfg = this.getConfig(); FileConfiguration cfg = this.getConfig();
NamespacedKey Nkey = new NamespacedKey(this, this.getDescription().getName()); NamespacedKey Nkey = new NamespacedKey(this, this.getDescription().getName());
public SQLHandler sql = new SQLHandler(); public SQLHandler sql = new SQLHandler();
public static int DB_VER = 1;
public void onEnable() { public void onEnable() {
this.saveDefaultConfig(); this.saveDefaultConfig();
registerEvents(); registerEvents();
@ -175,7 +176,7 @@ implements Listener
sender.sendMessage(ChatColor.GRAY + "================"); sender.sendMessage(ChatColor.GRAY + "================");
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "LMVE LEADERBOARD INFO"); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "LMVE LEADERBOARD INFO");
sender.sendMessage(ChatColor.YELLOW + "Usage : " + ChatColor.AQUA + "/lmve leaderboard <category>"); sender.sendMessage(ChatColor.YELLOW + "Usage : " + ChatColor.AQUA + "/lmve leaderboard <category>");
sender.sendMessage(ChatColor.YELLOW + "Categorys: "); sender.sendMessage(ChatColor.YELLOW + "Categories: ");
sender.sendMessage(ChatColor.RED + "time-played"); sender.sendMessage(ChatColor.RED + "time-played");
sender.sendMessage(ChatColor.RED + "deaths"); sender.sendMessage(ChatColor.RED + "deaths");
sender.sendMessage(ChatColor.RED + "damage-taken"); sender.sendMessage(ChatColor.RED + "damage-taken");
@ -195,7 +196,7 @@ implements Listener
return true; return true;
} }
//SQL REWORK
if(args[0].equalsIgnoreCase("settings")) { if(args[0].equalsIgnoreCase("settings")) {
if(!(sender instanceof Player)) { if(!(sender instanceof Player)) {
sender.sendMessage("Command is only for Players!"); sender.sendMessage("Command is only for Players!");
@ -233,7 +234,6 @@ implements Listener
try { try {
player_stat.save(PlayerStat); player_stat.save(PlayerStat);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }

View file

@ -1,6 +1,5 @@
package ml.codenoodles.lmve.modules; package ml.codenoodles.lmve.modules;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -10,8 +9,6 @@ import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; 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.Main;
import ml.codenoodles.lmve.other.ConsoleColor; import ml.codenoodles.lmve.other.ConsoleColor;
@ -40,7 +37,7 @@ public class Leaderboard {
} }
for(int i = 1; i <= totalPlayers; i++) { for(int i = 1; i <= totalPlayers; i++) {
try { //Get Players 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); PreparedStatement pst = conn.prepareStatement(query);
pst.setLong(1, i); pst.setLong(1, i);
ResultSet rs = pst.executeQuery(); ResultSet rs = pst.executeQuery();
@ -57,15 +54,6 @@ public class Leaderboard {
float value[] = new float[playerAmount]; float value[] = new float[playerAmount];
sender.sendMessage(ChatColor.GRAY + "=====[ LEADERBOARD ]====="); sender.sendMessage(ChatColor.GRAY + "=====[ LEADERBOARD ]=====");
switch(args[1]){ 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":{ case "deaths":{
sender.sendMessage(ChatColor.GRAY + "Category: " + ChatColor.AQUA + "Deaths"); sender.sendMessage(ChatColor.GRAY + "Category: " + ChatColor.AQUA + "Deaths");
for(int i = 1; i <= playerAmount; i++) { for(int i = 1; i <= playerAmount; i++) {

View file

@ -20,7 +20,7 @@ public class PlayerList implements Listener{
public int getAmount() { public int getAmount() {
int totalPlayers; int totalPlayers;
Connection conn; Connection conn;
String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "\\" + "Players.db"; String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db";
try { //Try Connection try { //Try Connection
conn = DriverManager.getConnection(path); conn = DriverManager.getConnection(path);
}catch(SQLException sqlEx) { }catch(SQLException sqlEx) {

View file

@ -1,7 +1,5 @@
package ml.codenoodles.lmve.modules; package ml.codenoodles.lmve.modules;
import java.io.File;
import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -14,10 +12,7 @@ import java.time.format.DateTimeFormatter;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.command.CommandSender; 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.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -111,7 +106,7 @@ public class PlayerStatistics implements Listener{
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
} }
// TODO Add Entry for PlayerSettings
if(!existsPlayerStats) { if(!existsPlayerStats) {
try { //Create default entry for tblPlayerStats try { //Create default entry for tblPlayerStats
String query = "INSERT INTO tblPlayerStats VALUES (" String query = "INSERT INTO tblPlayerStats VALUES ("
@ -171,7 +166,7 @@ public class PlayerStatistics implements Listener{
if(!existsPlayerFKills) { if(!existsPlayerFKills) {
try { //Create default entry for tblPlayerFKills try { //Create default entry for tblPlayerFKills
String query = "INSERT InTO tblPlayerFKills VALUES (" String query = "INSERT INTO tblPlayerFKills VALUES ("
+ (totalPlayers + 1) + "," + (totalPlayers + 1) + ","
+ "'" + uuid.toString() + "',"; + "'" + uuid.toString() + "',";
for(int i = 0; i < 23; i++) { for(int i = 0; i < 23; i++) {
@ -201,17 +196,17 @@ public class PlayerStatistics implements Listener{
UUID player_uuid = e.getPlayer().getUniqueId(); UUID player_uuid = e.getPlayer().getUniqueId();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
File playerStats = new File(main.getDataFolder() + "/Players", player_uuid + ".yml");
FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats);
Connection conn = null; Connection conn = null;
String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db";
String query; String query = "UPDATE tblPlayerStats SET LastJoined = '" + dtf.format(now) + "' WHERE UUID ='" + player_uuid.toString() + "';";
player_stat.set(player_uuid + ".LastJoined", dtf.format(now));
try { try {
player_stat.save(playerStats); conn = DriverManager.getConnection(dbPath);
} catch (IOException ex) { Statement stmt = conn.createStatement();
// TODO Auto-generated catch block stmt.execute(query);
ex.printStackTrace(); conn.close();
}catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
} }
} }
@ -223,51 +218,20 @@ public class PlayerStatistics implements Listener{
Connection conn = null; Connection conn = null;
String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db";
String query = "UPDATE tblPlayerStats SET " String query = "UPDATE tblPlayerStats SET "
+ "(DisplayName = " + p.getName() + ")," + "Displayname = '" + p.getName() + "',"
+ "(Health = " + p.getHealth() + ")," + "Health = '" + p.getHealth() + "',"
+ "(World = " + p.getWorld().getName() + "),"; + "World = '" + p.getWorld().getName() + "' WHERE UUID = '" + uuid.toString() + "';";
try { try {
conn = DriverManager.getConnection(dbPath); conn = DriverManager.getConnection(dbPath);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute(query); stmt.execute(query);
conn.close();
}catch(SQLException sqlEx) { }catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); 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) { public void outputStats(CommandSender sender, UUID uuid) {
Connection conn; Connection conn;
@ -395,6 +359,11 @@ public class PlayerStatistics implements Listener{
}catch(SQLException sqlEx) { }catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); 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 + "================"); sender.sendMessage(ChatColor.GRAY + "================");
} }

View file

@ -4,8 +4,11 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID; import java.util.UUID;
import ml.codenoodles.lmve.Main;
import ml.codenoodles.lmve.other.ConsoleColor; import ml.codenoodles.lmve.other.ConsoleColor;
public class SQLHandler { public class SQLHandler {
@ -39,16 +42,20 @@ public class SQLHandler {
break; break;
} }
} }
String path = "jdbc:sqlite:" + dbPath + "/" + "Players.db";
String query = "UPDATE " + tableName + " SET " + entity + " = ( " + entity + " + 1) WHERE UUID ='" + uuid.toString() + "';"; String query = "UPDATE " + tableName + " SET " + entity + " = ( " + entity + " + 1) WHERE UUID ='" + uuid.toString() + "';";
try { //Try connection and exec query try { //Try connection and exec query
conn = DriverManager.getConnection(path); conn = DriverManager.getConnection(dbPath);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute(query); stmt.execute(query);
}catch(SQLException sqlEx) { }catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); 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); 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 try { //Close Connection
conn.close(); conn.close();
}catch(SQLException sqlEx) { }catch(SQLException sqlEx) {
System.out.println("[LMVE]" + sqlEx.getMessage()); System.out.println("[LMVE]" + sqlEx.getMessage());
} }
if(successfullQuerys == 5) { if(successfullQuerys == 8) {
System.out.println(ConsoleColor.GREEN + "[LMVE]Default Database successfully created!" + ConsoleColor.RESET); System.out.println(ConsoleColor.GREEN + "[LMVE]Default Database successfully created!" + ConsoleColor.RESET);
} else { } else {
System.out.println(ConsoleColor.RED + "[LMVE]Oops.. Something went wrong during the creation of the Default Database." + ConsoleColor.RESET); System.out.println(ConsoleColor.RED + "[LMVE]Oops.. Something went wrong during the creation of the Default Database." + ConsoleColor.RESET);
} }
} }
//TODO Add DB Update Queries
} }

View file

@ -37,7 +37,6 @@ public class StatCounter implements Listener{
Player p = (Player) e.getEntity(); Player p = (Player) e.getEntity();
if(p.getGameMode() == GameMode.SURVIVAL || p.getGameMode() == GameMode.ADVENTURE) { if(p.getGameMode() == GameMode.SURVIVAL || p.getGameMode() == GameMode.ADVENTURE) {
UUID uuid = p.getUniqueId(); UUID uuid = p.getUniqueId();
Connection conn = null; Connection conn = null;
String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db";
String query = "UPDATE tblPlayerStats SET DamageTaken = (DamageTaken + " + e.getDamage() + ") WHERE UUID = " + uuid.toString() + "';"; 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); 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 { try {
player_stat.save(playerStats); player_stat.save(playerStats);
} catch (IOException ex) { } catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace(); ex.printStackTrace();
} }
} }