diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 5dd652e63..ed940a2ce 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -20,7 +20,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.scheduler.BukkitRunnable; -/* TODO 2.1.0 +/* TODO 2.2.0 Placeholder API Immutable InspectCache ? Recent players 25% @@ -69,6 +69,7 @@ public class Plan extends JavaPlugin { saveConfig(); + log(MiscUtils.checkVersion()); log("Database init.."); if (initDatabase()) { log("Database initiated."); @@ -84,8 +85,6 @@ public class Plan extends JavaPlugin { this.analysisCache = new AnalysisCacheHandler(this); registerListeners(); - log(MiscUtils.checkVersion()); - getCommand("plan").setExecutor(new PlanCommand(this)); this.api = new API(this); @@ -177,7 +176,9 @@ public class Plan extends JavaPlugin { pluginManager.registerEvents(new PlanPlayerListener(this), this); pluginManager.registerEvents(new PlanGamemodeChangeListener(this), this); pluginManager.registerEvents(new PlanCommandPreprocessListener(this), this); - pluginManager.registerEvents(new PlanPlayerMoveListener(this), this); + if (getConfig().getBoolean("Settings.Data.GatherLocations")) { + pluginManager.registerEvents(new PlanPlayerMoveListener(this), this); + } } private boolean initDatabase() { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java index 0853b3819..730dab1a0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java @@ -115,11 +115,13 @@ public class DataCacheHandler { if (cache) { if (dataCache.get(uuid) == null) { UserData uData = db.getUserData(uuid); - if (uData.getPlanLiteData() == null) { - getPlanLiteHandler().handleEvents(uData.getName(), uData); + if (uData != null) { + if (uData.getPlanLiteData() == null) { + getPlanLiteHandler().handleEvents(uData.getName(), uData); + } + dataCache.put(uuid, uData); + plugin.log("Added " + uuid.toString() + " to Cache."); } - dataCache.put(uuid, uData); - plugin.log("Added " + uuid.toString() + " to Cache."); } return dataCache.get(uuid); } else { @@ -127,8 +129,10 @@ public class DataCacheHandler { return dataCache.get(uuid); } UserData uData = db.getUserData(uuid); - if (uData.getPlanLiteData() == null) { - getPlanLiteHandler().handleEvents(uData.getName(), uData); + if (uData != null) { + if (uData.getPlanLiteData() == null) { + getPlanLiteHandler().handleEvents(uData.getName(), uData); + } } return uData; } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index c526a7ddf..ff069f025 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -154,14 +154,13 @@ public abstract class SQLDB extends Database { if (connection == null || connection.isClosed()) { return false; } - -// ResultSet set = connection.prepareStatement(supportsModification ? ("SHOW TABLES LIKE '" + userName + "'") : "SELECT name FROM sqlite_master WHERE type='table' AND name='" + userName + "'").executeQuery(); - -// boolean newDatabase = set.next(); -// set.close(); - + boolean usingMySQL = getConfigName().toLowerCase().equals("mysql"); + System.out.println(usingMySQL ? "Using MySQL":"Not using MySQL"+getConfigName()); + // ResultSet set = connection.prepareStatement(supportsModification ? ("SHOW TABLES LIKE '" + userName + "'") : "SELECT name FROM sqlite_master WHERE type='table' AND name='" + userName + "'").executeQuery(); + // boolean newDatabase = set.next(); + // set.close(); query("CREATE TABLE IF NOT EXISTS " + userName + " (" - + userColumnID + " integer PRIMARY KEY, " + + userColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", " + userColumnUUID + " varchar(36) NOT NULL, " + userColumnDemAge + " integer NOT NULL, " + userColumnDemGender + " varchar(8) NOT NULL, " @@ -171,15 +170,17 @@ public abstract class SQLDB extends Database { + userColumnPlayTime + " bigint NOT NULL, " + userColumnLoginTimes + " integer NOT NULL, " + userColumnLastPlayed + " bigint NOT NULL" + + (usingMySQL ? ", PRIMARY KEY (" + userColumnID + ")" : "") + ")" ); query("CREATE TABLE IF NOT EXISTS " + locationName + " (" - + locationColumnID + " integer PRIMARY KEY, " + + locationColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", " + locationColumnUserID + " integer NOT NULL, " + locationColumnCoordinatesX + " integer NOT NULL, " + locationColumnCoordinatesZ + " integer NOT NULL, " + locationColumnWorld + " varchar(64) NOT NULL, " + + (usingMySQL ? "PRIMARY KEY (" + userColumnID + "), " : "") + "FOREIGN KEY(" + locationColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")" + ")" ); @@ -390,13 +391,17 @@ public abstract class SQLDB extends Database { + commanduseColumnCommand + ", " + commanduseColumnTimesUsed + ") VALUES (?, ?)"); + boolean commitRequired = false; for (String key : data.keySet()) { statement.setString(1, key); statement.setInt(2, data.get(key)); statement.addBatch(); + commitRequired = true; } statement.executeBatch(); - connection.commit(); + if (commitRequired) { + connection.commit(); + } statement.close(); connection.setAutoCommit(true); @@ -582,13 +587,14 @@ public abstract class SQLDB extends Database { try { connection.setAutoCommit(false); PreparedStatement uStatement = connection.prepareStatement(uSQL); + boolean commitRequired = false; for (UserData uData : data) { int userId = getUserId(uData.getUuid().toString()); if (userId == -1) { saveLast.add(uData); continue; } - + uStatement.setInt(1, uData.getDemData().getAge()); uStatement.setString(2, uData.getDemData().getGender().toString().toLowerCase()); uStatement.setString(3, uData.getDemData().getGeoLocation()); @@ -603,10 +609,13 @@ public abstract class SQLDB extends Database { uStatement.setInt(7, uData.getLoginTimes()); uStatement.setLong(8, uData.getLastPlayed()); uStatement.setString(9, uData.getUuid().toString()); - uStatement.addBatch(); + uStatement.addBatch(); + commitRequired = true; } uStatement.executeBatch(); - connection.commit(); + if (commitRequired) { + connection.commit(); + } uStatement.close(); connection.setAutoCommit(true); data.removeAll(saveLast); @@ -619,7 +628,7 @@ public abstract class SQLDB extends Database { } for (UserData userData : saveLast) { saveUserData(userData.getUuid(), userData); - } + } } catch (SQLException | NullPointerException e) { e.printStackTrace(); } @@ -718,15 +727,19 @@ public abstract class SQLDB extends Database { + locationColumnCoordinatesZ + ", " + locationColumnWorld + ") VALUES (?, ?, ?, ?)"); + boolean commitRequired = false; for (Location location : locations) { saveStatement.setInt(1, userId); saveStatement.setInt(2, (int) location.getBlockX()); saveStatement.setInt(3, (int) location.getBlockZ()); saveStatement.setString(4, location.getWorld().getName()); saveStatement.addBatch(); + commitRequired = true; } saveStatement.executeBatch(); - connection.commit(); + if (commitRequired) { + connection.commit(); + } saveStatement.close(); connection.setAutoCommit(true); } catch (SQLException e) { @@ -746,13 +759,17 @@ public abstract class SQLDB extends Database { + nicknamesColumnUserID + ", " + nicknamesColumnNick + ") VALUES (?, ?)"); + boolean commitRequired = false; for (String name : names) { statement.setInt(1, userId); statement.setString(2, name); statement.addBatch(); + commitRequired = true; } statement.executeBatch(); - connection.commit(); + if (commitRequired) { + connection.commit(); + } statement.close(); connection.setAutoCommit(true); @@ -774,13 +791,17 @@ public abstract class SQLDB extends Database { + ipsColumnUserID + ", " + ipsColumnIP + ") VALUES (?, ?)"); + boolean commitRequired = false; for (InetAddress ip : ips) { statement.setInt(1, userId); statement.setString(2, ip.getHostAddress()); statement.addBatch(); + commitRequired = true; } statement.executeBatch(); - connection.commit(); + if (commitRequired) { + connection.commit(); + } statement.close(); connection.setAutoCommit(true); @@ -830,7 +851,7 @@ public abstract class SQLDB extends Database { @Override public void clean() { checkConnection(); - plugin.log("DATABASE-SQLDB\nCleaning DB not implemented"); + plugin.log("Database Cleaning has not yet been implemented."); } public void removeAllData() { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java index ded933ba7..0372bdaac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java @@ -101,7 +101,7 @@ public class FormatUtils { } /** - * Turns the version string into a double + * Turns the version string into a integer * * @param versionString String - number format 1.1.1 * @return parsed double - for example 1,11 diff --git a/Plan/src/main/resources/analysis.html b/Plan/src/main/resources/analysis.html index 36bb69599..ebbc4258f 100644 --- a/Plan/src/main/resources/analysis.html +++ b/Plan/src/main/resources/analysis.html @@ -28,9 +28,9 @@ %playerchartweek%
Recent logins: %recentlogins%
+