Updated Javadoc

This commit is contained in:
Rsl1122 2017-10-02 21:52:13 +03:00
parent 46f1ee40b2
commit 86ea8ec02c
48 changed files with 210 additions and 341 deletions

View File

@ -328,8 +328,6 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
* Initializes the database according to settings in the config.
* <p>
* If database connection can not be established plugin is disabled.
*
* @return true if init was successful, false if not.
*/
private void initDatabase() throws DatabaseInitException {
databases = new HashSet<>();

View File

@ -58,7 +58,7 @@ public class ServerSpecificSettings {
}
config.set(path, value);
Log.debug(" " + path + ": " + value);
} catch (NullPointerException e) {
} catch (NullPointerException ignored) {
}
changedSomething = true;
}

View File

@ -53,8 +53,8 @@ public class AnalyzeCommand extends SubCommand {
}
Plan plugin = Plan.getInstance();
Optional<String> serverName = plugin.getDB().getServerTable().getServerName(serverUUID);
if (serverName.isPresent()) {
String target = "/server/" + serverName.get();
serverName.ifPresent(name -> {
String target = "/server/" + name;
String url = plugin.getInfoManager().getLinkTo(target);
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
@ -70,7 +70,7 @@ public class AnalyzeCommand extends SubCommand {
}
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
}
}
});
}
@Override

View File

@ -13,8 +13,8 @@ import java.util.Objects;
* <p>
* Includes:
* <ul>
* <li>World & GameMode playtimes</li>
* <li>Player & Mob kills</li>
* <li>World and GameMode playtimes</li>
* <li>Player and Mob kills</li>
* <li>Deaths</li>
* </ul>
* <p>

View File

