diff --git a/.classpath b/.classpath index b2984e4..a7a337a 100644 --- a/.classpath +++ b/.classpath @@ -6,10 +6,6 @@ - - - - - + diff --git a/.project b/.project index 9e710a1..112b72a 100644 --- a/.project +++ b/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1604515347360 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2421e38 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "files.exclude": { + "**/.classpath": true, + "**/.project": true, + "**/.settings": true, + "**/.factorypath": true + } +} \ No newline at end of file diff --git a/bin/ml/codenoodles/lmve/Main.class b/bin/ml/codenoodles/lmve/Main.class index 5c533d6..58b9af3 100644 Binary files a/bin/ml/codenoodles/lmve/Main.class and b/bin/ml/codenoodles/lmve/Main.class differ diff --git a/bin/ml/codenoodles/lmve/modules/CustomRecipes.class b/bin/ml/codenoodles/lmve/modules/CustomRecipes.class index 1121c75..6ba81cf 100644 Binary files a/bin/ml/codenoodles/lmve/modules/CustomRecipes.class and b/bin/ml/codenoodles/lmve/modules/CustomRecipes.class differ diff --git a/bin/ml/codenoodles/lmve/modules/EnragedMobs.class b/bin/ml/codenoodles/lmve/modules/EnragedMobs.class index 15ccb95..d76870d 100644 Binary files a/bin/ml/codenoodles/lmve/modules/EnragedMobs.class and b/bin/ml/codenoodles/lmve/modules/EnragedMobs.class differ diff --git a/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class b/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class index a8126a7..b9871bc 100644 Binary files a/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class and b/bin/ml/codenoodles/lmve/modules/PlayerStatistics.class differ diff --git a/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class b/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class index bcd21c9..41065f1 100644 Binary files a/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class and b/bin/ml/codenoodles/lmve/modules/PreventMobGriefing.class differ diff --git a/bin/ml/codenoodles/lmve/modules/SQLHandler.class b/bin/ml/codenoodles/lmve/modules/SQLHandler.class index b5f433f..4cc8978 100644 Binary files a/bin/ml/codenoodles/lmve/modules/SQLHandler.class and b/bin/ml/codenoodles/lmve/modules/SQLHandler.class differ diff --git a/bin/ml/codenoodles/lmve/modules/StatCounter.class b/bin/ml/codenoodles/lmve/modules/StatCounter.class index 137605d..f5b9110 100644 Binary files a/bin/ml/codenoodles/lmve/modules/StatCounter.class and b/bin/ml/codenoodles/lmve/modules/StatCounter.class differ diff --git a/bin/ml/codenoodles/lmve/modules/UUIDReference.class b/bin/ml/codenoodles/lmve/modules/UUIDReference.class index 229e45b..61a4989 100644 Binary files a/bin/ml/codenoodles/lmve/modules/UUIDReference.class and b/bin/ml/codenoodles/lmve/modules/UUIDReference.class differ diff --git a/src/ml/codenoodles/lmve/Main.java b/src/ml/codenoodles/lmve/Main.java index 16a534d..a0f7287 100644 --- a/src/ml/codenoodles/lmve/Main.java +++ b/src/ml/codenoodles/lmve/Main.java @@ -43,7 +43,7 @@ implements Listener { FileConfiguration cfg = this.getConfig(); NamespacedKey Nkey = new NamespacedKey(this, this.getDescription().getName()); - SQLHandler sql = new SQLHandler(); + public SQLHandler sql = new SQLHandler(); public void onEnable() { this.saveDefaultConfig(); registerEvents(); diff --git a/src/ml/codenoodles/lmve/modules/EnragedMobs.java b/src/ml/codenoodles/lmve/modules/EnragedMobs.java index a9c1d4a..4504c71 100644 --- a/src/ml/codenoodles/lmve/modules/EnragedMobs.java +++ b/src/ml/codenoodles/lmve/modules/EnragedMobs.java @@ -7,7 +7,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.attribute.Attribute; import org.bukkit.entity.EntityType; -import org.bukkit.entity.PigZombie; +import org.bukkit.entity.Piglin; import org.bukkit.entity.Player; import org.bukkit.entity.Zombie; import org.bukkit.event.EventHandler; @@ -114,8 +114,8 @@ public class EnragedMobs implements Listener{ } return; } - case PIG_ZOMBIE:{ - PigZombie pigzombie = (PigZombie) e.getEntity(); + case PIGLIN:{ + Piglin pigzombie = (Piglin) e.getEntity(); boolean trigger = checkIfTrigger(); if(trigger) { if(!checkCustomName(pigzombie.getCustomName())) { @@ -125,7 +125,7 @@ public class EnragedMobs implements Listener{ pigzombie.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 9999, 1)); pigzombie.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 60, 1)); pigzombie.setHealth(pigzombie.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - pigzombie.setCustomName("Enraged Zombie Pigman"); + pigzombie.setCustomName("Enraged Piglin"); pigzombie.setCustomNameVisible(true); } } diff --git a/src/ml/codenoodles/lmve/modules/PlayerStatistics.java b/src/ml/codenoodles/lmve/modules/PlayerStatistics.java index 3793f50..0676223 100644 --- a/src/ml/codenoodles/lmve/modules/PlayerStatistics.java +++ b/src/ml/codenoodles/lmve/modules/PlayerStatistics.java @@ -2,11 +2,6 @@ package ml.codenoodles.lmve.modules; import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -25,7 +20,6 @@ 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.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -40,6 +34,168 @@ public class PlayerStatistics implements Listener{ this.main = main; } + + @EventHandler + private void createDefaultEntrys(PlayerJoinEvent e) { + Connection conn = null; + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); + LocalDateTime timeNow = LocalDateTime.now(); + Player p = (Player) e.getPlayer(); + String playerName = p.getName(); + Boolean existsPlayerStats = false; + Boolean existsPlayerHKills = false; + Boolean existsPlayerNKills = false; + Boolean existsPlayerFKills = false; + UUID uuid = e.getPlayer().getUniqueId(); + String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; + try { //Try connection + conn = DriverManager.getConnection(path); + } catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + + int totalPlayers = 0; + try { //Get Total Players + Statement stmt = conn.createStatement(); + ResultSet res = stmt.executeQuery("SELECT COUNT(*) AS rowcount FROM tblPlayerStats;"); + + res.next(); + totalPlayers = res.getInt("rowcount"); + res.close(); + }catch(SQLException sqlEx) { + System.out.println("[LMVE]" + sqlEx.getMessage()); + return; + } + + try { //Check if entry in tblPlayerStats already exists + String query = "SELECT (COUNT(*) > 0) FROM tblPlayerStats WHERE UUID = '" + uuid.toString() + "'"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + rs.next(); + existsPlayerStats = rs.getBoolean(1); + rs.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + + try { //Check if entry in tblPlayerHKills already exists + String query = "SELECT (COUNT(*) > 0) FROM tblPlayerHKills WHERE UUID = '" + uuid.toString() + "'"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + rs.next(); + existsPlayerHKills = rs.getBoolean(1); + rs.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + + try { //Check if entry in tblPlayerNKills already exists + String query = "SELECT (COUNT(*) > 0) FROM tblPlayerNKills WHERE UUID = '" + uuid.toString() + "'"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + rs.next(); + existsPlayerNKills = rs.getBoolean(1); + rs.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + + try { //Check if entry in tblPlayerFKills already exists + String query = "SELECT (COUNT(*) > 0) FROM tblPlayerFKills WHERE UUID = '" + uuid.toString() + "'"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + rs.next(); + existsPlayerFKills = rs.getBoolean(1); + rs.close(); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + + + if(!existsPlayerStats) { + try { //Create default entry for tblPlayerStats + String query = "INSERT INTO tblPlayerStats VALUES (" + + (totalPlayers + 1) + "," + + "'" + uuid.toString() + "'," //UUID + + "'" + playerName + "'," //Displayname + + p.getHealth() + "," //Health + + "'" + p.getWorld().getName() + "'," //Worldname + + "'" + dtf.format(timeNow) + "'," //FirstJoin + + "'null'," //LastJoin + + 0 + "," //Deaths + + 0 + ");"; //DamageTaken + Statement stmt = conn.createStatement(); + stmt.execute(query); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + } + + if(!existsPlayerHKills) { + try { //Create default entry for tblPlayerHKills + String query = "INSERT INTO tblPlayerHKills VALUES (" + + (totalPlayers + 1) + "," + + "'" + uuid.toString() + "',"; + for(int i = 0; i < 24; i++) { + if(i == 23) { + query += "0);"; + } else { + query += "0,"; + } + } + Statement stmt = conn.createStatement(); + stmt.execute(query); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + } + + if(!existsPlayerNKills) { + try{ //Create default entry for tblPlayerNKills + String query = "INSERT INTO tblPlayerNKills VALUES (" + + (totalPlayers + 1) + "," + + "'" + uuid.toString() + "',"; + for(int i = 0; i < 11; i++) { + if(i == 10) { + query += "0);"; + } else { + query += "0,"; + } + } + Statement stmt = conn.createStatement(); + stmt.execute(query); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + } + + if(!existsPlayerFKills) { + try { //Create default entry for tblPlayerFKills + String query = "INSERT InTO tblPlayerFKills VALUES (" + + (totalPlayers + 1) + "," + + "'" + uuid.toString() + "',"; + for(int i = 0; i < 23; i++) { + if(i == 22) { + query += "0);"; + } else { + query += "0,"; + } + } + Statement stmt = conn.createStatement(); + stmt.execute(query); + } catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + } + + + try { // Close connection + conn.close(); + } catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + } + @EventHandler private void UpdateLastJoined(PlayerJoinEvent e) { UUID player_uuid = e.getPlayer().getUniqueId(); @@ -47,6 +203,9 @@ public class PlayerStatistics implements Listener{ 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)); try { player_stat.save(playerStats); @@ -61,28 +220,24 @@ public class PlayerStatistics implements Listener{ Player p = (Player) e.getPlayer(); UUID uuid = p.getUniqueId(); - File playerStats = new File(main.getDataFolder() + "/Players", uuid + ".yml"); - FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats); - player_stat.set(uuid + ".General.DisplayName", p.getName()); - player_stat.set(uuid + ".General.Health", p.getHealth()); - player_stat.set(uuid + ".General.World", p.getWorld().getName()); - player_stat.set(uuid + ".General.Location.X", p.getLocation().getX()); - player_stat.set(uuid + ".General.Location.Y", p.getLocation().getY()); - player_stat.set(uuid + ".General.Location.Z", p.getLocation().getZ()); - float pTime = p.getStatistic(Statistic.PLAY_ONE_MINUTE); - pTime = pTime / 20; - pTime = pTime / 60; - pTime = pTime / 60; - player_stat.set(uuid + ".TimePlayed", pTime); + 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() + "),"; 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); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } + } - @EventHandler(priority = EventPriority.LOW) + //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"); @@ -110,7 +265,7 @@ public class PlayerStatistics implements Listener{ content = content.replaceAll(("\\b" + oldName + "\\b"), newName); Files.write(pListPath, content.getBytes(charset)); } - } + }*/ public void outputStats(CommandSender sender, UUID uuid) { diff --git a/src/ml/codenoodles/lmve/modules/SQLHandler.java b/src/ml/codenoodles/lmve/modules/SQLHandler.java index 850beb4..6e308d5 100644 --- a/src/ml/codenoodles/lmve/modules/SQLHandler.java +++ b/src/ml/codenoodles/lmve/modules/SQLHandler.java @@ -4,15 +4,53 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.util.UUID; import ml.codenoodles.lmve.other.ConsoleColor; public class SQLHandler { - public SQLHandler() { } + public void updateKillCounter(int table, String entity, UUID uuid, String dbPath) { + Connection conn = null; + String tableName = null; + + switch(table){ + case 0:{ + tableName = "tblPlayerStats"; + break; + } + case 1:{ + tableName = "tblPlayerFKills"; + break; + } + case 2:{ + tableName = "tblPlayerNKills"; + break; + } + case 3:{ + tableName = "tblPlayerHKills"; + break; + } + default:{ + tableName = "NULL"; + 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); + Statement stmt = conn.createStatement(); + stmt.execute(query); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); + } + } + public void createDefaultDatabase(String dbPath) { Connection conn; diff --git a/src/ml/codenoodles/lmve/modules/StatCounter.java b/src/ml/codenoodles/lmve/modules/StatCounter.java index 056e263..ba2f5a6 100644 --- a/src/ml/codenoodles/lmve/modules/StatCounter.java +++ b/src/ml/codenoodles/lmve/modules/StatCounter.java @@ -2,6 +2,10 @@ package ml.codenoodles.lmve.modules; import java.io.File; import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import java.util.UUID; import org.bukkit.GameMode; @@ -11,13 +15,12 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent; import ml.codenoodles.lmve.Main; +import ml.codenoodles.lmve.other.ConsoleColor; public class StatCounter implements Listener{ @@ -26,58 +29,26 @@ public class StatCounter implements Listener{ this.main = main; } - @EventHandler - private void BlockDestroyCounter(BlockBreakEvent e) { - Player p = e.getPlayer(); - UUID uuid = p.getUniqueId(); - File playerStats = new File(main.getDataFolder() + "/Players", uuid + ".yml"); - FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats); - long counter = player_stat.getInt(uuid + ".Statistics.Blocks.Destroyed"); - counter++; - player_stat.set(uuid + ".Statistics.Blocks.Destroyed", counter); - try { - player_stat.save(playerStats); - } catch (IOException ex) { - // TODO Auto-generated catch block - ex.printStackTrace(); - } - } - - @EventHandler - private void BlockPlaceCounter(BlockPlaceEvent e) { - Player p = e.getPlayer(); - UUID uuid = p.getUniqueId(); - File playerStats = new File(main.getDataFolder() + "/Players", uuid + ".yml"); - FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats); - long counter = player_stat.getInt(uuid + ".Statistics.Blocks.Placed"); - counter++; - player_stat.set(uuid + ".Statistics.Blocks.Placed", counter); - try { - player_stat.save(playerStats); - } catch (IOException ex) { - // TODO Auto-generated catch block - ex.printStackTrace(); - } - } - + @EventHandler private void PlayerDamageCounter(EntityDamageEvent e) { Entity entity = e.getEntity(); if (entity instanceof Player) { Player p = (Player) e.getEntity(); if(p.getGameMode() == GameMode.SURVIVAL || p.getGameMode() == GameMode.ADVENTURE) { - UUID uuid = p.getUniqueId(); - File playerStats = new File(main.getDataFolder() + "/Players", uuid + ".yml"); - FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats); - double damage = player_stat.getDouble(uuid + ".Statistics.DamageTaken"); - damage = damage + e.getDamage(); - player_stat.set(uuid + ".Statistics.DamageTaken", damage); + 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() + "';"; try { - player_stat.save(playerStats); - } catch (IOException ex) { - // TODO Auto-generated catch block - ex.printStackTrace(); + conn = DriverManager.getConnection(path); + Statement stmt = conn.createStatement(); + stmt.execute(query); + }catch(SQLException sqlEx) { + System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET); } + } } } @@ -103,393 +74,249 @@ public class StatCounter implements Listener{ private void EntityKillCounter(EntityDeathEvent e) { String ent_type = e.getEntity().getType().toString(); Player p = (Player) e.getEntity().getKiller(); - UUID player_uuid; + UUID uuid; + SQLHandler sql = new SQLHandler(); if(p != null) { - player_uuid = p.getUniqueId(); + uuid = p.getUniqueId(); } else { return; } - File playerStats = new File(main.getDataFolder() + "/Players", player_uuid + ".yml"); - FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats); - //Friendly - int sheep, pig, chicken, bat, cat, cod, cow, donkey, fox, horse, mooshroom, mule, - ocelot, parrot, rabbit,salmon, skeletonhorse, squid, tropicalfish, turtle, villager, wanderingtrader, snowgolem; //PRE 1.15 - //Neutral - int enderman, pufferfish, dolphin, llama, panda, polarBear, traderLlama, wolf, ironGolem, zombiePigman; //PRE 1.15 - int bee; //1.15 + - //Hostile - int blaze, creeper, drowned, elderGuardian, endermite, evoker, ghast, guardian, husk, - magmaCube, phantom, pillager, ravager, shulker, silverfish, skeleton, slime, - stray, vex, vindicator, witch, witherSkeleton, zombie, zombieVillager; //PRE 1.15 - //Boss - int enderDragon, wither; + + String dbPath = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db"; + switch(ent_type) { case "SHEEP":{ - sheep = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Sheep"); - sheep++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Sheep", sheep); + sql.updateKillCounter(1, "Sheep", uuid, dbPath); break; } case "PIG":{ - pig = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Pig"); - pig++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Pig", pig); + sql.updateKillCounter(1, "Pig", uuid, dbPath); break; } case "CHICKEN":{ - chicken = player_stat.getInt(player_uuid + "Statistics.Kills.Friendly.Chicken"); - chicken++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Chicken", chicken); + sql.updateKillCounter(1, "Chicken", uuid, dbPath); break; } case "BAT":{ - bat = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Bat"); - bat++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Bat", bat); + sql.updateKillCounter(1, "Bat", uuid, dbPath); break; } case "CAT":{ - cat = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Cat"); - cat++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Cat", cat); + sql.updateKillCounter(1, "Cat", uuid, dbPath); break; } case "COD":{ - cod = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Cod"); - cod++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Cod", cod); + sql.updateKillCounter(1, "Cod", uuid, dbPath); break; } case "COW":{ - cow = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Cow"); - cow++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Cow", cow); + sql.updateKillCounter(1, "Cow", uuid, dbPath); break; } case "DONKEY":{ - donkey = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Donkey"); - donkey++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Donkey", donkey); + sql.updateKillCounter(1, "Donkey", uuid, dbPath); break; } case "FOX":{ - fox = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Fox"); - fox++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Fox", fox); + sql.updateKillCounter(1, "Fox", uuid, dbPath); break; } case "HORSE":{ - horse = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Horse"); - horse++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Horse", horse); + sql.updateKillCounter(1, "Horse", uuid, dbPath); break; } case "MOOSHROOM":{ - mooshroom = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Mooshroom"); - mooshroom++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Mooshroom", mooshroom); + sql.updateKillCounter(1, "Mooshroom", uuid, dbPath); break; } case "MULE":{ - mule = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Mule"); - mule++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Mule", mule); + sql.updateKillCounter(1, "Mule", uuid, dbPath); break; } case "OCELOT":{ - ocelot = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Ocelot"); - ocelot++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Ocelot", ocelot); + sql.updateKillCounter(1, "Ocelot", uuid, dbPath); break; } case "PARROT":{ - parrot = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Parrot"); - parrot++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Parrot", parrot); + sql.updateKillCounter(1, "Parrot", uuid, dbPath); break; } case "RABBIT":{ - rabbit = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Rabbit"); - rabbit++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Rabbit", rabbit); + sql.updateKillCounter(1, "Rabbit", uuid, dbPath); break; } case "SALMON":{ - salmon = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Salmon"); - salmon++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Salmon", salmon); + sql.updateKillCounter(1, "Salmon", uuid, dbPath); break; } case "SKELETON_HORSE":{ - skeletonhorse = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Skeleton_Horse"); - skeletonhorse++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Skeleton_Horse", skeletonhorse); + sql.updateKillCounter(1, "Skeleton_Horse", uuid, dbPath); break; } case "SQUID":{ - squid = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Squid"); - squid++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Squid",squid); + sql.updateKillCounter(1, "Squid", uuid, dbPath); break; } case "TROPICAL_FISH":{ - tropicalfish = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Tropical_Fish"); - tropicalfish++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Tropical_Fish", tropicalfish); + sql.updateKillCounter(1, "Tropical_Fish", uuid, dbPath); break; } case "TURTLE":{ - turtle = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Turtle"); - turtle++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Turtle", turtle); + sql.updateKillCounter(1, "Turtle", uuid, dbPath); break; } case "VILLAGER":{ - villager = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Villager"); - villager++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Villager", villager); + sql.updateKillCounter(1, "Villager", uuid, dbPath); break; } case "WANDERING_TRADER":{ - wanderingtrader = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Wandering_Trader"); - wanderingtrader++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Wandering_Trader", wanderingtrader); + sql.updateKillCounter(1, "Wandering_Trader", uuid, dbPath); break; } case "SNOWMAN":{ - snowgolem = player_stat.getInt(player_uuid + ".Statistics.Kills.Friendly.Snowman"); - snowgolem++; - player_stat.set(player_uuid + ".Statistics.Kills.Friendly.Snowman", snowgolem); + sql.updateKillCounter(1, "Snowman", uuid, dbPath); break; } case "ENDERMAN":{ - enderman = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Enderman"); - enderman++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Enderman", enderman); + sql.updateKillCounter(2, "Enderman", uuid, dbPath); break; } case "PUFFERFISH":{ - pufferfish = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Pufferfish"); - pufferfish++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Pufferfish", pufferfish); + sql.updateKillCounter(2, "Pufferfish", uuid, dbPath); break; } case "DOLPHIN":{ - dolphin = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Dolphin"); - dolphin++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Dolphin", dolphin); + sql.updateKillCounter(2, "Dolphin", uuid, dbPath); break; } case "LLAMA":{ - llama = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Llama"); - llama++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Llama", llama); + sql.updateKillCounter(2, "Llama", uuid, dbPath); break; } case "PANDA":{ - panda = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Panda"); - panda++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Panda", panda); + sql.updateKillCounter(2, "Panda", uuid, dbPath); break; } case "POLAR_BEAR":{ - polarBear = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Polar_Bear"); - polarBear++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Polar_Bear", polarBear); + sql.updateKillCounter(2, "Polar_Bear", uuid, dbPath); break; } case "TRADER_LLAMA":{ - traderLlama = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Trader_Llama"); - traderLlama++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Trader_Llama", traderLlama); + sql.updateKillCounter(2, "Trader_Llama", uuid, dbPath); break; } case "WOLF":{ - wolf = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Wolf"); - wolf++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Wolf", wolf); + sql.updateKillCounter(2, "Wolf", uuid, dbPath); break; } - case "IRON:GOLEM":{ - ironGolem = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Iron_Golem"); - ironGolem++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Iron_Golem", ironGolem); + case "IRON_GOLEM":{ + sql.updateKillCounter(2, "Iron_Golem", uuid, dbPath); break; } case "PIG_ZOMBIE":{ - zombiePigman = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Zombie_Pigman"); - zombiePigman++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Zombie_Pigman", zombiePigman); + sql.updateKillCounter(2, "Pig_Zombie", uuid, dbPath); break; } case "BEE":{ - bee = player_stat.getInt(player_uuid + ".Statistics.Kills.Neutral.Bee"); - bee++; - player_stat.set(player_uuid + ".Statistics.Kills.Neutral.Bee", bee); + sql.updateKillCounter(2, "Bee", uuid, dbPath); break; } case "BLAZE":{ - blaze = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Blaze"); - blaze++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Blaze", blaze); + sql.updateKillCounter(3, "Blaze", uuid, dbPath); break; } case "CREEPER":{ - creeper = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Creeper"); - creeper++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Creeper", creeper); + sql.updateKillCounter(3, "Creeper", uuid, dbPath); break; } case "DROWNED":{ - drowned = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Drowned"); - drowned++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Drowned", drowned); + sql.updateKillCounter(3, "Drowned", uuid, dbPath); break; } case "ELDER_GUARDIAN":{ - elderGuardian = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Elder_Guardian"); - elderGuardian++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Elder_Guardian", elderGuardian); + sql.updateKillCounter(3, "Elder_Guardian", uuid, dbPath); break; } case "ENDERMITE":{ - endermite = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Endermite"); - endermite++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Endermite", endermite); + sql.updateKillCounter(3, "Endermite", uuid, dbPath); break; } case "EVOKER":{ - evoker = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Evoker"); - evoker++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Evoker", evoker); + sql.updateKillCounter(3, "Evoker", uuid, dbPath); break; } case "GHAST":{ - ghast = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Ghast"); - ghast++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Ghast", ghast); + sql.updateKillCounter(3, "Ghast", uuid, dbPath); break; } case "GUARDIAN":{ - guardian = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Guardian"); - guardian++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Guardian", guardian); + sql.updateKillCounter(3, "Guardian", uuid, dbPath); break; } case "HUSK":{ - husk = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Husk"); - husk++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Husk", husk); + sql.updateKillCounter(3, "Husk", uuid, dbPath); break; } case "MAGMA_CUBE":{ - magmaCube = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Magma_Cube"); - magmaCube++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Magma_Cube", magmaCube); + sql.updateKillCounter(3, "Magma_Cube", uuid, dbPath); break; } case "PHANTOM":{ - phantom = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Phantom"); - phantom++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Phantom", phantom); + sql.updateKillCounter(3, "Phantom", uuid, dbPath); break; } case "PILLAGER":{ - pillager = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Pillager"); - pillager++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Pillager", pillager); + sql.updateKillCounter(3, "Pillager", uuid, dbPath); break; } case "RAVAGER":{ - ravager = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Ravager"); - ravager++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Ravager", ravager); + sql.updateKillCounter(3, "Ravager", uuid, dbPath); break; } case "SHULKER":{ - shulker = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Shulker"); - shulker++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Shulker", shulker); + sql.updateKillCounter(3, "Shulker", uuid, dbPath); break; } case "SILVERFISH":{ - silverfish = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Silverfish"); - silverfish++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Silverfish", silverfish); + sql.updateKillCounter(3, "Silverfish", uuid, dbPath); break; } case "SKELETON":{ - skeleton = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Skeleton"); - skeleton++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Skeleton", skeleton); + sql.updateKillCounter(3, "Skeleton", uuid, dbPath); break; } case "SLIME":{ - slime = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Slime"); - slime++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Slime", slime); + sql.updateKillCounter(3, "Slime", uuid, dbPath); break; } case "STRAY":{ - stray = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Stray"); - stray++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Stray", stray); + sql.updateKillCounter(3, "Stray", uuid, dbPath); break; } case "VEX":{ - vex = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Vex"); - vex++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Vex", vex); + sql.updateKillCounter(3, "Vex", uuid, dbPath); break; } case "VINDICATOR":{ - vindicator = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Vindicator"); - vindicator++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Vindicator", vindicator); + sql.updateKillCounter(3, "Vindicator", uuid, dbPath); break; } case "WITCH":{ - witch = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Witch"); - witch++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Witch", witch); + sql.updateKillCounter(3, "Witch", uuid, dbPath); break; } case "WITHER_SKELETON":{ - witherSkeleton = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Wither_Skeleton"); - witherSkeleton++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Wither_Skeleton", witherSkeleton); + sql.updateKillCounter(3, "Wither_Skeleton", uuid, dbPath); break; } case "ZOMBIE":{ - zombie = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Zombie"); - zombie++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Zombie", zombie); + sql.updateKillCounter(3, "Zombie", uuid, dbPath); break; } case "ZOMBIE_VILLAGER":{ - zombieVillager = player_stat.getInt(player_uuid + ".Statistics.Kills.Hostile.Zombie_Villager"); - zombieVillager++; - player_stat.set(player_uuid + ".Statistics.Kills.Hostile.Zombie_Villager", zombieVillager); + sql.updateKillCounter(3, "Zombie_Villager", uuid, dbPath); break; } - case "ENDER_DRAGON":{ - enderDragon = player_stat.getInt(player_uuid + ".Statistics.Kills.Boss.Ender_Dragon"); - enderDragon++; - player_stat.set(player_uuid + ".Statistics.Kills.Boss.Ender_Dragon", enderDragon); - break; - } - case "WITHER":{ - wither = player_stat.getInt(player_uuid + ".Statistics.Kills.Boss.Wither"); - wither++; - player_stat.set(player_uuid + ".Statistics.Kills.Boss.Wither", wither); - break; - } - } - try { - player_stat.save(playerStats); - } catch (IOException ex) { - // TODO Auto-generated catch block - ex.printStackTrace(); } } } diff --git a/src/ml/codenoodles/lmve/modules/UUIDReference.java b/src/ml/codenoodles/lmve/modules/UUIDReference.java index c12c78a..515f532 100644 --- a/src/ml/codenoodles/lmve/modules/UUIDReference.java +++ b/src/ml/codenoodles/lmve/modules/UUIDReference.java @@ -29,7 +29,7 @@ public class UUIDReference implements Listener{ String playerName = p.getName(); String uuid = p.getUniqueId().toString(); - Connection conn; + Connection conn = null; boolean entryExists = false; String path = "jdbc:sqlite:" + dbPath + "/" + "Players.db"; try { //Try Connection