Fixed NPE when database was not initialized

This commit is contained in:
Eric 2016-11-20 12:52:05 +01:00
parent 198f83c738
commit dcd50bad33

View File

@ -42,7 +42,6 @@ public class ShopChest extends JavaPlugin {
private String latestVersion = "";
private String downloadLink = "";
private ShopUtils shopUtils;
private File debugLogFile;
private FileWriter fw;
private WorldGuardPlugin worldGuard;
@ -73,7 +72,7 @@ public class ShopChest extends JavaPlugin {
config = new Config(this);
if (config.enable_debug_log) {
debugLogFile = new File(getDataFolder(), "debug.txt");
File debugLogFile = new File(getDataFolder(), "debug.txt");
try {
if (!debugLogFile.exists()) {
@ -308,6 +307,7 @@ public class ShopChest extends JavaPlugin {
public void onDisable() {
debug("Disabling ShopChest...");
if (database != null) {
int highestId = database.getHighestID();
for (int i = 1; i <= highestId; i++) {
@ -320,6 +320,7 @@ public class ShopChest extends JavaPlugin {
}
database.disconnect();
}
if (fw != null && config.enable_debug_log) {
try {
@ -336,7 +337,7 @@ public class ShopChest extends JavaPlugin {
* @param message Message to print
*/
public void debug(String message) {
if (config.enable_debug_log) {
if (config.enable_debug_log && fw != null) {
try {
Calendar c = Calendar.getInstance();
String timestamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(c.getTime());
@ -354,7 +355,7 @@ public class ShopChest extends JavaPlugin {
* @param throwable {@link Throwable} whose stacktrace will be printed
*/
public void debug(Throwable throwable) {
if (config.enable_debug_log) {
if (config.enable_debug_log && fw != null) {
PrintWriter pw = new PrintWriter(fw);
throwable.printStackTrace(pw);
pw.flush();