@ -118,10 +118,8 @@ public abstract class Database {
/**
* Initiates the database.
* <p>
* Default method returns false.
*
* @return Was the initiation successful?
* @throws DatabaseInitException if SQLException or other exception occurs.
*/
public void init() throws DatabaseInitException {
}
@ -175,7 +173,7 @@ public abstract class Database {
public abstract void setVersion(int version) throws SQLException;
/**
* Closes the database & it's resources.
* Closes the database and it's resources.
*
* @throws SQLException If a database error occurs.
*/

View File

@ -18,7 +18,7 @@ import java.sql.SQLException;
import java.util.UUID;
/**
* Class containing main logic for different data related save & load functionality.
* Class containing main logic for different data related save and load functionality.
*
* @author Rsl1122
* @since 2.0.0
@ -29,9 +29,6 @@ public abstract class SQLDB extends Database {
private boolean open = false;
private ITask dbCleanTask;
/**
* @param plugin
*/
public SQLDB(IPlan plugin) {
super(plugin);
usingMySQL = getName().equals("MySQL");
@ -62,7 +59,7 @@ public abstract class SQLDB extends Database {
* Converts Unsaved Bukkit player files to database data.
* Cleans the database.
*
* @return Was the Initialization successful.
* @throws DatabaseInitException if Database fails to initiate.
*/
@Override
public void init() throws DatabaseInitException {
@ -140,8 +137,6 @@ public abstract class SQLDB extends Database {
* Creates the tables that contain data.
* <p>
* Updates table columns to latest schema.
*
* @return true if successful.
*/
private void createTables() throws DatabaseInitException {
Benchmark.start("Create tables");
@ -152,7 +147,9 @@ public abstract class SQLDB extends Database {
}
/**
* @return
* Get all tables in a good order.
*
* @return Table array.
*/
public Table[] getAllTables() {
return new Table[]{
@ -164,7 +161,7 @@ public abstract class SQLDB extends Database {
}
/**
* Get all tables except securityTable for removal of user data.
* Get all tables for removal of data.
*
* @return Tables in the order the data should be removed in.
*/
@ -184,7 +181,9 @@ public abstract class SQLDB extends Database {
public abstract void setupDataSource() throws DatabaseInitException;
/**
* @throws SQLException
* Closes the SQLDB
*
* @throws SQLException DB Error
*/
@Override
public void close() throws SQLException {
@ -205,10 +204,6 @@ public abstract class SQLDB extends Database {
return versionTable.getVersion();
}
/**
* @param version
* @throws SQLException
*/
@Override
public void setVersion(int version) throws SQLException {
versionTable.setVersion(version);
@ -219,10 +214,6 @@ public abstract class SQLDB extends Database {
return versionTable.isNewDatabase();
}
/**
* @param uuid
* @return
*/
@Override
public boolean wasSeenBefore(UUID uuid) {
if (uuid == null) {
@ -267,9 +258,6 @@ public abstract class SQLDB extends Database {
Log.info("Clean complete.");
}
/**
* @return
*/
@Override
public void removeAllData() throws SQLException {
setStatus("Clearing all data");

View File

@ -22,10 +22,6 @@ public class SQLiteDB extends SQLDB {
this(plugin, "database");
}
/**
* @param plugin
* @param dbName
*/
public SQLiteDB(Plan plugin, String dbName) {
super(plugin);
this.dbName = dbName;

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.database.sql;
/**
* SqlParser Class for parsing table creation, removal & modification statements.
* SqlParser Class for parsing table creation, removal and modification statements.
*
* @author Rsl1122
* @since 3.7.0

View File

@ -94,9 +94,9 @@ public class ActionsTable extends UserIDTable {
/**
* Used to get all Actions done by a user on this server.
*
* @param uuid
* @return
* @throws SQLException
* @param uuid UUID of the player
* @return List of actions done by the player. Does not include the kills.
* @throws SQLException DB Error
*/
public List<Action> getActions(UUID uuid) throws SQLException {
List<Action> actions = new ArrayList<>();

View File

@ -29,10 +29,6 @@ public class CommandUseTable extends Table {
private final ServerTable serverTable;
private String insertStatement;
/**
* @param db
* @param usingMySQL
*/
public CommandUseTable(SQLDB db, boolean usingMySQL) {
super("plan_commandusages", db, usingMySQL);
serverTable = db.getServerTable();
@ -43,9 +39,6 @@ public class CommandUseTable extends Table {
+ ") VALUES (?, ?, " + serverTable.statementSelectServerID + ")";
}
/**
* @return
*/
@Override
public void createTable() throws DBCreateTableException {
ServerTable serverTable = db.getServerTable();
@ -64,7 +57,7 @@ public class CommandUseTable extends Table {
* Used to get all commands used in this server.
*
* @return command - times used Map
* @throws SQLException
* @throws SQLException DB Error
*/
public Map<String, Integer> getCommandUse() throws SQLException {
return getCommandUse(Plan.getServerUUID());
@ -75,7 +68,7 @@ public class CommandUseTable extends Table {
*
* @param serverUUID UUID of the server.
* @return command - times used Map
* @throws SQLException
* @throws SQLException DB Error
*/
public Map<String, Integer> getCommandUse(UUID serverUUID) throws SQLException {
Map<String, Integer> commandUse = new HashMap<>();

View File

@ -37,9 +37,6 @@ public class IPsTable extends UserIDTable {
+ "?, ?)";
}
/**
* @return if the table was created successfully
*/
@Override
public void createTable() throws DBCreateTableException {
createTable(TableSqlParser.createTable(tableName)

View File

@ -30,10 +30,6 @@ public class KillsTable extends UserIDTable {
private final SessionsTable sessionsTable;
private String insertStatement;
/**
* @param db
* @param usingMySQL
*/
public KillsTable(SQLDB db, boolean usingMySQL) {
super("plan_kills", db, usingMySQL);
sessionsTable = db.getSessionsTable();
@ -49,9 +45,6 @@ public class KillsTable extends UserIDTable {
+ "?, ?, ?)";
}
/**
* @return
*/
@Override
public void createTable() throws DBCreateTableException {
createTable(TableSqlParser.createTable(tableName)
@ -154,7 +147,7 @@ public class KillsTable extends UserIDTable {
public Map<UUID, List<PlayerKill>> getPlayerKills(UUID serverUUID) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
String usersVictimIDColumn = usersTable + "." + usersTable.getColumnID();
String usersKillerIDColumn = "a." + usersTable.getColumnID();
String usersVictimUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as victim_uuid";
@ -206,7 +199,7 @@ public class KillsTable extends UserIDTable {
return;
}
PreparedStatement statement = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement(insertStatement);
String[] gms = GMTimes.getGMKeyArray();
for (UUID serverUUID : allSessions.keySet()) {
@ -240,7 +233,7 @@ public class KillsTable extends UserIDTable {
public Map<Integer, List<PlayerKill>> getAllPlayerKillsBySessionID() throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as victim_uuid";
statement = connection.prepareStatement("SELECT " +

View File

@ -41,9 +41,6 @@ public class NicknamesTable extends UserIDTable {
"?)";
}
/**
* @return if the table was created successfully
*/
@Override
public void createTable() throws DBCreateTableException {
createTable(TableSqlParser.createTable(tableName)

View File

@ -108,7 +108,7 @@ public class ServerTable extends Table {
*
* @param info Info to instert (All variables should be present.
* @throws IllegalStateException if one of the ServerInfo variables is null
* @throws SQLException
* @throws SQLException DB Error
*/
private void saveNewServerInfo(ServerInfo info) throws SQLException {
UUID uuid = info.getUuid();
@ -137,7 +137,7 @@ public class ServerTable extends Table {
*
* @param serverUUID UUID of the server.
* @return ID or or empty optional.
* @throws SQLException
* @throws SQLException DB Error
*/
public Optional<Integer> getServerID(UUID serverUUID) throws SQLException {
PreparedStatement statement = null;
@ -164,7 +164,7 @@ public class ServerTable extends Table {
*
* @param serverUUID UUID of the server.
* @return Name or empty optional.
* @throws SQLException
* @throws SQLException DB Error
*/
public Optional<String> getServerName(UUID serverUUID) throws SQLException {
PreparedStatement statement = null;
@ -209,7 +209,7 @@ public class ServerTable extends Table {
* Used to get BungeeCord WebServer info if present.
*
* @return information about Bungee server.
* @throws SQLException
* @throws SQLException DB Error
*/
public Optional<ServerInfo> getBungeeInfo() throws SQLException {
PreparedStatement statement = null;

View File

@ -32,10 +32,6 @@ public class SessionsTable extends UserIDTable {
private final ServerTable serverTable;
private String insertStatement;
/**
* @param db
* @param usingMySQL
*/
public SessionsTable(SQLDB db, boolean usingMySQL) {
super("plan_sessions", db, usingMySQL);
serverTable = db.getServerTable();
@ -52,9 +48,6 @@ public class SessionsTable extends UserIDTable {
+ serverTable.statementSelectServerID + ")";
}
/**
* @return
*/
@Override
public void createTable() throws DBCreateTableException {
createTable(TableSqlParser.createTable(this.tableName)
@ -79,7 +72,7 @@ public class SessionsTable extends UserIDTable {
*
* @param uuid UUID of the player.
* @param session Session of the player that has ended ({@code endSession} has been called)
* @throws SQLException
* @throws SQLException DB Error
*/
public void saveSession(UUID uuid, Session session) throws SQLException {
saveSessionInformation(uuid, session);
@ -99,7 +92,7 @@ public class SessionsTable extends UserIDTable {
*
* @param uuid UUID of the player.
* @param session Session of the player that has ended ({@code endSession} has been called)
* @throws SQLException
* @throws SQLException DB Error
*/
private void saveSessionInformation(UUID uuid, Session session) throws SQLException {
PreparedStatement statement = null;
@ -156,7 +149,7 @@ public class SessionsTable extends UserIDTable {
*
* @param uuid UUID of the player
* @return Map with Sessions that don't contain Kills or WorldTimes.
* @throws SQLException
* @throws SQLException DB Error
*/
private Map<String, List<Session>> getSessionInformation(UUID uuid) throws SQLException {
Map<Integer, String> serverNames = serverTable.getServerNames();
@ -205,7 +198,7 @@ public class SessionsTable extends UserIDTable {
*
* @param uuid UUID of the player.
* @return Milliseconds played on THIS server. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytime(UUID uuid) throws SQLException {
return getPlaytime(uuid, Plan.getServerUUID());
@ -217,7 +210,7 @@ public class SessionsTable extends UserIDTable {
* @param uuid UUID of the player.
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played on THIS server. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytime(UUID uuid, long afterDate) throws SQLException {
return getPlaytime(uuid, Plan.getServerUUID(), afterDate);
@ -229,7 +222,7 @@ public class SessionsTable extends UserIDTable {
* @param uuid UUID of the player.
* @param serverUUID UUID of the server. @see ServerTable
* @return Milliseconds played on the server. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytime(UUID uuid, UUID serverUUID) throws SQLException {
return getPlaytime(uuid, serverUUID, 0L);
@ -242,7 +235,7 @@ public class SessionsTable extends UserIDTable {
* @param serverUUID UUID of the server. @see ServerTable
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played after given epoch ms on the server. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytime(UUID uuid, UUID serverUUID, long afterDate) throws SQLException {
PreparedStatement statement = null;
@ -272,7 +265,7 @@ public class SessionsTable extends UserIDTable {
*
* @param uuid UUID of the Player.
* @return key - ServerName, value ms played
* @throws SQLException
* @throws SQLException DB Error
*/
public Map<String, Long> getPlaytimeByServer(UUID uuid) throws SQLException {
return getPlaytimeByServer(uuid, 0L);
@ -284,7 +277,7 @@ public class SessionsTable extends UserIDTable {
* @param uuid UUID of the Player.
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return key - ServerName, value ms played
* @throws SQLException
* @throws SQLException DB Error
*/
public Map<String, Long> getPlaytimeByServer(UUID uuid, long afterDate) throws SQLException {
Map<Integer, String> serverNames = serverTable.getServerNames();
@ -317,7 +310,7 @@ public class SessionsTable extends UserIDTable {
* Used to get the Total Playtime of THIS Server.
*
* @return Milliseconds played on the server. 0 if server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytimeOfServer() throws SQLException {
return getPlaytimeOfServer(Plan.getServerUUID());
@ -328,7 +321,7 @@ public class SessionsTable extends UserIDTable {
*
* @param serverUUID UUID of the server.
* @return Milliseconds played on the server. 0 if server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytimeOfServer(UUID serverUUID) throws SQLException {
return getPlaytimeOfServer(serverUUID, 0L);
@ -339,7 +332,7 @@ public class SessionsTable extends UserIDTable {
*
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played after given epoch ms on the server. 0 if server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytimeOfServer(long afterDate) throws SQLException {
return getPlaytimeOfServer(Plan.getServerUUID(), afterDate);
@ -351,7 +344,7 @@ public class SessionsTable extends UserIDTable {
* @param serverUUID UUID of the server.
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played after given epoch ms on the server. 0 if server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public long getPlaytimeOfServer(UUID serverUUID, long afterDate) throws SQLException {
PreparedStatement statement = null;
@ -380,7 +373,7 @@ public class SessionsTable extends UserIDTable {
*
* @param uuid UUID of the player.
* @return How many sessions player has. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public int getSessionCount(UUID uuid) throws SQLException {
return getSessionCount(uuid, 0L);
@ -392,7 +385,7 @@ public class SessionsTable extends UserIDTable {
* @param uuid UUID of the player.
* @param afterDate Epoch ms (Session count after this date is calculated)
* @return How many sessions player has. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public int getSessionCount(UUID uuid, long afterDate) throws SQLException {
return getSessionCount(uuid, Plan.getServerUUID(), afterDate);
@ -404,7 +397,7 @@ public class SessionsTable extends UserIDTable {
* @param uuid UUID of the player.
* @param serverUUID UUID of the server.
* @return How many sessions player has. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public int getSessionCount(UUID uuid, UUID serverUUID) throws SQLException {
return getSessionCount(uuid, serverUUID, 0L);
@ -417,7 +410,7 @@ public class SessionsTable extends UserIDTable {
* @param serverUUID UUID of the server.
* @param afterDate Epoch ms (Session count after this date is calculated)
* @return How many sessions player has. 0 if player or server not found.
* @throws SQLException
* @throws SQLException DB Error
*/
public int getSessionCount(UUID uuid, UUID serverUUID, long afterDate) throws SQLException {
PreparedStatement statement = null;

View File

@ -38,10 +38,6 @@ public class TPSTable extends Table {
private final ServerTable serverTable;
private String insertStatement;
/**
* @param db
* @param usingMySQL
*/
public TPSTable(SQLDB db, boolean usingMySQL) {
super("plan_tps", db, usingMySQL);
serverTable = db.getServerTable();
@ -83,7 +79,7 @@ public class TPSTable extends Table {
List<TPS> data = new ArrayList<>();
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement(Select.all(tableName)
.where(columnServerID + "=" + serverTable.statementSelectServerID)
.toString());
@ -109,7 +105,7 @@ public class TPSTable extends Table {
public void insertTPS(TPS tps) throws SQLException {
PreparedStatement statement = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement(insertStatement);
statement.setString(1, Plan.getServerUUID().toString());
@ -129,7 +125,9 @@ public class TPSTable extends Table {
}
/**
* @throws SQLException
* Clean the TPS Table of old data.
*
* @throws SQLException DB Error
*/
public void clean() throws SQLException {
Optional<TPS> allTimePeak = getAllTimePeak();
@ -138,7 +136,7 @@ public class TPSTable extends Table {
p = allTimePeak.get().getPlayers();
}
PreparedStatement statement = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement("DELETE FROM " + tableName +
" WHERE (" + columnDate + "<?)" +
" AND (" + columnPlayers + "" +
@ -170,7 +168,7 @@ public class TPSTable extends Table {
public Optional<TPS> getPeakPlayerCount(UUID serverUUID, long afterDate) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement(Select.all(tableName)
.where(columnServerID + "=" + serverTable.statementSelectServerID)
.and(columnPlayers + "= (SELECT MAX(" + columnPlayers + ") FROM " + tableName + ")")
@ -199,7 +197,7 @@ public class TPSTable extends Table {
public Map<UUID, List<TPS>> getAllTPS() throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
statement = connection.prepareStatement("SELECT " +
@ -244,7 +242,7 @@ public class TPSTable extends Table {
return;
}
PreparedStatement statement = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement(insertStatement);
// Every Server
@ -275,7 +273,7 @@ public class TPSTable extends Table {
public List<TPS> getNetworkOnlineData() throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.prepareStatement("SELECT " +
columnDate + ", " +
"SUM(" + columnPlayers + ") as players" +

View File

@ -3,16 +3,12 @@ package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify;
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;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
/**
* @author Rsl1122
@ -35,9 +31,11 @@ public abstract class Table {
protected final boolean usingMySQL;
/**
* @param name
* @param db
* @param usingMySQL
* Constructor.
*
* @param name Name of the table in the db.
* @param db Database to use.
* @param usingMySQL Is the database using MySQL?
*/
public Table(String name, SQLDB db, boolean usingMySQL) {
this.tableName = name;
@ -45,9 +43,6 @@ public abstract class Table {
this.usingMySQL = usingMySQL;
}
/**
* @return
*/
public abstract void createTable() throws DBCreateTableException;
protected void createTable(String sql) throws DBCreateTableException {
@ -59,29 +54,35 @@ public abstract class Table {
}
/**
* @return
* @throws SQLException
* Used to get a new Connection to the Database.
*
* @return SQL Connection
* @throws SQLException DB Error
*/
protected Connection getConnection() throws SQLException {
return db.getConnection();
}
/**
* @return
* @throws SQLException
* Get the Database Schema version from VersionTable.
*
* @return Database Schema version.
* @throws SQLException DB Error
*/
public int getVersion() throws SQLException {
return db.getVersion();
}
/**
* @param statementString
* @return
* @throws SQLException
* Executes an SQL Statement
*
* @param statementString Statement to execute
* @return What execute returns.
* @throws SQLException DB error
*/
protected boolean execute(String statementString) throws SQLException {
Statement statement = null;
try (Connection connection = getConnection()){
try (Connection connection = getConnection()) {
statement = connection.createStatement();
boolean b = statement.execute(statementString);
commit(connection);
@ -108,35 +109,25 @@ public abstract class Table {
}
/**
* @param toClose
* Closes DB elements.
*
* @param toClose All elements to close.
*/
protected void close(AutoCloseable... toClose) {
MiscUtils.close(toClose);
}
/**
* @return
*/
public String getTableName() {
return tableName;
}
/**
* @return
* Removes all data from the table.
*/
public void removeAllData() throws SQLException {
execute("DELETE FROM " + tableName);
}
/**
* @param <T>
* @param objects
* @return
*/
protected <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
return DBUtils.splitIntoBatchesId(objects);
}
protected void addColumns(String... columnInfo) {
for (int i = 0; i < columnInfo.length; i++) {
columnInfo[i] = "ALTER TABLE " + tableName + " ADD " + (usingMySQL ? "" : "COLUMN ") + columnInfo[i];

View File

@ -89,10 +89,7 @@ public class UserInfoTable extends UserIDTable {
.toString());
statement.setString(1, uuid.toString());
set = statement.executeQuery();
if (set.next()) {
return set.getInt("c") >= 1;
}
return false;
return set.next() && set.getInt("c") >= 1;
} finally {
close(set, statement);
}

View File

@ -25,10 +25,6 @@ public class UsersTable extends UserIDTable {
private final String columnTimesKicked = "times_kicked";
private String insertStatement;
/**
* @param db
* @param usingMySQL
*/
public UsersTable(SQLDB db, boolean usingMySQL) {
super("plan_users", db, usingMySQL);
statementSelectID = "(" + Select.from(tableName, tableName + "." + columnID).where(columnUUID + "=?").toString() + ")";
@ -38,9 +34,6 @@ public class UsersTable extends UserIDTable {
columnName);
}
/**
* @return
*/
@Override
public void createTable() throws DBCreateTableException {
createTable(TableSqlParser.createTable(tableName)
@ -79,8 +72,10 @@ public class UsersTable extends UserIDTable {
}
/**
* Remove a user from Users Table.
*
* @param uuid the UUID of the user that should be removed.
* @return if the removal was successful.
* @throws SQLException DB Error
*/
@Override
public void removeUser(UUID uuid) throws SQLException {
@ -111,18 +106,20 @@ public class UsersTable extends UserIDTable {
}
/**
* @param playername
* @return
* @throws SQLException
* Get UUID of a player.
*
* @param playerName Name of a player
* @return UUID of the player
* @throws SQLException DB Error
*/
public UUID getUuidOf(String playername) throws SQLException {
public UUID getUuidOf(String playerName) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try (Connection connection = getConnection()) {
statement = connection.prepareStatement(Select.from(tableName, columnUUID)
.where("UPPER(" + columnName + ")=UPPER(?)")
.toString());
statement.setString(1, playername);
statement.setString(1, playerName);
set = statement.executeQuery();
if (set.next()) {
String uuidS = set.getString(columnUUID);
@ -156,7 +153,7 @@ public class UsersTable extends UserIDTable {
* @param uuid UUID of the player.
* @param registered Register date.
* @param name Name of the player.
* @throws SQLException
* @throws SQLException DB Error
* @throws IllegalArgumentException If uuid or name are null.
*/
public void registerUser(UUID uuid, long registered, String name) throws SQLException {
@ -185,10 +182,7 @@ public class UsersTable extends UserIDTable {
.toString());
statement.setString(1, uuid.toString());
set = statement.executeQuery();
if (set.next()) {
return set.getInt("c") >= 1;
}
return false;
return set.next() && set.getInt("c") >= 1;
} finally {
close(set, statement);
}
@ -308,8 +302,8 @@ public class UsersTable extends UserIDTable {
* This method is for batch operations, and should not be used to add information of users.
* Use UserInfoTable instead.
*
* @param users
* @throws SQLException
* @param users Users to insert
* @throws SQLException DB Error
*/
public void insertUsers(Map<UUID, UserInfo> users) throws SQLException {
if (Verify.isEmpty(users)) {

View File

@ -16,17 +16,10 @@ import java.sql.SQLException;
*/
public class VersionTable extends Table {
/**
* @param db
* @param usingMySQL
*/
public VersionTable(SQLDB db, boolean usingMySQL) {
super("plan_version", db, usingMySQL);
}
/**
* @return
*/
@Override
public void createTable() throws DBCreateTableException {
createTable(TableSqlParser.createTable(tableName)
@ -77,8 +70,10 @@ public class VersionTable extends Table {
}
/**
* @param version
* @throws SQLException
* Set the DB Schema version
*
* @param version DB Schema version
* @throws SQLException DB Error
*/
public void setVersion(int version) throws SQLException {
removeAllData();

View File

@ -32,7 +32,7 @@ import java.util.UUID;
* <p>
* clearTable methods can be used to clear the table beforehand.
* <p>
* Server & User tables should be copied first.
* Server and User tables should be copied first.
*
* @author Rsl1122
* @since 4.0.0
@ -42,7 +42,7 @@ public class BatchOperationTable extends Table {
/**
* Constructor, call to access copy functionality.
*
* @param database
* @param database Database to copy things from
* @throws IllegalStateException if database.init has not been called.
* @throws ClassCastException if database is not SQLDB.
*/

View File

@ -14,7 +14,7 @@ import java.util.*;
* <ul>
* <li>PlayerName cache, used for reducing database calls on chat events</li>
* <li>DisplayName cache, used for reducing database calls on chat events</li>
* <li>FirstSession MessageCount Map, used for tracking first session & message count on that session.</li>
* <li>FirstSession MessageCount Map, used for tracking first session and message count on that session.</li>
* </ul>
*
* @author Rsl1122
@ -114,8 +114,10 @@ public class DataCache extends SessionCache {
}
/**
* @param uuid
* @return
* Check if a session is player's first session on the server.
*
* @param uuid UUID of the player
* @return true / false
*/
public boolean isFirstSession(UUID uuid) {
return firstSessionInformation.containsKey(uuid);

View File

@ -318,7 +318,7 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostNetworkPageContentWebAPI.class).sendNetworkContent(webServerAddress, HtmlStructure.createServerContainer(plugin));
} catch (WebAPIException e) {
} catch (WebAPIException ignored) {
}
}
}

View File

@ -124,8 +124,8 @@ public class BukkitServerInfoManager {
/**
* Saves Bungee connection information to local file on Bukkit servers.
*
* @param address
* @throws IOException
* @param address Address to save
* @throws IOException If ServerInfo file can not be written to.
*/
public void saveBungeeConnectionAddress(String address) throws IOException {
serverInfoFile.saveInfo(serverInfo, new ServerInfo(-1, null, "Bungee", address, -1));

View File

@ -20,7 +20,7 @@ import java.util.UUID;
/**
* Manages local server info file.
* <p>
* ServerInfo.yml contains current server's ID, UUID & Bungee WebServer connection information.
* ServerInfo.yml contains current server's ID, UUID and Bungee WebServer connection information.
* It
*
* @author Rsl1122

View File

@ -34,7 +34,7 @@ public abstract class Queue<T> {
}
/**
* Used to stop the queue processing & get the unprocessed objects.
* Used to stop the queue processing and get the unprocessed objects.
*
* @return List of unprocessed objects.
*/

View File

@ -27,14 +27,12 @@ import java.util.UUID;
public class ResponseHandler extends APIResponseHandler {
private final IPlan plugin;
private final WebServer webServer;
private final boolean usingHttps;
public ResponseHandler(IPlan plugin, WebServer webServer) {
super(webServer.getWebAPI());
this.plugin = plugin;
this.webServer = webServer;
this.usingHttps = webServer.isUsingHTTPS();
}

View File

@ -43,9 +43,6 @@ public class WebServer {
private boolean usingHttps = false;
/**
* @param plugin
*/
public WebServer(IPlan plugin) {
this.plugin = plugin;
this.port = Settings.WEBSERVER_PORT.getNumber();

View File

@ -13,7 +13,9 @@ import main.java.com.djrapitops.plan.systems.info.InformationManager;
public class AnalysisPageResponse extends Response {
/**
* @param informationManager
* Constructor.
*
* @param informationManager InformationManager to use for getting the Html
* @throws NullPointerException if AnalysisData has not been cached after 1 second.
*/
public AnalysisPageResponse(InformationManager informationManager) {

View File

@ -9,7 +9,7 @@ import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
import java.util.*;
/**
* @author Fuzzlemann & Rsl1122
* @author Fuzzlemann and Rsl1122
*/
public class WebAPIManager {

View File

@ -17,7 +17,7 @@ import java.util.UUID;
/**
* WebAPI for requesting Inspect plugins tab contents from a Bukkit Server.
* <p>
* Call: Bungee -> Bukkit
* Call: Bungee to Bukkit
* <p>
* Bad Requests:
* - Called a Bungee Server

View File

@ -16,7 +16,7 @@ import java.util.UUID;
/**
* WebAPI for posting Inspect page Plugins tab contents to the Bungee server.
* <p>
* Call: Bukkit -> Bungee
* Call: Bukkit to Bungee
* <p>
* Bad Requests:
* - Did not include uuid

View File

@ -22,7 +22,7 @@ import java.util.UUID;
/**
* WebAPI for requesting Bungee Server to request Plugins tab contents from every server.
* <p>
* Call: Bukkit -> Bungee
* Call: Bukkit to Bungee
* <p>
* Bad Requests:
* - Called a Bukkit Server

View File

@ -16,15 +16,19 @@ public class Benchmark {
}
/**
* @param source
* Start a benchmark.
*
* @param source Thing to bench.
*/
public static void start(String source) {
getBenchUtil().start(source);
}
/**
* @param source
* @return
* End a benchmark.
*
* @param source Thing to stop benching.
* @return ms it took.
*/
public static long stop(String source) {
long ms = getBenchUtil().stop(source);

View File

@ -23,42 +23,34 @@ public class FormatUtils {
}
/**
* @param ms
* @return
* Format time amount according to the config settings.
*
* @param ms Milliseconds.
* @return String formatted with the config settings.
*/
public static String formatTimeAmount(long ms) {
return formatMilliseconds(ms);
}
/**
* @param before
* @param after
* @return
* Format the time difference between an end point and a start point.
*
* @param before Epoch ms.
* @param after Epoch ms.
* @return String formatted with the config settings.
*/
public static String formatTimeAmountDifference(long before, long after) {
return formatMilliseconds(Math.abs(after - before));
}
/**
* @param epochMs
* @return
*/
public static String formatTimeStamp(long epochMs) {
return FormattingUtils.formatTimeStamp(epochMs);
}
/**
* @param epochMs
* @return
*/
public static String formatTimeStampSecond(long epochMs) {
return FormattingUtils.formatTimeStampSecond(epochMs);
}
/**
* @param epochMs
* @return
*/
public static String formatTimeStampYear(long epochMs) {
return FormattingUtils.formatTimeStampYear(epochMs);
}
@ -66,8 +58,8 @@ public class FormatUtils {
/**
* Removes letters from a string leaving only numbers and dots.
*
* @param dataPoint
* @return
* @param dataPoint String to remove stuff from.
* @return String with the stuff removed.
*/
public static String removeLetters(String dataPoint) {
return Format.create(dataPoint)
@ -78,8 +70,10 @@ public class FormatUtils {
}
/**
* @param dataPoint
* @return
* Removes numbers from a string leaving only letters.
*
* @param dataPoint String to remove stuff from.
* @return String with the stuff removed.
*/
public static String removeNumbers(String dataPoint) {
return Format.create(dataPoint)
@ -176,8 +170,10 @@ public class FormatUtils {
}
/**
* @param d
* @return
* Remove extra decimals from the end of the double.
*
* @param d Double.
* @return String format of the double.
*/
public static String cutDecimals(double d) {
return df.format(d);

View File

@ -28,7 +28,6 @@ public class ManageUtils {
*
* @param dbName Name of database (mysql/sqlite)
* @param copyFromDB Database you want to backup.
* @return success?
*/
public static void backup(String dbName, Database copyFromDB) throws DatabaseInitException, SQLException {
Plan plugin = Plan.getInstance();
@ -66,7 +65,6 @@ public class ManageUtils {
* @param clearAndCopyToDB Database that will be cleared data will be copied
* to.
* @param copyFromDB Database where data will be copied from
* @return success?
*/
public static void clearAndCopy(Database clearAndCopyToDB, Database copyFromDB) throws SQLException {
BatchOperationTable toDB = new BatchOperationTable(clearAndCopyToDB);

View File

@ -48,9 +48,11 @@ public class MiscUtils {
}
/**
* @param args
* @param sender
* @return
* Get a players name that matches the given arguments or name of the sender.
*
* @param args Arguments of command.
* @param sender Sender of command
* @return Player name.
*/
public static String getPlayerName(String[] args, ISender sender) {
return getPlayerName(args, sender, Permissions.INSPECT_OTHER);
@ -61,7 +63,7 @@ public class MiscUtils {
*
* @param args Arguments of a command, must not be empty if console sender.
* @param sender Command sender
* @param perm
* @param perm Permission to use when checking. No permission will notify user.
* @return The name of the player (first argument or sender)
*/
public static String getPlayerName(String[] args, ISender sender, Permissions perm) {

View File

@ -97,8 +97,10 @@ public class Analysis {
}
/**
* Analyze data in the db about this server.
*
* @param infoManager InformationManager of the plugin.
* @return
* @return Success?
*/
public boolean analyzeData(InformationManager infoManager, Database db) {
try {
@ -210,7 +212,9 @@ public class Analysis {
}
/**
* @return
* Check whether or not analysis is being run.
*
* @return true / false (state)
*/
public boolean isAnalysisBeingRun() {
return taskId != -1;

View File

@ -26,13 +26,6 @@ public class AnalysisUtils {
throw new IllegalStateException("Utility class");
}
/**
* @param now
* @param lastPlayed
* @param playTime
* @param loginTimes
* @return
*/
public static boolean isActive(long now, long lastPlayed, long playTime, int loginTimes) {
int timeToActive = 10;
long twoWeeks = 1209600000;
@ -41,12 +34,6 @@ public class AnalysisUtils {
&& playTime > 60 * timeToActive;
}
/**
* @param registered
* @param scale
* @param now
* @return
*/
public static long getNewPlayers(List<Long> registered, long scale, long now) {
long newPlayers = 0;
if (!registered.isEmpty()) {
@ -59,10 +46,6 @@ public class AnalysisUtils {
return newPlayers;
}
/**
* @param data
* @return
*/
public static List<Long> transformSessionDataToLengths(Collection<Session> data) {
return data.stream()
.filter(Objects::nonNull)
@ -71,12 +54,6 @@ public class AnalysisUtils {
.collect(Collectors.toList());
}
/**
* @param analysisType
* @param source
* @param uuids
* @return
*/
public static String getTotal(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType == null) {
return source.parseContainer("Err ", "Null Analysistype. ");
@ -112,12 +89,6 @@ public class AnalysisUtils {
.filter(value -> !value.equals(-1L));
}
/**
* @param analysisType
* @param source
* @param uuids
* @return
*/
public static String getAverage(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType == null) {
return source.parseContainer("Err ", "Null Analysistype. ");
@ -150,12 +121,6 @@ public class AnalysisUtils {
}
}
/**
* @param analysisType
* @param source
* @param uuids
* @return
*/
public static String getBooleanPercentage(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType != AnalysisType.BOOLEAN_PERCENTAGE) {
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
@ -172,12 +137,6 @@ public class AnalysisUtils {
}
}
/**
* @param analysisType
* @param source
* @param uuids
* @return
*/
public static String getBooleanTotal(AnalysisType analysisType, PluginData source, Collection<UUID> uuids) {
if (analysisType != AnalysisType.BOOLEAN_TOTAL) {
return source.parseContainer("Err ", "Wrong Analysistype specified: " + analysisType.name());
@ -224,11 +183,6 @@ public class AnalysisUtils {
return uniqueJoins.size();
}
/**
* @param sessions
* @param scale
* @return
*/
public static int getUniqueJoinsPerDay(Map<UUID, List<Session>> sessions, long scale) {
Map<Integer, Set<UUID>> uniqueJoins = new HashMap<>();
long now = MiscUtils.getTime();

View File

@ -8,7 +8,6 @@ import main.java.com.djrapitops.plan.data.UserInfo;
import main.java.com.djrapitops.plan.systems.webserver.response.PlayersPageResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@ -28,9 +27,6 @@ public class ExportUtility {
throw new IllegalStateException("Utility class");
}
/**
* @return
*/
public static File getFolder() {
String path = Settings.ANALYSIS_EXPORT_PATH.toString();
@ -50,10 +46,6 @@ public class ExportUtility {
return folder;
}
/**
* @param analysisData
* @param playerNames
*/
public static void export(AnalysisData analysisData, List<String> playerNames) {
if (!Settings.ANALYSIS_EXPORT.isTrue()) {
return;
@ -84,20 +76,12 @@ public class ExportUtility {
// }
}
/**
* @param folder
* @return
*/
public static File getPlayersFolder(File folder) {
File playersFolder = new File(folder, "player");
playersFolder.mkdirs();
return playersFolder;
}
/**
* @param userInfo
* @param playersFolder
*/
public static void writeInspectHtml(UserInfo userInfo, File playersFolder, String playerHtml) {
if (!Settings.ANALYSIS_EXPORT.isTrue()) {
return;
@ -127,12 +111,6 @@ public class ExportUtility {
// }
}
/**
* @param analysisData
* @param serverFolder
* @throws FileNotFoundException
* @throws IOException
*/
public static void writeAnalysisHtml(AnalysisData analysisData, File serverFolder) throws IOException {
if (!Settings.ANALYSIS_EXPORT.isTrue()) {
return;

View File

@ -18,26 +18,29 @@ public class MapComparator {
}
/**
* Sorts a HashMap of String, Integer by the Values of the HashMap.
* Sorts a Map of String, Integer by the Values of the Map.
*
* @param hashMap
* @param map Map to sort
* @return List with String Array, where first value is the value and second
* is the key.
*/
public static List<String[]> sortByValue(Map<String, Integer> hashMap) {
public static List<String[]> sortByValue(Map<String, Integer> map) {
List<String[]> sortedList = new ArrayList<>();
hashMap.keySet().forEach(key -> sortedList.add(new String[]{String.valueOf(hashMap.get(key)), key}));
map.keySet().forEach(key -> sortedList.add(new String[]{String.valueOf(map.get(key)), key}));
sortedList.sort(Comparator.comparingInt(strings -> Integer.parseInt(strings[0])));
return sortedList;
}
/**
* @param hashMap
* @return
* Sorts a Map of String, Long by the Values of the Map.
*
* @param map Map to sort
* @return List with String Array, where first value is the value and second
* is the key.
*/
public static List<String[]> sortByValueLong(Map<String, Long> hashMap) {
public static List<String[]> sortByValueLong(Map<String, Long> map) {
List<String[]> sortedList = new ArrayList<>();
hashMap.keySet().forEach(key -> sortedList.add(new String[]{String.valueOf(hashMap.get(key)), key}));
map.keySet().forEach(key -> sortedList.add(new String[]{String.valueOf(map.get(key)), key}));
sortedList.sort(Comparator.comparing(strings -> Long.valueOf(strings[0])));
return sortedList;
}

View File

@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.utilities.comparators;
import java.util.Comparator;
/**
* Compares Strings & sorts them by length
* Compares Strings and sorts them by length
*
* @author Rsl1122
* @since 3.6.2

View File

@ -28,11 +28,12 @@ public class Hastebin {
/**
* Uploads the content safely to Hastebin.
* Longer than allowed content is being uploaded too.
*
* @return The link to the Dump Log
* @implNote Splits the content into parts of 390.000 chars each,
* <p>
* Splits the content into parts of 390.000 chars each,
* uploads the parts in reverse order and adds the last link (if present)
* at each end of the following part, that's why the redundancy of 10.000 chars exists.
*
* @return The link to the Dump Log
* @see #split(String)
*/
public static String safeUpload(String content) {

View File

@ -413,23 +413,15 @@ public class HtmlStructure {
String serverName = plugin.getServerInfoManager().getServerName();
String address = "../server/" + serverName;
StringBuilder b = new StringBuilder("<div class=\"column\">");
// Header
b.append("<div class=\"box-header\"><h2><i class=\"fa fa-server\" aria-hidden=\"true\"></i> ")
.append(serverName)
.append("</h2></div>");
// Online players
b.append("<div class=\"box\"><p>").append(online).append("/").append(maxPlayers)
.append(" Players Online</p></div>");
// Footer
b.append("<div class=\"box-footer\"><p>Last Refresh: ").append(refresh).append("</p>");
b.append("<a href=\"").append(address).append("\" class=\"button right\">Analysis</a>");
b.append("</div>").append("</div>");
return b.toString();
return "<div class=\"column\">" + "<div class=\"box-header\"><h2><i class=\"fa fa-server\" aria-hidden=\"true\"></i> " +
serverName +
"</h2></div>" +
"<div class=\"box\"><p>" + online + "/" + maxPlayers +
" Players Online</p></div>" +
"<div class=\"box-footer\"><p>Last Refresh: " + refresh + "</p>" +
"<a href=\"" + address + "\" class=\"button right\">Analysis</a>" +
"</div></div>";
}
public static String parseOfflineServerContainer(String oldContent) {

View File

@ -23,9 +23,11 @@ public class HtmlUtils {
}
/**
* @param html
* @param replaceMap
* @return
* Replaces ${placeholder} placeholders.
*
* @param html Html to replace placeholders from
* @param replaceMap Placeholders and values
* @return Html with placeholders replaced
*/
public static String replacePlaceholders(String html, Map<String, Serializable> replaceMap) {
StrSubstitutor sub = new StrSubstitutor(replaceMap);
@ -63,16 +65,20 @@ public class HtmlUtils {
}
/**
* @param string
* @return
* Attempts to remove XSS components.
*
* @param string String to remove XSS components from
* @return String but with the components removed
*/
public static String removeXSS(String string) {
return string.replace("<!--", "").replace("-->", "").replace("</script>", "");
return string.replace("<!--", "").replace("-->", "").replace("</script>", "").replace("<script>", "");
}
/**
* @param string
* @return
* Changes Minecraft color codes to HTML span elements with correct color class assignments.
*
* @param string String to replace Minecraft color codes from
* @return String with span elements.
*/
public static String swapColorsToSpan(String string) {
Html[] replacer = new Html[]{Html.COLOR_0, Html.COLOR_1, Html.COLOR_2, Html.COLOR_3,

View File

@ -8,7 +8,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* Class for creating scatter graph data from Chunk & Entity load snapshots with TPS task.
* Class for creating scatter graph data from Chunk and Entity load snapshots with TPS task.
*
* @author Rsl1122
* @see TPSCountTimer

View File

@ -13,7 +13,7 @@ public class WorldPieCreator {
}
/**
* Used to create HighCharts series string for series & drilldown.
* Used to create HighCharts series string for series and drilldown.
*
* @param worldTimes WorldTimes object.
* @return String array, index 0: Series data, 1: drilldown data

View File

@ -26,32 +26,36 @@ public class UUIDUtility {
}
/**
* @param playername
* @return
* Get UUID of a player.
*
* @param playerName Player's name
* @return UUID of the player.
*/
public static UUID getUUIDOf(String playername) {
public static UUID getUUIDOf(String playerName) {
try {
return getUUIDOf(playername, MiscUtils.getIPlan().getDB());
return getUUIDOf(playerName, MiscUtils.getIPlan().getDB());
} catch (Exception e) {
return null;
}
}
/**
* @param playername
* @param db
* @return
* Get UUID of a player.
*
* @param playerName Player's name
* @param db Database to check from.
* @return UUID of the player
*/
public static UUID getUUIDOf(String playername, Database db) {
public static UUID getUUIDOf(String playerName, Database db) {
UUID uuid = null;
try {
uuid = db.getUsersTable().getUuidOf(playername);
uuid = db.getUsersTable().getUuidOf(playerName);
} catch (SQLException e) {
Log.toLog("UUIDUtility", e);
}
try {
if (uuid == null) {
uuid = UUIDFetcher.getUUIDOf(playername);
uuid = UUIDFetcher.getUUIDOf(playerName);
}
} catch (Exception | NoClassDefFoundError ignored) {
/* Ignored */