Added PlayerSettings to DB

This commit is contained in:
netbenix 2020-11-20 13:41:13 +01:00
parent b705fab3ff
commit aa291cad5a
2 changed files with 47 additions and 7 deletions

View file

@ -22,6 +22,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import ml.codenoodles.lmve.Main;
import ml.codenoodles.lmve.other.ConsoleColor;
public class PlayerStatistics implements Listener{
private Main main;
@ -41,6 +42,7 @@ public class PlayerStatistics implements Listener{
Boolean existsPlayerHKills = false;
Boolean existsPlayerNKills = false;
Boolean existsPlayerFKills = false;
Boolean existsPlayerSettings = false;
UUID uuid = e.getPlayer().getUniqueId();
String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db";
try { //Try connection
@ -105,8 +107,29 @@ public class PlayerStatistics implements Listener{
}catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
try {//Check if entry in tblPlayerSettings already exists
String query = "SELECT (COUNT(*) 0) FROM tblPlayerSettings WHERE UUID = '" + uuid.toString() + "'";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
rs.next();
existsPlayerSettings = rs.getBoolean(1);
rs.close();
}catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
// TODO Add Entry for PlayerSettings
if(!existsPlayerSettings) {
try {// Create default entry for tblPlayerSettings
String query = "INSERT INTO tblPlayerSetings VALUES ("
+ (totalPlayers + 1) + ","
+ "'" + uuid.toString() + "',"
+ "true);";
Statement stmt = conn.createStatement();
stmt.execute(query);
}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 ("

View file

@ -1,19 +1,24 @@
package ml.codenoodles.lmve.sounds;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Instrument;
import org.bukkit.Note;
import org.bukkit.Note.Tone;
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;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import ml.codenoodles.lmve.Main;
import ml.codenoodles.lmve.other.ConsoleColor;
public class ChatNotification implements Listener{
@ -26,9 +31,21 @@ public class ChatNotification implements Listener{
private void ChatNotifiy(AsyncPlayerChatEvent e) {
if(!main.getConfigFile().getBoolean("Chat.global-mute")) {
for(Player players : Bukkit.getOnlinePlayers()){
File playerStats = new File(main.getDataFolder() + "/Players", players.getUniqueId() + ".yml");
FileConfiguration player_stat = YamlConfiguration.loadConfiguration(playerStats);
if(player_stat.getBoolean(players.getUniqueId() + ".Settings.Sounds.ChatNotify")) {
Connection conn = null;
UUID uuid = e.getPlayer().getUniqueId();
String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/Players.db";
Boolean isEnabled = false;
try {
conn = DriverManager.getConnection(path);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ChatNotify AS chatnotify FROM tblPlayerSettings WHERE UUID = '" + uuid.toString() + "';");
rs.next();
isEnabled = rs.getBoolean(1);
rs.close();
} catch(SQLException sqlEx) {
System.out.println(ConsoleColor.RED + "[LMVE]" + sqlEx.getMessage() + ConsoleColor.RESET);
}
if(isEnabled) {
if(players.getPlayer().getName() != e.getPlayer().getName()) {
players.playNote(players.getLocation(), Instrument.BANJO, Note.natural(1, Tone.C));
}