Skip to content
Snippets Groups Projects
Commit b94be4d3 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Ajout de la classe ConsoleLog et remplacement des anciens appels de logs.

parent fb89fb06
No related branches found
No related tags found
1 merge request!6Donner le joueur habitué aux joueurs.
Pipeline #49 passed
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="CallToStringConcatCanBeReplacedByOperator" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="IncorrectFormatting" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="ProblematicWhitespace" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UnnecessaryQualifierForThis" enabled="false" level="WEAK WARNING" enabled_by_default="false" editorAttributes="INFO_ATTRIBUTES" />
<inspection_tool class="UnqualifiedStaticUsage" enabled="false" level="WEAK WARNING" enabled_by_default="false" editorAttributes="INFO_ATTRIBUTES">
<option name="m_ignoreStaticFieldAccesses" value="false" />
<option name="m_ignoreStaticMethodCalls" value="false" />
<option name="m_ignoreStaticAccessFromStaticContext" value="false" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
......@@ -6,6 +6,7 @@ import com.slprojects.slcraftplugin.commands.publics.Wild;
import com.slprojects.slcraftplugin.parallelTasks.InternalWebServer;
import com.slprojects.slcraftplugin.parallelTasks.PeriodicEvent;
import com.slprojects.slcraftplugin.parallelTasks.PlayerDataHandler;
import com.slprojects.slcraftplugin.utils.ConsoleLog;
import me.clip.placeholderapi.PlaceholderAPI;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.cacheddata.CachedMetaData;
......@@ -46,6 +47,7 @@ public final class Main extends JavaPlugin implements Listener {
// Variables
private static FileConfiguration config;
private static LuckPerms luckPermsApi;
public static String pluginName;
// Publiques car on les appelle ailleurs
public PlayerDataHandler playerDataHandler;
......@@ -54,13 +56,14 @@ public final class Main extends JavaPlugin implements Listener {
@Override
public void onEnable() {
pluginName = this.getName();
// On s'assure qu'on a placeholder api
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
getLogger().info("PlaceholderAPI chargé");
ConsoleLog.info("PlaceholderAPI chargé");
// On initialise les listeners
getServer().getPluginManager().registerEvents(this, this);
} else {
getServer().getConsoleSender().sendMessage(ChatColor.RED+"["+ this.getName() +"] PlaceholderAPI n'est pas accessible!");
ConsoleLog.danger("PlaceholderAPI n'est pas accessible!");
getServer().getPluginManager().disablePlugin(this);
}
......@@ -69,14 +72,14 @@ public final class Main extends JavaPlugin implements Listener {
if (getServer().getPluginManager().getPlugin("LuckPerms") != null) {
RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
if (provider != null) {
getLogger().info("LuckPerms chargé");
ConsoleLog.info("LuckPerms chargé");
luckPermsApi = provider.getProvider();
}else{
getServer().getConsoleSender().sendMessage(ChatColor.RED+"["+ this.getName() +"] LuckPerms n'est pas accessible!");
ConsoleLog.danger("LuckPerms n'est pas accessible!");
getServer().getPluginManager().disablePlugin(this);
}
} else {
getServer().getConsoleSender().sendMessage(ChatColor.RED+"["+ this.getName() +"] LuckPerms n'est pas accessible!");
ConsoleLog.danger("LuckPerms n'est pas accessible!");
getServer().getPluginManager().disablePlugin(this);
}
......@@ -264,7 +267,7 @@ public final class Main extends JavaPlugin implements Listener {
getServer().getConsoleSender().sendMessage("Func AsyncChatEvent(PlayerChatEvent e), HTTP response:" + response);
}
} catch (UnsupportedEncodingException ex) {
getLogger().warning(ChatColor.RED + "Impossible de d'encoder les données. Func AsyncChatEvent(PlayerChatEvent e)");
ConsoleLog.danger("Impossible de d'encoder les données. Func AsyncChatEvent(PlayerChatEvent e)");
ex.printStackTrace();
}
}
......@@ -283,7 +286,7 @@ public final class Main extends JavaPlugin implements Listener {
try {
MariaDbPoolDataSource dataSource = new MariaDbPoolDataSource("jdbc:mariadb://"+config.getString("database.host")+"/"+config.getString("database.database")+"?user="+config.getString("database.user")+"&password="+config.getString("database.password")+"&maxPoolSize=10");
conn = dataSource.getConnection();
//getLogger().info(ChatColor.GREEN+"Connexion à la base de données réussie!");
ConsoleLog.success("Connexion à la base de données réussie!");
}// ou les saisir
catch (SQLException e) {
getServer().getConsoleSender().sendMessage(ChatColor.RED+"Erreur lors de la connexion à la base de données.");
......@@ -293,10 +296,10 @@ public final class Main extends JavaPlugin implements Listener {
}
private void updateConfig(){
getLogger().info("Vérification du fichier de configuration...");
ConsoleLog.info("Vérification du fichier de configuration...");
// 1.6.0
if(!config.contains("server-type")){
getLogger().info("Ajout de la variable serverType dans le fichier de configuration...");
ConsoleLog.info("Ajout de la variable serverType dans le fichier de configuration...");
config.set("server-type", "dev");
saveConfig();
......@@ -304,7 +307,7 @@ public final class Main extends JavaPlugin implements Listener {
}
if(config.contains("wild") && (config.contains("excluded-biomes") && config.contains("world") && config.contains("max-range"))){
getLogger().info("Mise à jour des paramètres concernant la commande /wild");
ConsoleLog.info("Mise à jour des paramètres concernant la commande /wild");
config.set("wild.excluded-biomes", config.get("excluded-biomes"));
config.set("wild.world", config.get("world"));
......
package com.slprojects.slcraftplugin.parallelTasks;
import com.slprojects.slcraftplugin.Main;
import com.slprojects.slcraftplugin.utils.ConsoleLog;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
......@@ -45,7 +46,7 @@ public class PlayerDataHandler {
try {
con.close();
} catch (SQLException e) {
plugin.getLogger().warning("Impossible de fermer la connexion à la bdd. Func savePlayerData::saveOnJoin(Player player)");
ConsoleLog.warning("Impossible de fermer la connexion à la bdd. Func savePlayerData::saveOnJoin(Player player)");
e.printStackTrace();
}
}
......@@ -62,7 +63,7 @@ public class PlayerDataHandler {
try {
con.close();
} catch (SQLException e) {
plugin.getLogger().warning("Impossible de fermer la connexion à la bdd. Func savePlayerData::saveOnQuit(Player player)");
ConsoleLog.warning("Impossible de fermer la connexion à la bdd. Func savePlayerData::saveOnQuit(Player player)");
e.printStackTrace();
}
}
......@@ -93,7 +94,7 @@ public class PlayerDataHandler {
insertUtilisateur.executeQuery();
}
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::insertPlayerName(Player player)");
ConsoleLog.warning("Func savePlayerData::insertPlayerName(Player player)");
e.printStackTrace();
}
}
......@@ -106,7 +107,7 @@ public class PlayerDataHandler {
insertPlayerEntryOrExit.setString(3, Timestamp.valueOf(java.time.LocalDateTime.now()).toString());
insertPlayerEntryOrExit.executeQuery();
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::playerAddPlayerEntryOrExit(Player player, boolean isEnter)");
ConsoleLog.warning("Func savePlayerData::playerAddPlayerEntryOrExit(Player player, boolean isEnter)");
e.printStackTrace();
}
}
......@@ -135,7 +136,7 @@ public class PlayerDataHandler {
insertionDateInscription.executeQuery();
// On va précisier que la date d'inscription a été trouvée chez CoreProtect
plugin.getLogger().info("Le joueur "+ ChatColor.GOLD+player.getName()+ChatColor.RESET+" n'avait pas de données sur sa date d'inscription dans dans la table des paramètres utilisateurs. On lui a donc attribué comme date de création du compte, celle que détenait CoreProtect.");
ConsoleLog.info("Le joueur "+ ChatColor.GOLD+player.getName()+ChatColor.RESET+" n'avait pas de données sur sa date d'inscription dans dans la table des paramètres utilisateurs. On lui a donc attribué comme date de création du compte, celle que détenait CoreProtect.");
} else {
// On insère la date d'inscription (du coup on considère que Le joueur n'a pas joué avant, malgré la condition)
PreparedStatement insertionDateInscription = con.prepareStatement("INSERT INTO site_userSetting (`uuid`, `name`, `value`) VALUES (?,'joinedDate',?)");
......@@ -151,7 +152,7 @@ public class PlayerDataHandler {
// On est daccord que ceci n'est pas censé arriver, cela ne concerne que mes potes n'étant venus que durant les premières semaines du serveur.
plugin.getLogger().info("Le joueur "+ChatColor.GOLD+player.getName()+ChatColor.RESET+" n'avait pas de données sur sa date d'inscription dans dans la table des paramètres utilisateurs, ni dans la table des utilisateurs de CoreProtect. On lui a donc attribué comme date de création du compte, la date du début de sa partie.");
ConsoleLog.info("Le joueur "+ChatColor.GOLD+player.getName()+ChatColor.RESET+" n'avait pas de données sur sa date d'inscription dans dans la table des paramètres utilisateurs, ni dans la table des utilisateurs de CoreProtect. On lui a donc attribué comme date de création du compte, la date du début de sa partie.");
}
}else{
// Le joueur est nouveau, on insère la date d'inscription
......@@ -162,7 +163,7 @@ public class PlayerDataHandler {
}
}
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::checkJoinedDate(Player player)");
ConsoleLog.warning("Func savePlayerData::checkJoinedDate(Player player)");
e.printStackTrace();
}
}
......@@ -189,7 +190,7 @@ public class PlayerDataHandler {
}
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::setPlayerJoinCount(Player player)");
ConsoleLog.warning("Func savePlayerData::setPlayerJoinCount(Player player)");
e.printStackTrace();
}
}
......@@ -221,7 +222,7 @@ public class PlayerDataHandler {
}
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::increasePlayerPlayTime(Player player)");
ConsoleLog.warning("Func savePlayerData::increasePlayerPlayTime(Player player)");
e.printStackTrace();
}
}
......@@ -258,9 +259,9 @@ public class PlayerDataHandler {
}
};
}else{
plugin.getLogger().warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
plugin.getLogger().warning("Fonctionnement anormal! On dispose de la date de 'wildCmdLastUsed' mais pas de 'wildCmdAskNum' pour le joueur " + player.getName() + " UUID: " + player.getUniqueId());
plugin.getLogger().warning("Passage de 'wildCmdAskNum' à 0.");
ConsoleLog.warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
ConsoleLog.warning("Fonctionnement anormal! On dispose de la date de 'wildCmdLastUsed' mais pas de 'wildCmdAskNum' pour le joueur " + player.getName() + " UUID: " + player.getUniqueId());
ConsoleLog.warning("Passage de 'wildCmdAskNum' à 0.");
return new ArrayList<Object>(){
{
add(0);
......@@ -271,7 +272,7 @@ public class PlayerDataHandler {
}
}else{
plugin.getLogger().info("Mise à jour du joueur " + player.getName() + " UUID: " + player.getUniqueId());
plugin.getLogger().info("Création des champs 'wildCmdLastUsed' et 'wildCmdAskNum'");
ConsoleLog.info("Création des champs 'wildCmdLastUsed' et 'wildCmdAskNum'");
// On va insérer une date bidon pour éviter un potentiel cooldown
LocalDateTime dateBidon = LocalDateTime.parse("2001-12-11 12:30", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
......@@ -294,13 +295,13 @@ public class PlayerDataHandler {
}
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
ConsoleLog.warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
e.printStackTrace();
}
plugin.getLogger().warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
plugin.getLogger().warning("Fonctionnement anormal! La recherche dans la bdd a échouée pour le joueur " + player.getName() + " UUID: " + player.getUniqueId());
plugin.getLogger().warning("Passage de 'wildCmdLastUsed' au 11 décembre 2001 et 'wildCmdAskNum' à 0");
ConsoleLog.warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
ConsoleLog.warning("Fonctionnement anormal! La recherche dans la bdd a échouée pour le joueur " + player.getName() + " UUID: " + player.getUniqueId());
ConsoleLog.warning("Passage de 'wildCmdLastUsed' au 11 décembre 2001 et 'wildCmdAskNum' à 0");
return new ArrayList<Object>(){
{
......@@ -328,7 +329,7 @@ public class PlayerDataHandler {
updateWildCmdLastUsed.executeUpdate();
} catch (SQLException e) {
plugin.getLogger().warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
ConsoleLog.warning("Func savePlayerData::getPlayerWildCmdStats(Player player)");
e.printStackTrace();
}
}
......
package com.slprojects.slcraftplugin.utils;
import com.slprojects.slcraftplugin.Main;
import org.bukkit.ChatColor;
import static org.bukkit.Bukkit.getServer;
public class ConsoleLog {
public static void info(String message) {
getServer().getConsoleSender().sendMessage("[" + Main.pluginName + "] " + message);
}
public static void warning(String message) {
getServer().getConsoleSender().sendMessage(ChatColor.GOLD + Main.pluginName + "] " + message);
}
public static void danger(String message) {
getServer().getConsoleSender().sendMessage(ChatColor.RED + Main.pluginName + "] " + message);
}
public static void success(String message) {
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + Main.pluginName + "] " + message);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment