diff --git a/Plan/.idea/libraries/Maven__com_destroystokyo_paper_paper_1_12_R0_1_SNAPSHOT.xml b/Plan/.idea/libraries/Maven__com_destroystokyo_paper_paper_1_12_R0_1_SNAPSHOT.xml
new file mode 100644
index 000000000..ec40ac224
--- /dev/null
+++ b/Plan/.idea/libraries/Maven__com_destroystokyo_paper_paper_1_12_R0_1_SNAPSHOT.xml
@@ -0,0 +1,13 @@
+
* Placeholder values can be retrieved using the get method. *
- * Contains following place-holders: deaths, mobkills, playerkilss
+ * Contains following place-holders: deaths, mobkills, playerkills, avgdeaths, avgmobkills, avgplayerkills
*
* @author Rsl1122
* @since 3.5.2
*/
public class KillPart extends RawData
- * ATTENTION: TODO - Doesn't save the Locations in the locationCache.
- *
* Should only be called from Async thread
*/
public void saveCachedUserData() {
diff --git a/Plan/src/main/java/com/djrapitops/plan/database/Database.java b/Plan/src/main/java/com/djrapitops/plan/database/Database.java
index b1eb42a05..4c187e7e5 100644
--- a/Plan/src/main/java/com/djrapitops/plan/database/Database.java
+++ b/Plan/src/main/java/com/djrapitops/plan/database/Database.java
@@ -78,8 +78,27 @@ public abstract class Database {
*/
protected VersionTable versionTable;
+ /**
+ * Table representing plan_security in the database.
+ *
+ * @since 3.5.2
+ */
protected SecurityTable securityTable;
+ /**
+ * Table representing plan_worlds in the database.
+ *
+ * @since 3.6.0
+ */
+ protected WorldTable worldTable;
+
+ /**
+ * Table representing plan_world_times in the database.
+ *
+ * @since 3.6.0
+ */
+ protected WorldTimesTable worldTimesTable;
+
/**
* Super constructor.
*
@@ -343,7 +362,30 @@ public abstract class Database {
return tpsTable;
}
+ /**
+ * Used to get the security table.
+ *
+ * @return Table representing plan_security
+ */
public SecurityTable getSecurityTable() {
return securityTable;
}
+
+ /**
+ * Used to get the worlds table.
+ *
+ * @return Table representing plan_worlds
+ */
+ public WorldTable getWorldTable() {
+ return worldTable;
+ }
+
+ /**
+ * Used to get the world times table.
+ *
+ * @return Table representing plan_world_times
+ */
+ public WorldTimesTable getWorldTimesTable() {
+ return worldTimesTable;
+ }
}
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 18750f9cf..b4c711467 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
@@ -48,6 +48,8 @@ public abstract class SQLDB extends Database {
versionTable = new VersionTable(this, usingMySQL);
tpsTable = new TPSTable(this, usingMySQL);
securityTable = new SecurityTable(this, usingMySQL);
+ worldTable = new WorldTable(this, usingMySQL);
+ worldTimesTable = new WorldTimesTable(this, usingMySQL);
startConnectionPingTask();
}
@@ -118,7 +120,7 @@ public abstract class SQLDB extends Database {
}
if (newDatabase) {
Log.info("New Database created.");
- setVersion(6);
+ setVersion(7);
}
Benchmark.start("Database: Create tables");
for (Table table : getAllTables()) {
@@ -132,8 +134,8 @@ public abstract class SQLDB extends Database {
return false;
}
Benchmark.stop("Database: Create tables");
- if (!newDatabase && getVersion() < 6) {
- setVersion(6);
+ if (!newDatabase && getVersion() < 7) {
+ setVersion(7);
}
}
return true;
@@ -177,14 +179,22 @@ public abstract class SQLDB extends Database {
* @return
*/
public Table[] getAllTables() {
- return new Table[]{usersTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable, tpsTable};
+ return new Table[]{
+ usersTable, gmTimesTable, ipsTable,
+ nicknamesTable, sessionsTable, killsTable,
+ commandUseTable, tpsTable, worldTable,
+ worldTimesTable};
}
/**
* @return
*/
public Table[] getAllTablesInRemoveOrder() {
- return new Table[]{locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, usersTable, commandUseTable, tpsTable};
+ return new Table[]{
+ locationsTable, gmTimesTable, ipsTable,
+ nicknamesTable, sessionsTable, killsTable,
+ worldTimesTable, worldTable, usersTable,
+ commandUseTable, tpsTable};
}
/**
diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java
index 388c35f50..0bc030461 100644
--- a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java
+++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java
@@ -26,6 +26,9 @@ public class TPSTable extends Table {
private final String columnTPS;
private final String columnPlayers;
private final String columnCPUUsage;
+ private final String columnRAMUsage;
+ private final String columnEntities;
+ private final String columnChunksLoaded;
/**
* @param db
@@ -37,7 +40,9 @@ public class TPSTable extends Table {
columnTPS = "tps";
columnPlayers = "players_online";
columnCPUUsage = "cpu_usage";
- //TODO add new columns
+ columnRAMUsage = "ram_usage";
+ columnEntities = "entities";
+ columnChunksLoaded = "chunks_loaded";
}
@Override
@@ -47,14 +52,18 @@ public class TPSTable extends Table {
+ columnDate + " bigint NOT NULL, "
+ columnTPS + " double NOT NULL, "
+ columnPlayers + " integer NOT NULL, "
- + columnCPUUsage + " double NOT NULL"
+ + columnCPUUsage + " double NOT NULL, "
+ + columnEntities + " integer NOT NULL, "
+ + columnChunksLoaded + " integer NOT NULL"
+ ")"
- //TODO add new columns
);
int version = getVersion();
if (version < 6) {
alterTablesV6();
}
+ if (version < 7) {
+ alterTablesV7();
+ }
return true;
} catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex);
@@ -70,11 +79,26 @@ public class TPSTable extends Table {
execute("ALTER TABLE " + tableName + " ADD COLUMN " + columnCPUUsage + " double NOT NULL DEFAULT 0");
}
} catch (SQLException e) {
-
}
}
- //TODO alterTablesV7
+ private void alterTablesV7() {
+ String[] sql;
+ if (usingMySQL) {
+ sql = new String[]{
+ "ALTER TABLE " + tableName + " ADD " + columnRAMUsage + " bigint NOT NULL DEFAULT 0",
+ "ALTER TABLE " + tableName + " ADD " + columnEntities + " integer NOT NULL DEFAULT 0",
+ "ALTER TABLE " + tableName + " ADD " + columnChunksLoaded + " integer NOT NULL DEFAULT 0"
+ };
+ } else {
+ sql = new String[]{
+ "ALTER TABLE " + tableName + " ADD COLUMN " + columnRAMUsage + " bigint NOT NULL DEFAULT 0",
+ "ALTER TABLE " + tableName + " ADD COLUMN " + columnEntities + " integer NOT NULL DEFAULT 0",
+ "ALTER TABLE " + tableName + " ADD COLUMN " + columnChunksLoaded + " integer NOT NULL DEFAULT 0"
+ };
+ }
+ executeUnsafe(sql);
+ }
/**
* @return @throws SQLException
@@ -92,8 +116,10 @@ public class TPSTable extends Table {
double tps = set.getDouble(columnTPS);
int players = set.getInt(columnPlayers);
double cpuUsage = set.getDouble(columnCPUUsage);
- //TODO add new data
- data.add(new TPS(date, tps, players, cpuUsage, 0, 0, 0));
+ long ramUsage = set.getLong(columnRAMUsage);
+ int entities = set.getInt(columnEntities);
+ int chunksLoaded = set.getInt(columnChunksLoaded);
+ data.add(new TPS(date, tps, players, cpuUsage, ramUsage, entities, chunksLoaded));
}
return data;
} finally {
@@ -121,8 +147,11 @@ public class TPSTable extends Table {
+ columnDate + ", "
+ columnTPS + ", "
+ columnPlayers + ", "
- + columnCPUUsage
- + ") VALUES (?, ?, ?, ?)");
+ + columnCPUUsage + ", "
+ + columnRAMUsage + ", "
+ + columnEntities + ", "
+ + columnChunksLoaded
+ + ") VALUES (?, ?, ?, ?, ?, ?, ?)");
boolean commitRequired = false;
int i = 0;
@@ -131,6 +160,9 @@ public class TPSTable extends Table {
statement.setDouble(2, tps.getTps());
statement.setInt(3, tps.getPlayers());
statement.setDouble(4, tps.getCPUUsage());
+ statement.setLong(5, tps.getUsedMemory());
+ statement.setDouble(6, tps.getEntityCount());
+ statement.setDouble(7, tps.getChunksLoaded());
statement.addBatch();
commitRequired = true;
i++;
diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java
index 49e5b8821..7c53bcfd1 100644
--- a/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java
+++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java
@@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.database.tables;
+import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.database.Container;
import main.java.com.djrapitops.plan.database.DBUtils;
@@ -67,13 +68,28 @@ public abstract class Table {
}
/**
- * @param sql
+ * @param statement
* @return
* @throws SQLException
*/
- protected boolean execute(String sql) throws SQLException {
+ protected boolean execute(String statement) throws SQLException {
Connection connection = getConnection();
- return connection.createStatement().execute(sql);
+ return connection.createStatement().execute(statement);
+ }
+
+ /**
+ * Used to execute queries while possible SQLExceptions are suppressed.
+ *
+ * @param statements SQL statements to execute
+ */
+ protected void executeUnsafe(String... statements) {
+ Verify.nullCheck(statements);
+ for (String statement : statements) {
+ try {
+ execute(statement);
+ } catch (SQLException e) {
+ }
+ }
}
/**
diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java
index a1200de1f..0382f75c6 100644
--- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java
+++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java
@@ -123,9 +123,9 @@ public class UsersTable extends Table {
}
private void alterTablesV4() {
- String[] queries;
+ String[] statements;
if (usingMySQL) {
- queries = new String[]{
+ statements = new String[]{
"ALTER TABLE " + tableName + " ADD " + columnContainsBukkitData + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnOP + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnBanned + " boolean NOT NULL DEFAULT 0",
@@ -133,7 +133,7 @@ public class UsersTable extends Table {
"ALTER TABLE " + tableName + " ADD " + columnRegistered + " bigint NOT NULL DEFAULT 0"
};
} else {
- queries = new String[]{
+ statements = new String[]{
"ALTER TABLE " + tableName + " ADD COLUMN " + columnContainsBukkitData + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnOP + " boolean NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnBanned + " boolean NOT NULL DEFAULT 0",
@@ -141,34 +141,24 @@ public class UsersTable extends Table {
"ALTER TABLE " + tableName + " ADD COLUMN " + columnRegistered + " bigint NOT NULL DEFAULT 0"
};
}
- for (String query : queries) {
- try {
- execute(query);
- } catch (Exception e) {
- }
- }
+ executeUnsafe(statements);
}
private void alterTablesV3() {
- String[] queries;
+ String[] statements;
if (usingMySQL) {
- queries = new String[]{
+ statements = new String[]{
"ALTER TABLE " + tableName + " ADD " + columnDeaths + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD " + columnMobKills + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " DROP INDEX " + columnPlayerKills
};
} else {
- queries = new String[]{
+ statements = new String[]{
"ALTER TABLE " + tableName + " ADD COLUMN " + columnDeaths + " integer NOT NULL DEFAULT 0",
"ALTER TABLE " + tableName + " ADD COLUMN " + columnMobKills + " integer NOT NULL DEFAULT 0"
};
}
- for (String query : queries) {
- try {
- execute(query);
- } catch (Exception e) {
- }
- }
+ executeUnsafe(statements);
}
/**
@@ -870,12 +860,4 @@ public class UsersTable extends Table {
close(statement);
}
}
-
- /**
- * @param uuids
- * @return
- */
- public Map
+ * Used for storing id references to world names.
+ *
+ * @author Rsl1122
+ * @since 3.6.0 / Database version 7
+ */
+public class WorldTable extends Table {
+
+ private final String columnWorldId;
+ private final String columnWorldName;
+
+ /**
+ * Constructor.
+ *
+ * @param db Database this table is a part of.
+ * @param usingMySQL Database is a MySQL database.
+ */
+ public WorldTable(SQLDB db, boolean usingMySQL) {
+ super("plan_worlds", db, usingMySQL);
+ columnWorldId = "world_id";
+ columnWorldName = "world_name";
+ }
+
+ @Override
+ public boolean createTable() {
+ try {
+ execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ + columnWorldId + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
+ + columnWorldName + " varchar(100) NOT NULL"
+ + (usingMySQL ? ", PRIMARY KEY (" + columnWorldId + ")" : "")
+ + ")"
+ );
+ return true;
+ } catch (SQLException ex) {
+ Log.toLog(this.getClass().getName(), ex);
+ return false;
+ }
+ }
+
+ /**
+ * Used to get the available world names.
+ *
+ * @return List of all world names in the database.
+ * @throws SQLException Database error occurs.
+ */
+ public List
+ * Already saved names will not be saved.
+ *
+ * @param worlds List of world names.
+ * @throws SQLException Database error occurs.
+ */
+ public void saveWorlds(List