diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java index 2417884..6c2d352 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java @@ -1,6 +1,5 @@ package net.mc_pandacraft.java.plugin.pandacraftutils; -import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -10,22 +9,45 @@ import java.util.Map; * Configuration du plugin */ public class ConfigManager { - private static ConfigManager instance; + private static ConfigManager instance = null; - public static ConfigManager getInstance() { return instance; } + public static ConfigManager getInstance() { + + if (instance == null) + instance = new ConfigManager(); + + return instance; + } @SuppressWarnings("unused") - private PandacraftUtils plugin; + private PandacraftUtils plugin = PandacraftUtils.getInstance(); - public ConfigManager(File f, PandacraftUtils pl) { - plugin = pl; - instance = this; + private ConfigManager() { initChatAnalysisBadWord(); initCommandAlias(); } + + + /* + * Connexion à la base de donnée + */ + + public String Database_host = "localhost"; + public int Database_port = 3306; + public String Database_username = "pandacraft"; + public String Database_database = "pandacraft"; + public String Database_password = "HYtKq92pfx9ucwzq"; + + + + + + + + /* * Configuration AFK */ @@ -57,13 +79,12 @@ public class ConfigManager { */ ChatAnalysis_badWords.add("pu+tes?"); ChatAnalysis_badWords.add("conn?a(rd?|ss?e?)"); - ChatAnalysis_badWords.add("sal(o|au)pe?s?"); + ChatAnalysis_badWords.add("sal(o+|au)pe?s?"); ChatAnalysis_badWords.add("[ea]ncul(é|e|er|ai(s|t|))"); ChatAnalysis_badWords.add("merdes?"); ChatAnalysis_badWords.add("ni(qu|k)e? ta m(è|e|é)re?"); ChatAnalysis_badWords.add("fil?s de putes?"); ChatAnalysis_badWords.add("ta m(è|e|é)re? l(a|e) putes?"); - ChatAnalysis_badWords.add("ta m(è|e|é)re?"); ChatAnalysis_badWords.add("tafiole?s?"); ChatAnalysis_badWords.add("vas? te pendre"); ChatAnalysis_badWords.add("fuck"); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index 8d14410..9f8120c 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -1,6 +1,8 @@ package net.mc_pandacraft.java.plugin.pandacraftutils; +import java.sql.SQLException; + import net.mc_pandacraft.java.plugin.pandacraftutils.afk.CommandAfk; import net.mc_pandacraft.java.plugin.pandacraftutils.chat_analyzer.ChatAnalysisManager; import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.creative.CreativCheatManager; @@ -16,11 +18,17 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.staff_playe import net.mc_pandacraft.java.plugin.pandacraftutils.spawntime.SpawnTimeManager; import net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid.CommandWandSelection; import net.mc_pandacraft.java.plugin.pandacraftutils.system_analyzer.CommandSystem; +import net.mc_pandacraft.java.util.mysql.DBConnection; import org.bukkit.plugin.java.JavaPlugin; public class PandacraftUtils extends JavaPlugin { + private static PandacraftUtils instance; + public static PandacraftUtils getInstance() { return instance; } + + public DBConnection databaseConnection; + public CommandAfk commandAfk; public CommandList commandPlayers; public CommandSetblock commandSetblock; @@ -44,8 +52,18 @@ public class PandacraftUtils extends JavaPlugin { @Override public void onEnable(){ - // initialisation de la configuration - new ConfigManager(null, this); + instance = this; + + try { + databaseConnection = new DBConnection(ConfigManager.getInstance().Database_host, + ConfigManager.getInstance().Database_port, + ConfigManager.getInstance().Database_database, + ConfigManager.getInstance().Database_username, + ConfigManager.getInstance().Database_password); + } catch (ClassNotFoundException | SQLException e) { + getLogger().severe("Impossible de se connecter à la base de donnée !"); + e.printStackTrace(); + } commandPlayers = new CommandList(this); commandSetblock = new CommandSetblock(this); @@ -83,6 +101,9 @@ public class PandacraftUtils extends JavaPlugin { noPvpProtectManager = null; serverPingListener = null; + + + try { databaseConnection.getConnection().close(); } catch (SQLException e) { } } } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/PandacraftUtils_Player.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/PandacraftUtils_Player.java new file mode 100644 index 0000000..d373e8c --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/PandacraftUtils_Player.java @@ -0,0 +1,34 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; +/** + * Représente les données persistante correspondant à un joueur donné sur le serveur + * + * Le nom de cette classe correspond à celle de la table dans la base de donnée, + * d'où la présence d'un _(underscore), qui n'est pas admis en général + * dans le nom d'une classe + * @author Marc Baloup + * + */ +public class PandacraftUtils_Player extends Table { + + // TODO Créer la table dans la base de donnée + + // TODO Ajouter les champs + + + + + + + @Override + public String[] getValues() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getFieldsName() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/Table.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/Table.java new file mode 100644 index 0000000..6be06d7 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/Table.java @@ -0,0 +1,123 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; + +import org.apache.commons.lang.StringUtils; + +import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +import net.mc_pandacraft.java.util.mysql.DBConnection; + +public abstract class Table { + + DBConnection db = PandacraftUtils.getInstance().databaseConnection; + + + private boolean saved = false; + + + // champ relatif aux données + private int id = 0; + + + + public Table() { + + + } + + + + + + public void save() { + String tableName = this.getClass().getSimpleName(); + + try { + Connection conn; + conn = db.getConnection(); + + String[] fields = getFieldsName(), values = getValues(); + + + + if (saved) + { // mettre à jour les valeurs dans la base + String sql = ""; + for (int i=0; i