mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 02:57:52 +01:00
Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics
This commit is contained in:
commit
ec4e3cce91
@ -144,7 +144,6 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
saveConfig();
|
||||
Benchmark.stop("Enable", "Copy default config");
|
||||
|
||||
processingQueue = new ProcessingQueue();
|
||||
|
||||
Benchmark.start("Init Database");
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
@ -159,6 +158,8 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
Log.error("WebServer was not successfully initialized.");
|
||||
}
|
||||
|
||||
processingQueue = new ProcessingQueue();
|
||||
|
||||
serverInfoManager = new ServerInfoManager(this);
|
||||
infoManager = new InformationManager(this);
|
||||
webServer.setInfoManager(infoManager);
|
||||
|
@ -5,6 +5,7 @@ import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.SubCommand;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
@ -12,6 +13,8 @@ import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to clear a database of all data.
|
||||
*
|
||||
@ -80,12 +83,12 @@ public class ManageClearCommand extends SubCommand {
|
||||
try {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
|
||||
if (database.removeAllData()) {
|
||||
database.removeAllData();
|
||||
// TODO Clear active session of all users & start new ones
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_CLEAR_SUCCESS).toString());
|
||||
} else {
|
||||
} catch (SQLException e) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||
}
|
||||
Log.toLog(this.getClass().getSimpleName() + "/" + this.getTaskName(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
|
@ -85,11 +85,8 @@ public class ManageRemoveCommand extends SubCommand {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
try {
|
||||
// TODO Clear active session of user & start new one
|
||||
if (plugin.getDB().removeAccount(uuid)) {
|
||||
plugin.getDB().removeAccount(uuid);
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, plugin.getDB().getConfigName()));
|
||||
} else {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||
|
@ -49,7 +49,7 @@ public class AnalysisData extends RawData {
|
||||
joinInfoPart = new JoinInfoPart();
|
||||
playerCountPart = new PlayerCountPart();
|
||||
playtimePart = new PlaytimePart();
|
||||
killPart = new KillPart();
|
||||
killPart = new KillPart(joinInfoPart);
|
||||
tpsPart = new TPSPart();
|
||||
activityPart = new ActivityPart(joinInfoPart, tpsPart);
|
||||
worldPart = new WorldPart();
|
||||
|
@ -30,7 +30,7 @@ import java.util.stream.Collectors;
|
||||
* ${playersNewAverageDay} - (Number)
|
||||
* ${playersNewAverageWeek} - (Number)
|
||||
* ${playersNewAverageMonth} - (Number)
|
||||
* //TODO ${tableBodySessions}, ${sessionCount}, ${lastPeakTime}, ${playersLastPeak}, ${bestPeakTime}, ${playersBestPeak}
|
||||
* //TODO ${tableBodySessions}
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
|
@ -1,5 +1,13 @@
|
||||
package main.java.com.djrapitops.plan.data.analysis;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.PlayerKill;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Part responsible for all Death related analysis.
|
||||
* <p>
|
||||
@ -15,43 +23,32 @@ package main.java.com.djrapitops.plan.data.analysis;
|
||||
*/
|
||||
public class KillPart extends RawData {
|
||||
|
||||
private final JoinInfoPart joinInfoPart;
|
||||
|
||||
private long playerKills;
|
||||
private long mobKills;
|
||||
private long deaths;
|
||||
|
||||
public KillPart() {
|
||||
public KillPart(JoinInfoPart joinInfoPart) {
|
||||
this.joinInfoPart = joinInfoPart;
|
||||
|
||||
playerKills = 0;
|
||||
mobKills = 0;
|
||||
deaths = 0;
|
||||
}
|
||||
|
||||
// TODO JoinInfo Part, sessions for kills.
|
||||
|
||||
@Override
|
||||
public void analyse() {
|
||||
addValue("deathCount", deaths);
|
||||
List<Session> sessions = joinInfoPart.getAllSessions();
|
||||
deaths += sessions.stream().mapToLong(Session::getDeaths).sum();
|
||||
mobKills += sessions.stream().mapToLong(Session::getMobKills).sum();
|
||||
playerKills += sessions.stream().map(Session::getPlayerKills).mapToLong(Collection::size).sum();
|
||||
|
||||
addValue("deathCount", this.deaths);
|
||||
addValue("mobKillCount", mobKills);
|
||||
addValue("killCount", playerKills);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds kills to the dataset.
|
||||
*
|
||||
* @param amount amount of kills
|
||||
* @throws IllegalArgumentException if kills is null
|
||||
*/
|
||||
public void addKills(long amount) {
|
||||
playerKills += amount;
|
||||
}
|
||||
|
||||
public void addMobKills(long amount) {
|
||||
mobKills += amount;
|
||||
}
|
||||
|
||||
public void addDeaths(long amount) {
|
||||
deaths += amount;
|
||||
}
|
||||
|
||||
public long getPlayerKills() {
|
||||
return playerKills;
|
||||
}
|
||||
@ -63,4 +60,8 @@ public class KillPart extends RawData {
|
||||
public long getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
|
||||
public void addKills(Map<UUID, List<PlayerKill>> playerKills) {
|
||||
this.playerKills += playerKills.values().stream().mapToLong(Collection::size).sum();
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,7 @@ import java.util.UUID;
|
||||
* Placeholder values can be retrieved using the get method.
|
||||
* <p>
|
||||
* Contains following placeholders after analyzed:
|
||||
* ${playersTotal}
|
||||
* //TODO ${playersOnline}, ${playersMax}
|
||||
* ${playersTotal}, ${ops}
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
@ -31,6 +30,7 @@ public class PlayerCountPart extends RawData {
|
||||
|
||||
@Override
|
||||
public void analyse() {
|
||||
addValue("ops", ops.size());
|
||||
addValue("playersTotal", uuids.size());
|
||||
}
|
||||
|
||||
|
@ -185,19 +185,18 @@ public abstract class Database {
|
||||
* Removes all data related to an account from the database.
|
||||
*
|
||||
* @param uuid UUID of the account.
|
||||
* @return Success of the removal.
|
||||
* @throws SQLException If a database error occurs.
|
||||
*/
|
||||
public abstract boolean removeAccount(UUID uuid) throws SQLException;
|
||||
public abstract void removeAccount(UUID uuid) throws SQLException;
|
||||
|
||||
/**
|
||||
* Used to clear all data from the database.
|
||||
* <p>
|
||||
* Uses DELETE * FROM table.
|
||||
*
|
||||
* @return Success of removal.
|
||||
* @throws SQLException if remove fails.
|
||||
*/
|
||||
public abstract boolean removeAllData();
|
||||
public abstract void removeAllData() throws SQLException;
|
||||
|
||||
/**
|
||||
* Used to fetch the saved UUIDs in the users table.
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.databases;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
@ -65,13 +67,28 @@ public abstract class SQLDB extends Database {
|
||||
try {
|
||||
setupDataSource();
|
||||
setupDatabase();
|
||||
clean();
|
||||
scheduleClean(10L);
|
||||
} finally {
|
||||
Benchmark.stop("Database", benchName);
|
||||
Log.logDebug("Database");
|
||||
}
|
||||
}
|
||||
|
||||
public void scheduleClean(long secondsDelay) {
|
||||
plugin.getRunnableFactory().createNew(new AbsRunnable("DB Clean Task") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
clean();
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
} finally {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * secondsDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures connection functions correctly and all tables exist.
|
||||
* <p>
|
||||
@ -200,9 +217,9 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeAccount(UUID uuid) throws SQLException {
|
||||
public void removeAccount(UUID uuid) throws SQLException {
|
||||
if (uuid == null) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -215,45 +232,30 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
|
||||
UserIDTable table = (UserIDTable) t;
|
||||
if (!table.removeUser(uuid)) {
|
||||
throw new IllegalStateException("Removal Failed");
|
||||
table.removeUser(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return false;
|
||||
} finally {
|
||||
Benchmark.stop("Database", "Remove Account");
|
||||
setAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
private void clean() throws DatabaseInitException {
|
||||
private void clean() throws SQLException {
|
||||
Log.info("Cleaning the database.");
|
||||
try {
|
||||
tpsTable.clean();
|
||||
Log.info("Clean complete.");
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseInitException("Database Clean failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAllData() {
|
||||
public void removeAllData() throws SQLException {
|
||||
setStatus("Clearing all data");
|
||||
try {
|
||||
for (Table table : getAllTablesInRemoveOrder()) {
|
||||
if (!table.removeAllData()) {
|
||||
return false;
|
||||
table.removeAllData();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} finally {
|
||||
setAvailable();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.Action;
|
||||
@ -15,9 +16,7 @@ import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Table that is in charge of storing actions.
|
||||
@ -41,10 +40,21 @@ public class ActionsTable extends UserIDTable {
|
||||
private final String columnAdditionalInfo = "additional_info";
|
||||
|
||||
private final ServerTable serverTable;
|
||||
private String insertStatement;
|
||||
|
||||
public ActionsTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_actions", db, usingMySQL);
|
||||
serverTable = db.getServerTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnServerID + ", "
|
||||
+ columnActionID + ", "
|
||||
+ columnDate + ", "
|
||||
+ columnAdditionalInfo
|
||||
+ ") VALUES ("
|
||||
+ usersTable.statementSelectID + ", "
|
||||
+ serverTable.statementSelectServerID + ", "
|
||||
+ "?, ?, ?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,17 +74,8 @@ public class ActionsTable extends UserIDTable {
|
||||
public void insertAction(UUID uuid, Action action) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnServerID + ", "
|
||||
+ columnActionID + ", "
|
||||
+ columnDate + ", "
|
||||
+ columnAdditionalInfo
|
||||
+ ") VALUES ("
|
||||
+ usersTable.statementSelectID + ", "
|
||||
+ serverTable.statementSelectServerID + ", "
|
||||
+ "?, ?, ?)"
|
||||
);
|
||||
|
||||
statement = prepareStatement(insertStatement);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, Plan.getServerUUID().toString());
|
||||
statement.setInt(3, action.getDoneAction().getId());
|
||||
@ -103,6 +104,7 @@ public class ActionsTable extends UserIDTable {
|
||||
statement = prepareStatement(Select.from(tableName, "*")
|
||||
.where(columnUserID + "=" + usersTable.statementSelectID)
|
||||
.toString());
|
||||
statement.setFetchSize(5000);
|
||||
statement.setString(1, uuid.toString());
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
@ -118,4 +120,81 @@ public class ActionsTable extends UserIDTable {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, Map<UUID, List<Action>>> getAllActions() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
|
||||
statement = prepareStatement("SELECT " +
|
||||
columnActionID + ", " +
|
||||
columnDate + ", " +
|
||||
columnAdditionalInfo + ", " +
|
||||
usersUUIDColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID +
|
||||
" JOIN " + serverTable + " on " + serverIDColumn + "=" + columnServerID
|
||||
);
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, Map<UUID, List<Action>>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
|
||||
Map<UUID, List<Action>> serverMap = map.getOrDefault(serverUUID, new HashMap<>());
|
||||
List<Action> actions = serverMap.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
long date = set.getLong(columnDate);
|
||||
Actions doneAction = Actions.getById(set.getInt(columnActionID));
|
||||
String additionalInfo = set.getString(columnAdditionalInfo);
|
||||
|
||||
actions.add(new Action(date, doneAction, additionalInfo, -1));
|
||||
|
||||
serverMap.put(uuid, actions);
|
||||
map.put(serverUUID, serverMap);
|
||||
}
|
||||
return map;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertActions(Map<UUID, Map<UUID, List<Action>>> allActions) throws SQLException {
|
||||
if (Verify.isEmpty(allActions)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
// Every Server
|
||||
for (UUID serverUUID : allActions.keySet()) {
|
||||
// Every User
|
||||
for (Map.Entry<UUID, List<Action>> entry : allActions.get(serverUUID).entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
// Every Action
|
||||
List<Action> actions = entry.getValue();
|
||||
for (Action action : actions) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, serverUUID.toString());
|
||||
statement.setInt(3, action.getDoneAction().getId());
|
||||
statement.setLong(4, action.getDate());
|
||||
statement.setString(5, action.getAdditionalInfo());
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -27,6 +26,7 @@ public class CommandUseTable extends Table {
|
||||
private final String columnServerID = "server_id";
|
||||
|
||||
private final ServerTable serverTable;
|
||||
private String insertStatement;
|
||||
|
||||
/**
|
||||
* @param db
|
||||
@ -35,6 +35,11 @@ public class CommandUseTable extends Table {
|
||||
public CommandUseTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_commandusages", db, usingMySQL);
|
||||
serverTable = db.getServerTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ columnCommand + ", "
|
||||
+ columnTimesUsed + ", "
|
||||
+ columnServerID
|
||||
+ ") VALUES (?, ?, " + serverTable.statementSelectServerID + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +77,6 @@ public class CommandUseTable extends Table {
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<String, Integer> getCommandUse(UUID serverUUID) throws SQLException {
|
||||
Benchmark.start("Get CommandUse");
|
||||
Map<String, Integer> commandUse = new HashMap<>();
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
@ -96,7 +100,6 @@ public class CommandUseTable extends Table {
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
Benchmark.stop("Database", "Get CommandUse");
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,11 +130,6 @@ public class CommandUseTable extends Table {
|
||||
private void insertCommand(String command) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
String insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ columnCommand + ", "
|
||||
+ columnTimesUsed + ", "
|
||||
+ columnServerID
|
||||
+ ") VALUES (?, ?, " + serverTable.statementSelectServerID + ")";
|
||||
statement = prepareStatement(insertStatement);
|
||||
statement.setString(1, command);
|
||||
statement.setInt(2, 1);
|
||||
@ -177,4 +175,67 @@ public class CommandUseTable extends Table {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, Map<String, Integer>> getAllCommandUsages() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
|
||||
statement = prepareStatement("SELECT " +
|
||||
columnCommand + ", " +
|
||||
columnTimesUsed + ", " +
|
||||
serverUUIDColumn + ", " +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + serverTable + " on " + serverIDColumn + "=" + columnServerID
|
||||
);
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, Map<String, Integer>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
|
||||
Map<String, Integer> serverMap = map.getOrDefault(serverUUID, new HashMap<>());
|
||||
|
||||
String command = set.getString(columnCommand);
|
||||
int timesUsed = set.getInt(columnTimesUsed);
|
||||
|
||||
serverMap.put(command, timesUsed);
|
||||
map.put(serverUUID, serverMap);
|
||||
}
|
||||
return map;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertCommandUsage(Map<UUID, Map<String, Integer>> allCommandUsages) throws SQLException {
|
||||
if (allCommandUsages.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
// Every Server
|
||||
for (UUID serverUUID : allCommandUsages.keySet()) {
|
||||
// Every Command
|
||||
for (Map.Entry<String, Integer> entry : allCommandUsages.get(serverUUID).entrySet()) {
|
||||
String command = entry.getKey();
|
||||
int timesUsed = entry.getValue();
|
||||
|
||||
statement.setString(1, command);
|
||||
statement.setInt(2, timesUsed);
|
||||
statement.setString(3, serverUUID.toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
@ -18,6 +19,7 @@ public class IPsTable extends UserIDTable {
|
||||
|
||||
private final String columnIP = "ip";
|
||||
private final String columnGeolocation = "geolocation";
|
||||
private String insertStatement;
|
||||
|
||||
/**
|
||||
* @param db The database
|
||||
@ -25,6 +27,13 @@ public class IPsTable extends UserIDTable {
|
||||
*/
|
||||
public IPsTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_ips", db, usingMySQL);
|
||||
insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnIP + ", "
|
||||
+ columnGeolocation
|
||||
+ ") VALUES ("
|
||||
+ usersTable.statementSelectID + ", "
|
||||
+ "?, ?)";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,13 +98,8 @@ public class IPsTable extends UserIDTable {
|
||||
private void insertIp(UUID uuid, String ip, String geolocation) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnIP + ", "
|
||||
+ columnGeolocation
|
||||
+ ") VALUES ("
|
||||
+ usersTable.statementSelectID + ", "
|
||||
+ "?, ?)");
|
||||
|
||||
statement = prepareStatement(insertStatement);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, ip);
|
||||
statement.setString(3, geolocation);
|
||||
@ -156,4 +160,69 @@ public class IPsTable extends UserIDTable {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, Map<String, String>> getAllIPsAndGeolocations() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
|
||||
statement = prepareStatement("SELECT " +
|
||||
columnGeolocation + ", " +
|
||||
columnIP + ", " +
|
||||
usersUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID
|
||||
);
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, Map<String, String>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
|
||||
Map<String, String> userMap = map.getOrDefault(uuid, new HashMap<>());
|
||||
|
||||
String geoLocation = set.getString(columnGeolocation);
|
||||
String ip = set.getString(columnIP);
|
||||
|
||||
userMap.put(ip, geoLocation);
|
||||
map.put(uuid, userMap);
|
||||
}
|
||||
return map;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertIPsAndGeolocations(Map<UUID, Map<String, String>> allIPsAndGeolocations) throws SQLException {
|
||||
if (Verify.isEmpty(allIPsAndGeolocations)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
// Every User
|
||||
for (UUID uuid : allIPsAndGeolocations.keySet()) {
|
||||
// Every IP & Geolocation
|
||||
for (Map.Entry<String, String> entry : allIPsAndGeolocations.get(uuid).entrySet()) {
|
||||
String ip = entry.getKey();
|
||||
String geoLocation = entry.getValue();
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, ip);
|
||||
statement.setString(3, geoLocation);
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
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.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.PlayerKill;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
@ -12,9 +12,7 @@ import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -57,7 +55,7 @@ public class KillsTable extends UserIDTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeUser(UUID uuid) {
|
||||
public void removeUser(UUID uuid) throws SQLException{
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName +
|
||||
@ -68,10 +66,6 @@ public class KillsTable extends UserIDTable {
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
@ -127,6 +121,7 @@ public class KillsTable extends UserIDTable {
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID +
|
||||
" WHERE " + columnKillerUserID + "=" + usersTable.statementSelectID);
|
||||
|
||||
statement.setFetchSize(10000);
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
set = statement.executeQuery();
|
||||
@ -147,4 +142,44 @@ public class KillsTable extends UserIDTable {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, List<PlayerKill>> getPlayerKills() throws SQLException {
|
||||
return getPlayerKills(Plan.getServerUUID());
|
||||
}
|
||||
|
||||
public Map<UUID, List<PlayerKill>> getPlayerKills(UUID serverUUID) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String usersVictimIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersKillerIDColumn = "a." + usersTable.getColumnID();
|
||||
String usersVictimUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as victim_uuid";
|
||||
String usersKillerUUIDColumn = "a." + usersTable.getColumnUUID() + " as killer_uuid";
|
||||
statement = prepareStatement("SELECT " +
|
||||
columnDate + ", " +
|
||||
columnWeapon + ", " +
|
||||
usersVictimUUIDColumn + ", " +
|
||||
usersKillerUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersVictimIDColumn + "=" + columnVictimUserID +
|
||||
" JOIN " + usersTable + " a on " + usersKillerIDColumn + "=" + columnKillerUserID);
|
||||
|
||||
statement.setFetchSize(10000);
|
||||
set = statement.executeQuery();
|
||||
|
||||
Map<UUID, List<PlayerKill>> allKills = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID killer = UUID.fromString(set.getString("killer_uuid"));
|
||||
UUID victim = UUID.fromString(set.getString("victim_uuid"));
|
||||
long date = set.getLong(columnDate);
|
||||
String weapon = set.getString(columnWeapon);
|
||||
List<PlayerKill> kills = allKills.getOrDefault(killer, new ArrayList<>());
|
||||
kills.add(new PlayerKill(victim, weapon, date));
|
||||
allKills.put(killer, kills);
|
||||
}
|
||||
return allKills;
|
||||
} finally {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
@ -9,9 +10,7 @@ import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -22,6 +21,7 @@ public class NicknamesTable extends UserIDTable {
|
||||
private final String columnServerID = "server_id";
|
||||
|
||||
private final ServerTable serverTable;
|
||||
private String insertStatement;
|
||||
|
||||
/**
|
||||
* @param db The database
|
||||
@ -30,6 +30,14 @@ public class NicknamesTable extends UserIDTable {
|
||||
public NicknamesTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_nicknames", db, usingMySQL);
|
||||
serverTable = db.getServerTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " (" +
|
||||
columnUserID + ", " +
|
||||
columnServerID + ", " +
|
||||
columnNick +
|
||||
") VALUES (" +
|
||||
usersTable.statementSelectID + ", " +
|
||||
serverTable.statementSelectServerID + ", " +
|
||||
"?)";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,14 +150,7 @@ public class NicknamesTable extends UserIDTable {
|
||||
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " (" +
|
||||
columnUserID + ", " +
|
||||
columnServerID + ", " +
|
||||
columnNick +
|
||||
") VALUES (" +
|
||||
usersTable.statementSelectID + ", " +
|
||||
serverTable.statementSelectServerID + ", " +
|
||||
"?)");
|
||||
statement = prepareStatement(insertStatement);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, Plan.getServerUUID().toString());
|
||||
statement.setString(3, displayName);
|
||||
@ -160,4 +161,77 @@ public class NicknamesTable extends UserIDTable {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, Map<UUID, List<String>>> getAllNicknames() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
|
||||
statement = prepareStatement("SELECT " +
|
||||
columnNick + ", " +
|
||||
usersUUIDColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID +
|
||||
" JOIN " + serverTable + " on " + serverIDColumn + "=" + columnServerID
|
||||
);
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, Map<UUID, List<String>>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
|
||||
Map<UUID, List<String>> serverMap = map.getOrDefault(serverUUID, new HashMap<>());
|
||||
List<String> nicknames = serverMap.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
nicknames.add(set.getString(columnNick));
|
||||
|
||||
serverMap.put(uuid, nicknames);
|
||||
map.put(serverUUID, serverMap);
|
||||
}
|
||||
return map;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertNicknames(Map<UUID, Map<UUID, List<String>>> allNicknames) throws SQLException {
|
||||
if (Verify.isEmpty(allNicknames)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
// Every Server
|
||||
for (UUID serverUUID : allNicknames.keySet()) {
|
||||
// Every User
|
||||
for (Map.Entry<UUID, List<String>> entry : allNicknames.get(serverUUID).entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
// Every Nickname
|
||||
List<String> nicknames = entry.getValue();
|
||||
for (String nickname : nicknames) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, serverUUID.toString());
|
||||
statement.setString(3, nickname);
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public String getColumnNick() {
|
||||
return columnNick;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
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.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
@ -28,9 +29,14 @@ public class SecurityTable extends Table {
|
||||
private final String columnUser = "username";
|
||||
private final String columnSaltedHash = "salted_pass_hash";
|
||||
private final String columnPermLevel = "permission_level";
|
||||
private String insertStatement;
|
||||
|
||||
public SecurityTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_security", db, usingMySQL);
|
||||
insertStatement = Insert.values(tableName,
|
||||
columnUser,
|
||||
columnSaltedHash,
|
||||
columnPermLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,10 +73,7 @@ public class SecurityTable extends Table {
|
||||
public void addNewUser(String user, String saltPassHash, int permLevel) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(Insert.values(tableName,
|
||||
columnUser,
|
||||
columnSaltedHash,
|
||||
columnPermLevel));
|
||||
statement = prepareStatement(insertStatement);
|
||||
statement.setString(1, user);
|
||||
statement.setString(2, saltPassHash);
|
||||
statement.setInt(3, permLevel);
|
||||
@ -110,6 +113,7 @@ public class SecurityTable extends Table {
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement(Select.all(tableName).toString());
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
List<WebUser> list = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
@ -125,4 +129,29 @@ public class SecurityTable extends Table {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void addUsers(List<WebUser> users) throws SQLException {
|
||||
if (Verify.isEmpty(users)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
for (WebUser user : users) {
|
||||
String userName = user.getName();
|
||||
String pass = user.getSaltedPassHash();
|
||||
int permLvl = user.getPermLevel();
|
||||
|
||||
statement.setString(1, userName);
|
||||
statement.setString(2, pass);
|
||||
statement.setInt(3, permLvl);
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,18 @@ public class ServerTable extends Table {
|
||||
private final String columnWebserverAddress = "web_address";
|
||||
private final String columnInstalled = "is_installed";
|
||||
private final String columnMaxPlayers = "max_players";
|
||||
private String insertStatement;
|
||||
|
||||
public ServerTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_servers", db, usingMySQL);
|
||||
statementSelectServerID = "(" + Select.from(tableName, tableName + "." + columnServerID).where(columnServerUUID + "=?").toString() + ")";
|
||||
statementSelectServerNameID = "(" + Select.from(tableName, tableName + "." + columnServerName).where(columnServerID + "=?").toString() + ")";
|
||||
insertStatement = Insert.values(tableName,
|
||||
columnServerUUID,
|
||||
columnServerName,
|
||||
columnWebserverAddress,
|
||||
columnInstalled,
|
||||
columnMaxPlayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,12 +116,7 @@ public class ServerTable extends Table {
|
||||
Verify.nullCheck(uuid, name, webAddress);
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(Insert.values(tableName,
|
||||
columnServerUUID,
|
||||
columnServerName,
|
||||
columnWebserverAddress,
|
||||
columnInstalled,
|
||||
columnMaxPlayers));
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, name);
|
||||
@ -264,4 +266,40 @@ public class ServerTable extends Table {
|
||||
public String getColumnID() {
|
||||
return columnServerID;
|
||||
}
|
||||
|
||||
public String getColumnUUID() {
|
||||
return columnServerUUID;
|
||||
}
|
||||
|
||||
public void insertAllServers(List<ServerInfo> allServerInfo) throws SQLException {
|
||||
if (Verify.isEmpty(allServerInfo)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
for (ServerInfo info : allServerInfo) {
|
||||
UUID uuid = info.getUuid();
|
||||
String name = info.getName();
|
||||
String webAddress = info.getWebAddress();
|
||||
|
||||
if (Verify.notNull(uuid, name, webAddress)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, name);
|
||||
statement.setString(3, webAddress);
|
||||
statement.setBoolean(4, true);
|
||||
statement.setInt(5, info.getMaxPlayers());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -450,7 +450,6 @@ public class SessionsTable extends UserIDTable {
|
||||
return getSessionInfoOfServer(Plan.getServerUUID());
|
||||
}
|
||||
|
||||
// TODO Write tests for this method
|
||||
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) throws SQLException {
|
||||
Optional<Integer> id = serverTable.getServerID(serverUUID);
|
||||
if (!id.isPresent()) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
@ -14,10 +15,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class representing database table plan_tps
|
||||
@ -37,6 +35,7 @@ public class TPSTable extends Table {
|
||||
private final String columnChunksLoaded = "chunks_loaded";
|
||||
|
||||
private final ServerTable serverTable;
|
||||
private String insertStatement;
|
||||
|
||||
/**
|
||||
* @param db
|
||||
@ -45,6 +44,18 @@ public class TPSTable extends Table {
|
||||
public TPSTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_tps", db, usingMySQL);
|
||||
serverTable = db.getServerTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ columnServerID + ", "
|
||||
+ columnDate + ", "
|
||||
+ columnTPS + ", "
|
||||
+ columnPlayers + ", "
|
||||
+ columnCPUUsage + ", "
|
||||
+ columnRAMUsage + ", "
|
||||
+ columnEntities + ", "
|
||||
+ columnChunksLoaded
|
||||
+ ") VALUES ("
|
||||
+ serverTable.statementSelectServerID + ", "
|
||||
+ "?, ?, ?, ?, ?, ?, ?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,7 +86,7 @@ public class TPSTable extends Table {
|
||||
statement = prepareStatement(Select.all(tableName)
|
||||
.where(columnServerID + "=" + serverTable.statementSelectServerID)
|
||||
.toString());
|
||||
statement.setFetchSize(10000);
|
||||
statement.setFetchSize(20000);
|
||||
statement.setString(1, Plan.getServerUUID().toString());
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
@ -99,18 +110,7 @@ public class TPSTable extends Table {
|
||||
public void insertTPS(TPS tps) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnServerID + ", "
|
||||
+ columnDate + ", "
|
||||
+ columnTPS + ", "
|
||||
+ columnPlayers + ", "
|
||||
+ columnCPUUsage + ", "
|
||||
+ columnRAMUsage + ", "
|
||||
+ columnEntities + ", "
|
||||
+ columnChunksLoaded
|
||||
+ ") VALUES ("
|
||||
+ serverTable.statementSelectServerID + ", "
|
||||
+ "?, ?, ?, ?, ?, ?, ?)");
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
statement.setString(1, Plan.getServerUUID().toString());
|
||||
statement.setLong(2, tps.getDate());
|
||||
@ -132,12 +132,18 @@ public class TPSTable extends Table {
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clean() throws SQLException {
|
||||
Optional<TPS> allTimePeak = getAllTimePeak();
|
||||
int p = -1;
|
||||
if (allTimePeak.isPresent()) {
|
||||
p = allTimePeak.get().getPlayers();
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName +
|
||||
" WHERE (" + columnDate + "<?)" +
|
||||
" AND (" + columnPlayers + "" +
|
||||
" != (SELECT MAX(" + columnPlayers + ") FROM " + tableName + "))");
|
||||
" != ?)");
|
||||
statement.setInt(1, p);
|
||||
// More than 2 Months ago.
|
||||
long fiveWeeks = TimeAmount.MONTH.ms() * 2L;
|
||||
statement.setLong(1, MiscUtils.getTime() - fiveWeeks);
|
||||
@ -167,7 +173,7 @@ public class TPSTable extends Table {
|
||||
try {
|
||||
statement = prepareStatement(Select.all(tableName)
|
||||
.where(columnServerID + "=" + serverTable.statementSelectServerID)
|
||||
.and(columnPlayers + "= (SELECT MAX(" + columnPlayers + ") FROM " + tableName+")")
|
||||
.and(columnPlayers + "= (SELECT MAX(" + columnPlayers + ") FROM " + tableName + ")")
|
||||
.and(columnDate + ">= ?")
|
||||
.toString());
|
||||
statement.setString(1, serverUUID.toString());
|
||||
@ -189,4 +195,81 @@ public class TPSTable extends Table {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, List<TPS>> getAllTPS() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
|
||||
statement = prepareStatement("SELECT " +
|
||||
columnDate + ", " +
|
||||
columnTPS + ", " +
|
||||
columnPlayers + ", " +
|
||||
columnCPUUsage + ", " +
|
||||
columnRAMUsage + ", " +
|
||||
columnEntities + ", " +
|
||||
columnChunksLoaded + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + serverTable + " on " + serverIDColumn + "=" + columnServerID
|
||||
);
|
||||
statement.setFetchSize(20000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, List<TPS>> serverMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
|
||||
List<TPS> tpsList = serverMap.getOrDefault(serverUUID, new ArrayList<>());
|
||||
|
||||
long date = set.getLong(columnDate);
|
||||
double tps = set.getDouble(columnTPS);
|
||||
int players = set.getInt(columnPlayers);
|
||||
double cpuUsage = set.getDouble(columnCPUUsage);
|
||||
long ramUsage = set.getLong(columnRAMUsage);
|
||||
int entities = set.getInt(columnEntities);
|
||||
int chunksLoaded = set.getInt(columnChunksLoaded);
|
||||
|
||||
tpsList.add(new TPS(date, tps, players, cpuUsage, ramUsage, entities, chunksLoaded));
|
||||
serverMap.put(serverUUID, tpsList);
|
||||
}
|
||||
return serverMap;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertAllTPS(Map<UUID, List<TPS>> allTPS) throws SQLException {
|
||||
if (Verify.isEmpty(allTPS)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(insertStatement);
|
||||
|
||||
// Every Server
|
||||
for (Map.Entry<UUID, List<TPS>> entry : allTPS.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
// Every TPS Data point
|
||||
List<TPS> tpsList = entry.getValue();
|
||||
for (TPS tps : tpsList) {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
statement.setLong(2, tps.getDate());
|
||||
statement.setDouble(3, tps.getTicksPerSecond());
|
||||
statement.setInt(4, tps.getPlayers());
|
||||
statement.setDouble(5, tps.getCPUUsage());
|
||||
statement.setLong(6, tps.getUsedMemory());
|
||||
statement.setDouble(7, tps.getEntityCount());
|
||||
statement.setDouble(8, tps.getChunksLoaded());
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import com.google.common.base.Objects;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
@ -135,14 +135,8 @@ public abstract class Table {
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean removeAllData() {
|
||||
try {
|
||||
public void removeAllData() throws SQLException {
|
||||
execute("DELETE FROM " + tableName);
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,4 +196,19 @@ public abstract class Table {
|
||||
|
||||
endTransaction(statement.getConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Table table = (Table) o;
|
||||
return usingMySQL == table.usingMySQL &&
|
||||
Objects.equal(tableName, table.tableName) &&
|
||||
Objects.equal(db, table.db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(tableName, db, usingMySQL);
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -23,7 +22,7 @@ public abstract class UserIDTable extends Table {
|
||||
usersTable = db.getUsersTable();
|
||||
}
|
||||
|
||||
public boolean removeUser(UUID uuid) {
|
||||
public void removeUser(UUID uuid) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName +
|
||||
@ -32,10 +31,6 @@ public abstract class UserIDTable extends Table {
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
@ -16,13 +17,11 @@ import main.java.com.djrapitops.plan.database.sql.Update;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Server Specific user information table.
|
||||
*
|
||||
* <p>
|
||||
* Represents plan_user_info.
|
||||
*
|
||||
* @author Rsl1122
|
||||
@ -155,11 +154,11 @@ public class UserInfoTable extends UserIDTable {
|
||||
*
|
||||
* @return List of UserInfo objects.
|
||||
*/
|
||||
public List<UserInfo> getAllUserInfo() throws SQLException {
|
||||
return getAllUserInfo(Plan.getServerUUID());
|
||||
public List<UserInfo> getServerUserInfo() throws SQLException {
|
||||
return getServerUserInfo(Plan.getServerUUID());
|
||||
}
|
||||
|
||||
public List<UserInfo> getAllUserInfo(UUID serverUUID) throws SQLException {
|
||||
public List<UserInfo> getServerUserInfo(UUID serverUUID) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
@ -193,4 +192,84 @@ public class UserInfoTable extends UserIDTable {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, List<UserInfo>> getAllUserInfo() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
|
||||
statement = prepareStatement("SELECT " +
|
||||
tableName + "." + columnRegistered + ", " +
|
||||
columnBanned + ", " +
|
||||
columnOP + ", " +
|
||||
usersUUIDColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID +
|
||||
" JOIN " + serverTable + " on " + serverIDColumn + "=" + columnServerID
|
||||
);
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, List<UserInfo>> serverMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
|
||||
List<UserInfo> userInfos = serverMap.getOrDefault(serverUUID, new ArrayList<>());
|
||||
|
||||
long registered = set.getLong(columnRegistered);
|
||||
boolean banned = set.getBoolean(columnBanned);
|
||||
boolean op = set.getBoolean(columnOP);
|
||||
|
||||
userInfos.add(new UserInfo(uuid, "", registered, op, banned));
|
||||
|
||||
serverMap.put(uuid, userInfos);
|
||||
}
|
||||
return serverMap;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertUserInfo(Map<UUID, List<UserInfo>> allUserInfos) throws SQLException {
|
||||
if (Verify.isEmpty(allUserInfos)) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " (" +
|
||||
columnUserID + ", " +
|
||||
columnRegistered + ", " +
|
||||
columnServerID + ", " +
|
||||
columnBanned + ", " +
|
||||
columnOP +
|
||||
") VALUES (" +
|
||||
usersTable.statementSelectID + ", " +
|
||||
"?, " +
|
||||
serverTable.statementSelectServerID + ", ?, ?)");
|
||||
|
||||
// Every Server
|
||||
for (Map.Entry<UUID, List<UserInfo>> entry : allUserInfos.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
// Every User
|
||||
for (UserInfo user : entry.getValue()) {
|
||||
statement.setString(1, user.getUuid().toString());
|
||||
statement.setLong(2, user.getRegistered());
|
||||
statement.setString(3, serverUUID.toString());
|
||||
statement.setBoolean(4, user.isBanned());
|
||||
statement.setBoolean(5, user.isOpped());
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ public class UsersTable extends UserIDTable {
|
||||
* @return if the removal was successful.
|
||||
*/
|
||||
@Override
|
||||
public boolean removeUser(UUID uuid) {
|
||||
public void removeUser(UUID uuid) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUUID + "=?)");
|
||||
@ -85,9 +85,6 @@ public class UsersTable extends UserIDTable {
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
return false;
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
@ -277,8 +274,14 @@ public class UsersTable extends UserIDTable {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
NicknamesTable nicknamesTable = db.getNicknamesTable();
|
||||
statement = prepareStatement(
|
||||
"SELECT name FROM plan_users WHERE name LIKE LOWER(?) UNION SELECT name FROM plan_users WHERE id = (SELECT user_id FROM plan_nicknames WHERE nickname LIKE LOWER(?))"
|
||||
"SELECT " + columnName + " FROM " + tableName +
|
||||
" WHERE " + columnName + " LIKE LOWER(?)" +
|
||||
" UNION SELECT " + columnName + " FROM " + tableName +
|
||||
" WHERE " + columnID + " =" +
|
||||
" (SELECT " + columnID + " FROM " + nicknamesTable +
|
||||
" WHERE " + nicknamesTable.getColumnNick() + " LIKE LOWER(?))"
|
||||
);
|
||||
statement.setString(1, searchString);
|
||||
statement.setString(2, searchString);
|
||||
|
@ -210,7 +210,6 @@ public class WorldTimesTable extends UserIDTable {
|
||||
try {
|
||||
String worldIDColumn = worldTable + "." + worldTable.getColumnID();
|
||||
String worldNameColumn = worldTable + "." + worldTable.getColumnWorldName() + " as world_name";
|
||||
String sessionIDColumn = sessionsTable + "." + sessionsTable.getColumnID();
|
||||
statement = prepareStatement("SELECT " +
|
||||
"SUM(" + columnSurvival + ") as survival, " +
|
||||
"SUM(" + columnCreative + ") as creative, " +
|
||||
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.database.tables.move;
|
||||
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.ServerTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.Table;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A Fake table used to store a lot of big table operations.
|
||||
* <p>
|
||||
* To use this table create a new BatchOperationTable with both SQLDB objects.
|
||||
* {@code SQLDB from; SQLDB to;}
|
||||
* {@code fromT = new BatchOperationTable(from);}
|
||||
* {@code toT = new BatchOperationTable(to);}
|
||||
* {@code fromT.copy(toT);}
|
||||
* <p>
|
||||
* The copy methods assume that the table has been cleared, or that no duplicate data will be entered for a user.
|
||||
* <p>
|
||||
* clearTable methods can be used to clear the table beforehand.
|
||||
* <p>
|
||||
* Server & User tables should be copied first.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class BatchOperationTable extends Table {
|
||||
public BatchOperationTable(SQLDB db, boolean usingMySQL) {
|
||||
super("", db, usingMySQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() throws DBCreateTableException {
|
||||
throw new IllegalStateException("Method not supposed to be used on this table.");
|
||||
}
|
||||
|
||||
public void clearTable(Table table) throws SQLException {
|
||||
table.removeAllData();
|
||||
}
|
||||
|
||||
public void clearTable(Collection<UUID> uuids, Table table) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void copyActions(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getActionsTable().insertActions(db.getActionsTable().getAllActions());
|
||||
}
|
||||
|
||||
public void copyCommandUse(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getCommandUseTable().insertCommandUsage(db.getCommandUseTable().getAllCommandUsages());
|
||||
}
|
||||
|
||||
public void copyIPsAndGeolocs(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getIpsTable().insertIPsAndGeolocations(db.getIpsTable().getAllIPsAndGeolocations());
|
||||
}
|
||||
|
||||
public void copyNicknames(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getNicknamesTable().insertNicknames(db.getNicknamesTable().getAllNicknames());
|
||||
}
|
||||
|
||||
public void copyWebUsers(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getSecurityTable().addUsers(db.getSecurityTable().getUsers());
|
||||
}
|
||||
|
||||
public void copyServers(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
List<ServerInfo> servers = serverTable.getBukkitServers();
|
||||
serverTable.getBungeeInfo().ifPresent(servers::add);
|
||||
toDB.db.getServerTable().insertAllServers(servers);
|
||||
}
|
||||
|
||||
public void copyTPS(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getTpsTable().insertAllTPS(db.getTpsTable().getAllTPS());
|
||||
}
|
||||
|
||||
public void copyUserInfo(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getUserInfoTable().insertUserInfo(db.getUserInfoTable().getAllUserInfo());
|
||||
}
|
||||
|
||||
public void copyWorlds(BatchOperationTable toDB) throws SQLException {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getWorldTable().saveWorlds(db.getWorldTable().getWorlds());
|
||||
}
|
||||
}
|
@ -73,7 +73,7 @@ public class InformationManager {
|
||||
}
|
||||
|
||||
public void cachePlayer(UUID uuid) {
|
||||
PageCache.loadPage("inspectPage: "+uuid, () -> new InspectPageResponse(this, uuid));
|
||||
PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(this, uuid));
|
||||
// TODO Player page plugin tab request
|
||||
}
|
||||
|
||||
|
@ -95,9 +95,10 @@ public class PlanPlayerListener implements Listener {
|
||||
cache.cacheSession(uuid, Session.start(time, world, gm));
|
||||
|
||||
plugin.addToProcessQueue(
|
||||
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline),
|
||||
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
|
||||
new IPUpdateProcessor(uuid, ip),
|
||||
new NameProcessor(uuid, playerName, displayName)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.Actions;
|
||||
import main.java.com.djrapitops.plan.database.tables.UserInfoTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
@ -26,13 +27,15 @@ public class RegisterProcessor extends PlayerProcessor {
|
||||
private final long time;
|
||||
private final int playersOnline;
|
||||
private final String name;
|
||||
private final Processor[] afterProcess;
|
||||
|
||||
public RegisterProcessor(UUID uuid, long registered, long time, String name, int playersOnline) {
|
||||
public RegisterProcessor(UUID uuid, long registered, long time, String name, int playersOnline, Processor... afterProcess) {
|
||||
super(uuid);
|
||||
this.registered = registered;
|
||||
this.time = time;
|
||||
this.playersOnline = playersOnline;
|
||||
this.name = name;
|
||||
this.afterProcess = afterProcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,5 +58,6 @@ public class RegisterProcessor extends PlayerProcessor {
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
plugin.addToProcessQueue(afterProcess);
|
||||
}
|
||||
}
|
@ -478,11 +478,6 @@ public class WebServer {
|
||||
return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
|
||||
}
|
||||
|
||||
if (!infoManager.isCached(uuid)) {
|
||||
String error = "Player's data was not cached.<br>Use /plan inspect " + playerName + " to cache the Data.";
|
||||
return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
|
||||
}
|
||||
|
||||
return PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(infoManager, uuid));
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ManageUtils {
|
||||
*/
|
||||
public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB) {
|
||||
// try {
|
||||
clearAndCopyToDB.removeAllData();
|
||||
//clearAndCopyToDB.removeAllData();
|
||||
//TODO List<UserInfo> allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs());
|
||||
// clearAndCopyToDB.saveMultipleUserData(allUserData);
|
||||
// TODO clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());
|
||||
|
@ -5,10 +5,7 @@ import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.data.*;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
@ -240,6 +237,7 @@ public class Analysis {
|
||||
CommandUsagePart commandUsagePart = analysisData.getCommandUsagePart();
|
||||
GeolocationPart geolocPart = analysisData.getGeolocationPart();
|
||||
JoinInfoPart joinInfo = analysisData.getJoinInfoPart();
|
||||
KillPart killPart = analysisData.getKillPart();
|
||||
PlayerCountPart playerCount = analysisData.getPlayerCountPart();
|
||||
PlaytimePart playtime = analysisData.getPlaytimePart();
|
||||
TPSPart tpsPart = analysisData.getTpsPart();
|
||||
@ -260,7 +258,7 @@ public class Analysis {
|
||||
tpsPart.addTpsData(tpsData);
|
||||
Log.debug("Analysis", "TPS Data Size: " + tpsData.size());
|
||||
|
||||
List<UserInfo> userInfo = db.getUserInfoTable().getAllUserInfo();
|
||||
List<UserInfo> userInfo = db.getUserInfoTable().getServerUserInfo();
|
||||
Map<UUID, UserInfo> mappedUserInfo = userInfo.stream().collect(Collectors.toMap(UserInfo::getUuid, Function.identity()));
|
||||
Map<UUID, Long> lastSeen = db.getSessionsTable().getLastSeenForAllPlayers();
|
||||
for (Map.Entry<UUID, Long> entry : lastSeen.entrySet()) {
|
||||
@ -290,6 +288,9 @@ public class Analysis {
|
||||
joinInfo.addActiveSessions(activeSessions);
|
||||
joinInfo.addSessions(sessions);
|
||||
|
||||
Map<UUID, List<PlayerKill>> playerKills = db.getKillsTable().getPlayerKills();
|
||||
killPart.addKills(playerKills);
|
||||
|
||||
Map<UUID, List<String>> geolocations = db.getIpsTable().getAllGeolocations();
|
||||
geolocPart.addGeoLocations(geolocations);
|
||||
|
||||
|
@ -1,103 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.RandomData;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class DatabaseCommitTest {
|
||||
|
||||
private Plan plan;
|
||||
private SQLDB db;
|
||||
private int rows;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit t = TestInit.init();
|
||||
plan = t.getPlanMock();
|
||||
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
|
||||
db.init();
|
||||
|
||||
File file = new File(plan.getDataFolder(), "Errors.txt");
|
||||
rows = FileUtil.lines(file).size();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException, SQLException {
|
||||
db.close();
|
||||
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
List<String> lines = FileUtil.lines(f);
|
||||
int rowsAgain = lines.size();
|
||||
if (rowsAgain > 0) {
|
||||
for (String line : lines) {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Errors were caught.", rows == rowsAgain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExceptionWhenCommitEmpty() throws Exception {
|
||||
db.init();
|
||||
|
||||
db.commit(db.getConnection());
|
||||
db.commit(db.getConnection());
|
||||
db.commit(db.getConnection());
|
||||
}
|
||||
|
||||
@Ignore("//TODO")
|
||||
@Test
|
||||
public void testCommitToDBFile() throws Exception {
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Ignore("//TODO")
|
||||
@Test
|
||||
public void testCommitToDBFile2() throws Exception {
|
||||
db.init();
|
||||
List<TPS> tps = RandomData.randomTPS();
|
||||
// db.getTpsTable().saveTPSData(tps);
|
||||
db.close();
|
||||
db.init();
|
||||
assertFalse(db.getTpsTable().getTPSData().isEmpty());
|
||||
}
|
||||
|
||||
// TODO Commit tests for new Login save features.
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile5() throws Exception {
|
||||
db.init();
|
||||
WebUser webUser = new WebUser("Test", "SHA1:rioegnorgiengoieng:oiegnoeigneo:352", 0);
|
||||
db.getSecurityTable().addNewUser(webUser);
|
||||
db.close();
|
||||
db.init();
|
||||
assertEquals(webUser, db.getSecurityTable().getWebUser("Test"));
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.data.*;
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
||||
@ -91,6 +92,15 @@ public class DatabaseTest {
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExceptionWhenCommitEmpty() throws Exception {
|
||||
db.init();
|
||||
|
||||
db.commit(((SQLDB) db).getConnection());
|
||||
db.commit(((SQLDB) db).getConnection());
|
||||
db.commit(((SQLDB) db).getConnection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSQLiteGetConfigName() {
|
||||
assertEquals("sqlite", db.getConfigName());
|
||||
@ -112,7 +122,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveCommandUse() throws SQLException {
|
||||
public void testSaveCommandUse() throws SQLException, DatabaseInitException {
|
||||
CommandUseTable commandUseTable = db.getCommandUseTable();
|
||||
Map<String, Integer> expected = new HashMap<>();
|
||||
|
||||
@ -139,7 +149,7 @@ public class DatabaseTest {
|
||||
commandUseTable.commandUsed("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
}
|
||||
|
||||
expected.remove("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
commitTest();
|
||||
|
||||
Map<String, Integer> commandUse = db.getCommandUse();
|
||||
assertEquals(expected, commandUse);
|
||||
@ -207,6 +217,8 @@ public class DatabaseTest {
|
||||
tpsTable.insertTPS(tps);
|
||||
}
|
||||
|
||||
commitTest();
|
||||
|
||||
assertEquals(expected, tpsTable.getTPSData());
|
||||
}
|
||||
|
||||
@ -233,7 +245,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPTable() throws SQLException {
|
||||
public void testIPTable() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
IPsTable ipsTable = db.getIpsTable();
|
||||
|
||||
@ -242,6 +254,7 @@ public class DatabaseTest {
|
||||
|
||||
ipsTable.saveIP(uuid, expectedIP, expectedGeoLoc);
|
||||
ipsTable.saveIP(uuid, expectedIP, expectedGeoLoc);
|
||||
commitTest();
|
||||
|
||||
List<String> ips = ipsTable.getIps(uuid);
|
||||
assertEquals(1, ips.size());
|
||||
@ -257,14 +270,15 @@ public class DatabaseTest {
|
||||
assertEquals(expectedGeoLoc, result.get());
|
||||
}
|
||||
|
||||
@Test // Does not test getting sessions from another server.
|
||||
public void testNicknamesTable() throws SQLException {
|
||||
@Test
|
||||
public void testNicknamesTable() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
NicknamesTable nickTable = db.getNicknamesTable();
|
||||
|
||||
String expected = "TestNickname";
|
||||
nickTable.saveUserName(uuid, expected);
|
||||
nickTable.saveUserName(uuid, expected);
|
||||
commitTest();
|
||||
|
||||
List<String> nicknames = nickTable.getNicknames(uuid);
|
||||
assertEquals(1, nicknames.size());
|
||||
@ -275,10 +289,12 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecurityTable() throws SQLException {
|
||||
public void testSecurityTable() throws SQLException, DatabaseInitException {
|
||||
SecurityTable securityTable = db.getSecurityTable();
|
||||
WebUser expected = new WebUser("Test", "RandomGarbageBlah", 0);
|
||||
securityTable.addNewUser(expected);
|
||||
commitTest();
|
||||
|
||||
assertTrue(securityTable.userExists("Test"));
|
||||
WebUser test = securityTable.getWebUser("Test");
|
||||
assertEquals(expected, test);
|
||||
@ -296,11 +312,13 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldTable() throws SQLException {
|
||||
public void testWorldTable() throws SQLException, DatabaseInitException {
|
||||
WorldTable worldTable = db.getWorldTable();
|
||||
List<String> worlds = Arrays.asList("Test", "Test2", "Test3");
|
||||
worldTable.saveWorlds(worlds);
|
||||
|
||||
commitTest();
|
||||
|
||||
List<String> saved = worldTable.getWorlds();
|
||||
assertEquals(worlds, saved);
|
||||
}
|
||||
@ -330,7 +348,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionPlaytimeSaving() throws SQLException {
|
||||
public void testSessionPlaytimeSaving() throws SQLException, DatabaseInitException {
|
||||
saveTwoWorlds();
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
@ -346,6 +364,8 @@ public class DatabaseTest {
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
sessionsTable.saveSession(uuid, session);
|
||||
|
||||
commitTest();
|
||||
|
||||
assertEquals(expectedLength, sessionsTable.getPlaytime(uuid));
|
||||
assertEquals(0L, sessionsTable.getPlaytime(uuid, 30000L));
|
||||
|
||||
@ -358,7 +378,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionSaving() throws SQLException {
|
||||
public void testSessionSaving() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
@ -370,6 +390,8 @@ public class DatabaseTest {
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
sessionsTable.saveSession(uuid, session);
|
||||
|
||||
commitTest();
|
||||
|
||||
Map<String, List<Session>> sessions = sessionsTable.getSessions(uuid);
|
||||
|
||||
for (Map.Entry<String, List<Session>> entry : sessions.entrySet()) {
|
||||
@ -394,7 +416,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterUnRegistered() throws SQLException {
|
||||
public void testUserInfoTableRegisterUnRegistered() throws SQLException, DatabaseInitException {
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
assertFalse(userInfoTable.isRegistered(uuid));
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
@ -402,6 +424,8 @@ public class DatabaseTest {
|
||||
|
||||
userInfoTable.registerUserInfo(uuid, 123456789L);
|
||||
|
||||
commitTest();
|
||||
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
assertTrue(userInfoTable.isRegistered(uuid));
|
||||
|
||||
@ -415,7 +439,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterRegistered() throws SQLException {
|
||||
public void testUserInfoTableRegisterRegistered() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
@ -424,6 +448,7 @@ public class DatabaseTest {
|
||||
assertFalse(userInfoTable.isRegistered(uuid));
|
||||
|
||||
userInfoTable.registerUserInfo(uuid, 223456789L);
|
||||
commitTest();
|
||||
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
assertTrue(userInfoTable.isRegistered(uuid));
|
||||
@ -436,28 +461,33 @@ public class DatabaseTest {
|
||||
assertFalse(userInfo.isBanned());
|
||||
assertFalse(userInfo.isOpped());
|
||||
|
||||
assertEquals(userInfo, userInfoTable.getAllUserInfo().get(0));
|
||||
assertEquals(userInfo, userInfoTable.getServerUserInfo().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableUpdateBannedOpped() throws SQLException {
|
||||
public void testUserInfoTableUpdateBannedOpped() throws SQLException, DatabaseInitException {
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
userInfoTable.registerUserInfo(uuid, 223456789L);
|
||||
assertTrue(userInfoTable.isRegistered(uuid));
|
||||
|
||||
userInfoTable.updateOpAndBanStatus(uuid, true, true);
|
||||
commitTest();
|
||||
|
||||
UserInfo userInfo = userInfoTable.getUserInfo(uuid);
|
||||
assertTrue(userInfo.isBanned());
|
||||
assertTrue(userInfo.isOpped());
|
||||
|
||||
userInfoTable.updateOpAndBanStatus(uuid, false, true);
|
||||
commitTest();
|
||||
|
||||
userInfo = userInfoTable.getUserInfo(uuid);
|
||||
|
||||
assertTrue(userInfo.isBanned());
|
||||
assertFalse(userInfo.isOpped());
|
||||
|
||||
userInfoTable.updateOpAndBanStatus(uuid, false, false);
|
||||
commitTest();
|
||||
|
||||
userInfo = userInfoTable.getUserInfo(uuid);
|
||||
|
||||
assertFalse(userInfo.isBanned());
|
||||
@ -465,13 +495,16 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersTableUpdateName() throws SQLException {
|
||||
public void testUsersTableUpdateName() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
|
||||
assertEquals(uuid, usersTable.getUuidOf("Test"));
|
||||
usersTable.updateName(uuid, "NewName");
|
||||
|
||||
commitTest();
|
||||
|
||||
assertNull(usersTable.getUuidOf("Test"));
|
||||
|
||||
assertEquals("NewName", usersTable.getPlayerName(uuid));
|
||||
@ -479,7 +512,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersTableKickSaving() throws SQLException {
|
||||
public void testUsersTableKickSaving() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertEquals(0, usersTable.getTimesKicked(uuid));
|
||||
@ -489,7 +522,7 @@ public class DatabaseTest {
|
||||
for (int i = 0; i < random + 1; i++) {
|
||||
usersTable.kicked(uuid);
|
||||
}
|
||||
|
||||
commitTest();
|
||||
assertEquals(random + 1, usersTable.getTimesKicked(uuid));
|
||||
}
|
||||
|
||||
@ -602,7 +635,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerTableBungeeSave() throws SQLException {
|
||||
public void testServerTableBungeeSave() throws SQLException, DatabaseInitException {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
|
||||
Optional<ServerInfo> bungeeInfo = serverTable.getBungeeInfo();
|
||||
@ -612,6 +645,8 @@ public class DatabaseTest {
|
||||
ServerInfo bungeeCord = new ServerInfo(-1, bungeeUUID, "BungeeCord", "Random:1234", 20);
|
||||
serverTable.saveCurrentServerInfo(bungeeCord);
|
||||
|
||||
commitTest();
|
||||
|
||||
bungeeCord.setId(2);
|
||||
|
||||
bungeeInfo = serverTable.getBungeeInfo();
|
||||
@ -624,7 +659,7 @@ public class DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerTableBungee() throws SQLException {
|
||||
public void testServerTableBungee() throws SQLException, DatabaseInitException {
|
||||
testServerTableBungeeSave();
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
|
||||
@ -637,4 +672,55 @@ public class DatabaseTest {
|
||||
Map<UUID, Long> lastSeen = db.getSessionsTable().getLastSeenForAllPlayers();
|
||||
assertTrue(lastSeen.isEmpty());
|
||||
}
|
||||
|
||||
private void commitTest() throws DatabaseInitException, SQLException {
|
||||
db.close();
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionTableGetInfoOfServer() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
Session session = new Session(12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
session.setPlayerKills(createKills());
|
||||
|
||||
SessionsTable sessionsTable = db.getSessionsTable();
|
||||
sessionsTable.saveSession(uuid, session);
|
||||
|
||||
commitTest();
|
||||
|
||||
Map<UUID, List<Session>> sessions = sessionsTable.getSessionInfoOfServer();
|
||||
|
||||
session.setPlayerKills(new ArrayList<>());
|
||||
session.setWorldTimes(new WorldTimes(new HashMap<>()));
|
||||
|
||||
List<Session> sSessions = sessions.get(uuid);
|
||||
assertFalse(sessions.isEmpty());
|
||||
assertNotNull(sSessions);
|
||||
assertFalse(sSessions.isEmpty());
|
||||
assertEquals(session, sSessions.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKillTableGetKillsOfServer() throws SQLException, DatabaseInitException {
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
KillsTable killsTable = db.getKillsTable();
|
||||
List<PlayerKill> expected = createKills();
|
||||
killsTable.savePlayerKills(uuid, 1, expected);
|
||||
|
||||
commitTest();
|
||||
|
||||
Map<UUID, List<PlayerKill>> playerKills = killsTable.getPlayerKills();
|
||||
List<PlayerKill> kills = playerKills.get(uuid);
|
||||
assertFalse(playerKills.isEmpty());
|
||||
assertNotNull(kills);
|
||||
assertFalse(kills.isEmpty());
|
||||
assertEquals(expected, kills);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ActionsTest {
|
||||
|
||||
@Test
|
||||
public void getUnknownActionsEnum() {
|
||||
Actions action = Actions.getById(Integer.MIN_VALUE);
|
||||
assertEquals(Actions.UNKNOWN, action);
|
||||
}
|
||||
|
||||
}
|
@ -10,6 +10,7 @@ import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
||||
import main.java.com.djrapitops.plan.utilities.html.graphs.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.RandomData;
|
||||
@ -53,7 +54,30 @@ public class GraphTest {
|
||||
assertEquals("[[0,0.0],[9,9.0]]", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList));
|
||||
assertEquals("[[0,0.0],[9,9.0]]", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList));
|
||||
assertEquals("[{'code':'1','value':1},{'code':'2','value':2},{'code':'3','value':3},{'code':'4','value':4},{'code':'5','value':5},{'code':'6','value':6},{'code':'7','value':7},{'code':'8','value':8},{'code':'9','value':9}]", WorldMapCreator.createDataSeries(geoList));
|
||||
assertEquals(Arrays.toString(WorldPieCreator.createSeriesData(worldTimes)), "[[{name:'WORLD',y:0,drilldown: 'WORLD'}], {name:'WORLD', id:'WORLD',data: []}]");
|
||||
assertEquals("[[{name:'WORLD',y:0,drilldown: 'WORLD'}], {name:'WORLD', id:'WORLD',data: []}]", Arrays.toString(WorldPieCreator.createSeriesData(worldTimes)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGraphCreatorsForBracketMistakes() {
|
||||
String[] series = new String[]{
|
||||
CPUGraphCreator.buildSeriesDataString(tpsList),
|
||||
PlayerActivityGraphCreator.buildSeriesDataString(tpsList),
|
||||
PunchCardGraphCreator.createDataSeries(sessionList),
|
||||
RamGraphCreator.buildSeriesDataString(tpsList),
|
||||
TPSGraphCreator.buildSeriesDataString(tpsList),
|
||||
WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList),
|
||||
WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList),
|
||||
WorldMapCreator.createDataSeries(geoList),
|
||||
Arrays.toString(WorldPieCreator.createSeriesData(worldTimes))
|
||||
};
|
||||
for (String test : series) {
|
||||
int opened = StringUtils.countMatches(test, "{");
|
||||
int closed = StringUtils.countMatches(test, "}");
|
||||
Assert.assertEquals(opened, closed);
|
||||
opened = StringUtils.countMatches(test, "[");
|
||||
closed = StringUtils.countMatches(test, "]");
|
||||
Assert.assertEquals(opened, closed);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4,12 +4,11 @@
|
||||
*/
|
||||
package test.java.utils;
|
||||
|
||||
import main.java.com.djrapitops.plan.database.DatabaseTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import main.java.com.djrapitops.plan.database.DatabaseCommitTest;
|
||||
import main.java.com.djrapitops.plan.database.DatabaseTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -18,7 +17,7 @@ import java.io.IOException;
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({DatabaseCommitTest.class, DatabaseTest.class})
|
||||
@Suite.SuiteClasses({DatabaseTest.class})
|
||||
public class DBTestSuite {
|
||||
@BeforeClass
|
||||
public static void setUp() throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user