From dd6806ac2da71a5126239c98e75142efb43b16c1 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 10 Jan 2017 17:07:19 +0200 Subject: [PATCH] Stop checking if plugin is disabled --- com/gamingmesh/jobs/config/GeneralConfigManager.java | 6 +++--- com/gamingmesh/jobs/dao/JobsDAO.java | 7 ++++++- com/gamingmesh/jobs/dao/JobsDAOMySQL.java | 8 ++++---- com/gamingmesh/jobs/dao/JobsDAOSQLite.java | 8 ++++---- com/gamingmesh/jobs/i18n/Language.java | 1 + 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/com/gamingmesh/jobs/config/GeneralConfigManager.java b/com/gamingmesh/jobs/config/GeneralConfigManager.java index 34fe20f1..a2224546 100644 --- a/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -383,7 +383,7 @@ public class GeneralConfigManager { } else { Jobs.getPluginLogger().warning("Invalid storage method! Changing method to sqlite!"); c.getC().set("storage-method", "sqlite"); - Jobs.setDAO(JobsDAOSQLite.initialize()); + startSqlite(); } c.getW().addComment("mysql-username", "Requires Mysql."); @@ -858,10 +858,10 @@ public class GeneralConfigManager { String database = config.getString("mysql-database"); String prefix = config.getString("mysql-table-prefix"); if (plugin.isEnabled()) - Jobs.setDAO(JobsDAOMySQL.initialize(hostname, database, username, password, prefix)); + Jobs.setDAO(JobsDAOMySQL.initialize(plugin, hostname, database, username, password, prefix)); } public synchronized void startSqlite() { - Jobs.setDAO(JobsDAOSQLite.initialize()); + Jobs.setDAO(JobsDAOSQLite.initialize(plugin)); } } diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 8a4b4511..1a574dd9 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -67,8 +67,10 @@ public abstract class JobsDAO { private JobsConnectionPool pool; private String prefix; private HashMap> map = new HashMap>(); + private Jobs plugin; - protected JobsDAO(String driverName, String url, String username, String password, String prefix) { + protected JobsDAO(Jobs plugin, String driverName, String url, String username, String password, String prefix) { + this.plugin = plugin; this.prefix = prefix; try { pool = new JobsConnectionPool(driverName, url, username, password); @@ -845,6 +847,9 @@ public abstract class JobsDAO { // synchronized (jPlayer.saveLock) { jPlayer.progression.clear(); for (JobsDAOData jobdata : list) { + if (!plugin.isEnabled()) + return null; + // add the job Job job = Jobs.getJob(jobdata.getJobName()); if (job == null) diff --git a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java index 0e3c48a3..f0b3f1f4 100644 --- a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java +++ b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java @@ -32,13 +32,13 @@ import com.gamingmesh.jobs.stuff.UUIDUtil; public class JobsDAOMySQL extends JobsDAO { private String database; - private JobsDAOMySQL(String hostname, String database, String username, String password, String prefix) { - super("com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database, username, password, prefix); + private JobsDAOMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix) { + super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database, username, password, prefix); this.database = database; } - public static JobsDAOMySQL initialize(String hostname, String database, String username, String password, String prefix) { - JobsDAOMySQL dao = new JobsDAOMySQL(hostname, database, username, password, prefix); + public static JobsDAOMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix) { + JobsDAOMySQL dao = new JobsDAOMySQL(plugin, hostname, database, username, password, prefix); try { dao.setUp(); } catch (SQLException e) { diff --git a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java index b2f865ac..6aac6805 100644 --- a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java +++ b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java @@ -29,8 +29,8 @@ import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.stuff.UUIDUtil; public class JobsDAOSQLite extends JobsDAO { - public static JobsDAOSQLite initialize() { - JobsDAOSQLite dao = new JobsDAOSQLite(); + public static JobsDAOSQLite initialize(Jobs plugin) { + JobsDAOSQLite dao = new JobsDAOSQLite(plugin); File dir = Jobs.getFolder(); if (!dir.exists()) dir.mkdirs(); @@ -42,8 +42,8 @@ public class JobsDAOSQLite extends JobsDAO { return dao; } - private JobsDAOSQLite() { - super("org.sqlite.JDBC", "jdbc:sqlite:" + new File(Jobs.getFolder(), "jobs.sqlite.db").getPath(), null, null, ""); + private JobsDAOSQLite(Jobs plugin) { + super(plugin, "org.sqlite.JDBC", "jdbc:sqlite:" + new File(Jobs.getFolder(), "jobs.sqlite.db").getPath(), null, null, ""); } private static void close(ResultSet res) { diff --git a/com/gamingmesh/jobs/i18n/Language.java b/com/gamingmesh/jobs/i18n/Language.java index 8c59bdbb..e1cc7101 100644 --- a/com/gamingmesh/jobs/i18n/Language.java +++ b/com/gamingmesh/jobs/i18n/Language.java @@ -30,6 +30,7 @@ public class Language { public Language(Jobs plugin) { this.plugin = plugin; + reload(); } /**