Replace printStackTrace with Logger.throwing in various classes
The changes made in these classes are intended to improve error handling and visibility. Instead of simply printing the StackTrace, the Logger.throwing method is now used to send error messages to the logger in a more controlled manner. This should facilitate better error tracking and resolution. The affected classes include database, configuration, and quest implementation classes.
This commit is contained in:
parent
8a22f5188e
commit
46bfb4fd65
|
|
@ -54,8 +54,7 @@ abstract class AbstractConfig {
|
||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
throw new RuntimeException(ex.getCause());
|
throw new RuntimeException(ex.getCause());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.severe("Error invoking %.", method.toString());
|
Logger.throwing(AbstractConfig.class.getName(), "readConfig", ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +68,7 @@ abstract class AbstractConfig {
|
||||||
yaml.save(file);
|
yaml.save(file);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.severe("Could not save %.", file.toString());
|
Logger.severe("Could not save %.", file.toString());
|
||||||
ex.printStackTrace();
|
Logger.throwing(AbstractConfig.class.getName(), "save", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.altitudequests.config;;
|
package com.alttd.altitudequests.config;
|
||||||
|
|
||||||
import com.alttd.altitudequests.objects.variants.BreedMobsQuestObject;
|
import com.alttd.altitudequests.objects.variants.BreedMobsQuestObject;
|
||||||
import com.alttd.altitudequests.objects.variants.CollectDropsQuestObject;
|
import com.alttd.altitudequests.objects.variants.CollectDropsQuestObject;
|
||||||
|
|
@ -67,7 +67,7 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
Logger.info("Loaded Mine quest " + key);
|
Logger.info("Loaded Mine quest " + key);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(QuestsConfig.class.getName(), "loadMineQuest", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MINE_QUEST_NAME = config.getString("mining.name", MINE_QUEST_NAME);
|
MINE_QUEST_NAME = config.getString("mining.name", MINE_QUEST_NAME);
|
||||||
|
|
@ -106,7 +106,7 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
Logger.info("Loaded Kill mob quest " + key);
|
Logger.info("Loaded Kill mob quest " + key);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(QuestsConfig.class.getName(), "loadKillMobQuest", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KILL_MOB_QUEST_NAME = config.getString("kill_mobs.name", KILL_MOB_QUEST_NAME);
|
KILL_MOB_QUEST_NAME = config.getString("kill_mobs.name", KILL_MOB_QUEST_NAME);
|
||||||
|
|
@ -145,7 +145,7 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
Logger.info("Loaded Collect drops quest " + key);
|
Logger.info("Loaded Collect drops quest " + key);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(QuestsConfig.class.getName(), "loadCollectQuest", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
COLLECT_DROPS_QUEST_NAME = config.getString("collect_drops.name", COLLECT_DROPS_QUEST_NAME);
|
COLLECT_DROPS_QUEST_NAME = config.getString("collect_drops.name", COLLECT_DROPS_QUEST_NAME);
|
||||||
|
|
@ -195,7 +195,7 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
Logger.info("Loaded Collect drops quest " + key);
|
Logger.info("Loaded Collect drops quest " + key);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(QuestsConfig.class.getName(), "loadOtherQuests", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OTHER_QUEST_NAME = config.getString("other.name", OTHER_QUEST_NAME);
|
OTHER_QUEST_NAME = config.getString("other.name", OTHER_QUEST_NAME);
|
||||||
|
|
@ -232,7 +232,7 @@ public class QuestsConfig extends AbstractConfig {
|
||||||
Logger.info("Loaded Breed mob quest " + key);
|
Logger.info("Loaded Breed mob quest " + key);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(QuestsConfig.class.getName(), "loadBreedMobQuest", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BREED_MOB_QUEST_NAME = config.getString("breed_mobs.name", BREED_MOB_QUEST_NAME);
|
BREED_MOB_QUEST_NAME = config.getString("breed_mobs.name", BREED_MOB_QUEST_NAME);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class Database {
|
||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Database.class.getName(), "init", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Run all create table functions
|
//Run all create table functions
|
||||||
|
|
@ -45,8 +45,7 @@ public class Database {
|
||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
throw new RuntimeException(ex.getCause());
|
throw new RuntimeException(ex.getCause());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.severe("Error invoking %.", method.toString());
|
Logger.throwing(Database.class.getName(), "init", ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +68,7 @@ public class Database {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Database.class.getName(), "openConnection", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = DriverManager.getConnection(
|
connection = DriverManager.getConnection(
|
||||||
|
|
@ -83,7 +82,7 @@ public class Database {
|
||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Database.class.getName(), "getConnection", e);
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +102,7 @@ public class Database {
|
||||||
")";
|
")";
|
||||||
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
|
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Database.class.getName(), "createUserPointsTable", e);
|
||||||
Logger.severe("Error while trying to create user point table");
|
Logger.severe("Error while trying to create user point table");
|
||||||
Logger.severe("Shutting down AltitudeQuests");
|
Logger.severe("Shutting down AltitudeQuests");
|
||||||
Bukkit.getPluginManager().disablePlugin(AQuest.getInstance());
|
Bukkit.getPluginManager().disablePlugin(AQuest.getInstance());
|
||||||
|
|
@ -121,9 +120,8 @@ public class Database {
|
||||||
")";
|
")";
|
||||||
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
|
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Database.class.getName(), "createQuestLogTable", e);
|
||||||
Logger.severe("Error while trying to create quest log table");
|
Logger.severe("Error while trying to create quest log table\nShutting down AltitudeQuests");
|
||||||
Logger.severe("Shutting down AltitudeQuests");
|
|
||||||
Bukkit.getPluginManager().disablePlugin(AQuest.getInstance());
|
Bukkit.getPluginManager().disablePlugin(AQuest.getInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public abstract class Quest {
|
||||||
if (resultSet.next())
|
if (resultSet.next())
|
||||||
return resultSet.getInt("total");
|
return resultSet.getInt("total");
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(Quest.class.getName(), "loadQuestsDoneThisMonth", exception);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -127,11 +127,11 @@ public abstract class Quest {
|
||||||
} catch (InvocationTargetException | IllegalAccessException | InstantiationException |
|
} catch (InvocationTargetException | IllegalAccessException | InstantiationException |
|
||||||
NoSuchMethodException e) {
|
NoSuchMethodException e) {
|
||||||
player.sendMiniMessage("<red>Unable to create quest, contact an admin</red>", null);
|
player.sendMiniMessage("<red>Unable to create quest, contact an admin</red>", null);
|
||||||
e.printStackTrace();
|
Logger.throwing(Quest.class.getName(), "createDailyQuest", e);
|
||||||
Logger.severe("% does not have a constructor with a Player input or has improper access.", questClass.getName());
|
Logger.severe("% does not have a constructor with a Player input or has improper access.", questClass.getName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
player.sendMiniMessage("<red>Unable to create quest, contact an admin</red>", null);
|
player.sendMiniMessage("<red>Unable to create quest, contact an admin</red>", null);
|
||||||
e.printStackTrace();
|
Logger.throwing(Quest.class.getName(), "createDailyQuest", e);
|
||||||
Logger.severe("% could not be created due to invalid namespace key or variant.", questClass.getName());
|
Logger.severe("% could not be created due to invalid namespace key or variant.", questClass.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +198,7 @@ public abstract class Quest {
|
||||||
putDailyQuest(uuid, quest1);
|
putDailyQuest(uuid, quest1);
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
|
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
|
||||||
InvocationTargetException e) {
|
InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Quest.class.getName(), "loadDailyQuest", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -281,9 +281,8 @@ public abstract class Quest {
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
Logger.info("% finished their quest", uuidString);
|
Logger.info("% finished their quest", uuidString);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.throwing(Quest.class.getName(), "saveDone", e);
|
||||||
Logger.severe("Error while trying to create quest log table");
|
Logger.severe("Error while trying to create quest log table\nShutting down AltitudeQuests");
|
||||||
Logger.severe("Shutting down AltitudeQuests");
|
|
||||||
Bukkit.getPluginManager().disablePlugin(AQuest.getInstance());
|
Bukkit.getPluginManager().disablePlugin(AQuest.getInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public class BreedMobsQuest extends Quest {
|
||||||
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(BreedMobsQuest.class.getName(), "save", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ public class CollectDropsQuest extends Quest {
|
||||||
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(CollectDropsQuest.class.getName(), "save", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ public class KillMobsQuest extends Quest {
|
||||||
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(KillMobsQuest.class.getName(), "save", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ public class MineQuest extends Quest {
|
||||||
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(MineQuest.class.getName(), "save", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ public class OtherQuest extends Quest {
|
||||||
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
statement.setInt(15, isRewardReceived() ? 1 : 0);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(OtherQuest.class.getName(), "save", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class LoadUser extends BukkitRunnable {
|
||||||
Logger.warning("Unable to load quest for %, creating new quest...", uuid.toString());
|
Logger.warning("Unable to load quest for %, creating new quest...", uuid.toString());
|
||||||
}
|
}
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
Logger.throwing(LoadUser.class.getName(), "run", exception);
|
||||||
}
|
}
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
Logger.info("Creating new daily quest for %", uuid.toString());
|
Logger.info("Creating new daily quest for %", uuid.toString());
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,8 @@ public class Logger {
|
||||||
}
|
}
|
||||||
logger.severe(severe);
|
logger.severe(severe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void throwing(String sourceClass, String sourceMethod, Exception e) {
|
||||||
|
logger.throwing(sourceClass, sourceMethod, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user