From f9a49ff2ee164ccfec9ce115e8416604111d18c9 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 3 Jan 2015 00:35:55 -0500 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20des=20donn=C3=A9es=20de=20co?= =?UTF-8?q?nfiguration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/config.yml | 28 +++++ resources/plugin.yml | 2 +- .../plugin/pandacraftutils/ConfigManager.java | 105 +++++++++++++++--- .../plugin/pandacraftutils/afk/AfkPlayer.java | 2 - 5 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 resources/config.yml diff --git a/make_jar.jardesc b/make_jar.jardesc index be956c0..d258baf 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/config.yml b/resources/config.yml new file mode 100644 index 0000000..16b9463 --- /dev/null +++ b/resources/config.yml @@ -0,0 +1,28 @@ +database: + host: localhost + port: 3306 + base: pandacraft + user: pandacraft + pass: HYtKq92pfx9ucwzq + + + + + +afk: +# in seconds + timeoutAutoMessage: 300 + timeoutAutoKick: 600 + + + + + +chatAnalysis: +# in miliseconds + timeBeforeResendSameMessage: 120000 + timeBeforeResendSameCommand: 60000 + timePerCaracterForNewMessage: 100 + maxViolationLevel: 20 + nbSecondForOneVLDown: 10 + diff --git a/resources/plugin.yml b/resources/plugin.yml index 30525bc..6a9d833 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 2.7 +version: 2.8 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java index 7d54c8a..7fdeb9b 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java @@ -1,28 +1,82 @@ package net.mc_pandacraft.java.plugin.pandacraftutils; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.configuration.file.FileConfiguration; + /* * Configuration du plugin */ public class ConfigManager { private static ConfigManager instance = null; - public static ConfigManager getInstance() { + public synchronized static ConfigManager getInstance() { if (instance == null) - instance = new ConfigManager(); + try { + instance = new ConfigManager(); + } catch (Exception e) { + PandacraftUtils.getInstance().getLogger().severe("Erreur de chargement de la configuration de PandacraftUtils"); + e.printStackTrace(); + } return instance; } - @SuppressWarnings("unused") + public synchronized static void reloadConfig() { + instance = null; + } + private PandacraftUtils plugin = PandacraftUtils.getInstance(); - private ConfigManager() { + private ConfigManager() throws Exception { + + // dossier de configuration principale + File configDir = plugin.getDataFolder(); + configDir.mkdir(); + + // dossier qui doit contenir les messages automatiques + File autoMessagesDir = new File(configDir, "automessages"); + autoMessagesDir.mkdir(); + + // dossier qui doit contenir les alias de commandes + File commandAliasDir = new File(configDir, "commandalias"); + commandAliasDir.mkdir(); + + // dossier qui doit contenir les séries de commandes + File multiCommandsDir = new File(configDir, "multicommands"); + multiCommandsDir.mkdir(); + + // fichier qui doit contenir les insultes à censurer + File badWordsFile = new File(configDir, "badwords.txt"); + badWordsFile.createNewFile(); + + plugin.saveDefaultConfig(); + FileConfiguration configFile = plugin.getConfig(); + + + Database_host = configFile.getString("database.host"); + Database_port = configFile.getInt("database.port"); + Database_database = configFile.getString("database.base"); + Database_username = configFile.getString("database.user"); + Database_password = configFile.getString("database.pass"); + + AFK_timeoutAutoAfkMessage = configFile.getInt("afk.timeoutAutoMessage"); + AFK_timeoutAutoAfkKick = configFile.getInt("afk.timeoutAutoKick"); + + + + ChatAnalysis_timeBeforeResendSameMessage = configFile.getLong("chatAnalysis.timeBeforeResendSameMessage"); + ChatAnalysis_timeBeforeResendSameCommand = configFile.getLong("chatAnalysis.timeBeforeResendSameCommand"); + ChatAnalysis_timePerCaracterForNewMessage = configFile.getLong("chatAnalysis.timePerCaracterForNewMessage"); + ChatAnalysis_maxViolationLevel = configFile.getInt("chatAnalysis.maxViolationLevel"); + ChatAnalysis_nbSecondForOneVLDown = configFile.getInt("chatAnalysis.nbSecondForOneVLDown"); + + initChatAnalysisBadWord(); @@ -35,11 +89,11 @@ public class ConfigManager { * 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"; + public String Database_host; + public int Database_port; + public String Database_username; + public String Database_database; + public String Database_password; @@ -51,9 +105,14 @@ public class ConfigManager { /* * Configuration AFK */ - - public int AFK_timeoutAutoAfkMessage = 60*5; // 5 min - public int AFK_timeoutAutoAfkKick = 60*10; // 10 min + /** + * En secondes + */ + public int AFK_timeoutAutoAfkMessage; + /** + * En secondes + */ + public int AFK_timeoutAutoAfkKick; // 10 min @@ -62,12 +121,24 @@ public class ConfigManager { * Configuration analyse du chat et des messages privés * (antispam, insultes, publicité) */ + + /** + * En milisecondes + */ + public long ChatAnalysis_timeBeforeResendSameMessage;// 2 min + /** + * En milisecondes + */ + public long ChatAnalysis_timeBeforeResendSameCommand;// 60 sec + /** + * En milisecondes + */ + public long ChatAnalysis_timePerCaracterForNewMessage;// 0.1 sec + public int ChatAnalysis_maxViolationLevel; + public int ChatAnalysis_nbSecondForOneVLDown; + + - public long ChatAnalysis_timeBeforeResendSameMessage = 120000;// 2 min - public long ChatAnalysis_timeBeforeResendSameCommand = 60000;// 60 sec - public long ChatAnalysis_timePerCaracterForNewMessage = 100;// 0.1 sec - public int ChatAnalysis_maxViolationLevel = 20; - public int ChatAnalysis_nbSecondForOneVLDown = 10; public List ChatAnalysis_badWords; // les insultes diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/AfkPlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/AfkPlayer.java index bd9e0a1..942f507 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/AfkPlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/AfkPlayer.java @@ -4,8 +4,6 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.Essentials import org.bukkit.entity.Player; -import com.earth2me.essentials.Essentials; - public class AfkPlayer { private Player player; private long timeLastAction;