Various Bugfixes
This commit is contained in:
parent
f8c3d40786
commit
61cd7bb950
3 changed files with 17 additions and 71 deletions
|
|
@ -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++) {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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,18 +218,13 @@ 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);
|
||||||
}catch(SQLException sqlEx) {
|
|
||||||
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn.close();
|
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);
|
||||||
|
|
@ -242,38 +232,6 @@ public class PlayerStatistics implements Listener{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//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;
|
||||||
|
|
|
||||||
Reference in a new issue