Fixed some method calls

This commit is contained in:
Rsl1122 2018-01-15 15:54:33 +02:00
parent 0aed988e22
commit 902c7c2470
30 changed files with 247 additions and 492 deletions

View File

@ -19,7 +19,6 @@
*/
package com.djrapitops.plan;
import com.djrapitops.plan.api.API;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanCommand;
import com.djrapitops.plan.data.plugin.HookHandler;
@ -31,11 +30,10 @@ import com.djrapitops.plan.system.BukkitSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.processing.ProcessingQueue;
import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.processing.processors.importing.importers.OfflinePlayerImporter;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem;
@ -47,25 +45,21 @@ import com.djrapitops.plan.systems.info.BukkitInformationManager;
import com.djrapitops.plan.systems.info.ImporterManager;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.systems.info.server.BukkitServerInfoManager;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plan.utilities.metrics.BStats;
import com.djrapitops.plugin.BukkitPlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.List;
import java.util.UUID;
/**
@ -79,11 +73,10 @@ import java.util.UUID;
*/
public class Plan extends BukkitPlugin implements PlanPlugin {
private API api;
private BukkitSystem system;
private Systems systems;
private ProcessingQueue processingQueue;
private HookHandler hookHandler; // Manages 3rd party data sources
private BukkitInformationManager infoManager;
@ -91,22 +84,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
private ServerVariableHolder serverVariableHolder;
/**
* Used to get the PlanAPI. @see API
*
* @return API of the current instance of Plan.
* @throws IllegalStateException If onEnable method has not been called on
* Plan and the instance is null.
* @throws NoClassDefFoundError If Plan is not installed.
*/
public static API getPlanAPI() throws NoClassDefFoundError {
Plan instance = getInstance();
if (instance == null) {
throw new IllegalStateException("Plugin not enabled properly, Singleton instance is null.");
}
return instance.getApi();
}
/**
* Used to get the plugin-instance singleton.
*
@ -162,7 +139,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
DBSystem.getInstance().enable();
Benchmark.start("WebServer Initialization");
processingQueue = new ProcessingQueue();
serverInfoManager = new BukkitServerInfoManager(this);
infoManager = new BukkitInformationManager(this);
@ -182,8 +158,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
TaskSystem.getInstance().enable();
this.api = new API(this);
boolean usingBungeeWebServer = infoManager.isUsingAnotherWebServer();
boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
@ -234,25 +208,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
//Clears the page cache
ResponseCache.clearCache();
// Processes unprocessed processors
if (processingQueue != null) {
List<Processor> processors = processingQueue.stopAndReturnLeftovers();
if (!reloading) {
Log.info("Processing unprocessed processors. (" + processors.size() + ")"); // TODO Move to Locale
for (Processor processor : processors) {
processor.process();
}
} else {
RunnableFactory.createNew("Re-Add processors", new AbsRunnable() {
@Override
public void run() {
addToProcessQueue(processors.toArray(new Processor[processors.size()]));
cancel();
}
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
}
}
systems.close();
Log.info(Locale.get(Msg.DISABLED).toString());
@ -329,29 +284,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
return serverInfoManager;
}
public ProcessingQueue getProcessingQueue() {
return processingQueue;
}
public void addToProcessQueue(Processor... processors) {
if (!reloading) {
for (Processor processor : processors) {
if (processor == null) {
continue;
}
processingQueue.addToQueue(processor);
}
} else {
RunnableFactory.createNew("Re-Add processors", new AbsRunnable() {
@Override
public void run() {
addToProcessQueue(processors);
cancel();
}
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
}
}
@Override
public Config getMainConfig() {
return ConfigSystem.getInstance().getConfig();
@ -402,20 +334,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
throw new IllegalStateException("This method should be used on this plugin.");
}
/**
* Method for getting the API.
* <p>
* Created due to necessity for testing, but can be used.
* For direct API getter use {@code Plan.getPlanAPI()}.
* <p>
* If Plan is reloaded a new API instance is created.
*
* @return Plan API instance.
*/
public API getApi() {
return api;
}
public Systems getSystems() {
return systems;
}

View File

@ -13,8 +13,6 @@ import com.djrapitops.plan.system.BungeeSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.processing.ProcessingQueue;
import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.tasks.TaskSystem;
@ -52,8 +50,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
private BungeeInformationManager infoManager;
private ServerVariableHolder variableHolder;
private ProcessingQueue processingQueue;
@Deprecated
private boolean setupAllowed = false;
private BungeeSystem system;
@ -93,8 +90,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
TaskSystem.getInstance().enable();
processingQueue = new ProcessingQueue();
Log.logDebug("Enable", "WebServer Initialization");
Log.info(Locale.get(Msg.ENABLED).toString());
if (Settings.ANALYSIS_EXPORT.isTrue()) {
@ -113,13 +108,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
@Override
public void onDisable() {
if (processingQueue != null) {
try {
processingQueue.stop();
} catch (IllegalArgumentException ignored) {
/*ignored*/
}
}
systems.close();
Log.info(Locale.get(Msg.DISABLED).toString());
Benchmark.pluginDisabled(PlanBungee.class);
@ -134,7 +122,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
@Override
public void onReload() {
ConfigSystem.reload();
}
@Override
@ -158,19 +145,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return WebServerSystem.getInstance().getWebServer();
}
@Override
public ProcessingQueue getProcessingQueue() {
return processingQueue;
}
@Override
public void addToProcessQueue(Processor... processors) {
for (Processor processor : processors) {
processingQueue.addToQueue(processor);
}
}
@Override
public InputStream getResource(String resource) {
return getResourceAsStream(resource);
@ -215,4 +189,9 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
public BungeeSystem getSystem() {
return system;
}
@Override
public boolean isReloading() {
return reloading;
}
}

View File

@ -28,27 +28,34 @@ public interface PlanPlugin extends IPlugin {
@Deprecated
Database getDB();
@Deprecated
ServerVariableHolder getVariable();
@Deprecated
UUID getServerUuid();
@Deprecated
InformationManager getInfoManager();
@Deprecated
WebServer getWebServer();
File getDataFolder();
@Deprecated
ProcessingQueue getProcessingQueue();
@Deprecated
void addToProcessQueue(Processor... processors);
InputStream getResource(String resource);
@Deprecated
Config getMainConfig();
ColorScheme getColorScheme();
@Deprecated
Systems getSystems();
boolean isReloading();

View File

@ -21,9 +21,15 @@ public interface PlanAPI {
throw new IllegalAccessError("Not yet implemented"); // TODO
}
void registerPluginData(PluginData pluginData);
void addPluginDataSource(PluginData pluginData);
Map<UUID, String> getKnownUsernames();
String getPlayerInspectPageLink(String playerName);
String getPlayerName(UUID uuid);
UUID playerNameToUUID(String playerName);
Map<UUID, String> getKnownPlayerNames();
FetchOperations fetchFromPlanDB();
}

View File

@ -0,0 +1,23 @@
package com.djrapitops.plan.api.exceptions;
public class PassEncryptException extends Exception {
public PassEncryptException() {
}
public PassEncryptException(String s) {
super(s);
}
public PassEncryptException(String s, Throwable throwable) {
super(s, throwable);
}
public PassEncryptException(Throwable throwable) {
super(throwable);
}
public PassEncryptException(String s, Throwable throwable, boolean b, boolean b1) {
super(s, throwable, b, b1);
}
}

View File

@ -3,7 +3,6 @@ package com.djrapitops.plan.data.plugin;
import com.djrapitops.plan.Plan;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.pluginbridge.plan.Bridge;
import java.util.ArrayList;
import java.util.List;
@ -29,7 +28,7 @@ public class HookHandler {
additionalDataSources = new ArrayList<>();
configHandler = new PluginsConfigSection();
try {
Bridge.hook(this);
// Bridge.hook(this);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.error("Plan Plugin Bridge not included in the plugin jar.");

View File

@ -3,10 +3,7 @@ package com.djrapitops.plan.system.database.databases;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.operation.BackupOperations;
import com.djrapitops.plan.system.database.databases.operation.CheckOperations;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import com.djrapitops.plan.system.database.databases.operation.RemoveOperations;
import com.djrapitops.plan.system.database.databases.operation.*;
import com.djrapitops.plan.utilities.NullCheck;
/**
@ -62,4 +59,8 @@ public abstract class Database {
public boolean isOpen() {
return open;
}
public abstract SearchOperations search();
public abstract CountOperations count();
}

View File

@ -0,0 +1,11 @@
package com.djrapitops.plan.system.database.databases.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import java.util.UUID;
public interface CountOperations {
int serverPlayerCount(UUID server) throws DBException;
}

View File

@ -3,17 +3,23 @@ package com.djrapitops.plan.system.database.databases.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.PlayerProfile;
import com.djrapitops.plan.data.ServerProfile;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.data.container.TPS;
import java.util.*;
public interface FetchOperations {
// Profiles
ServerProfile getServerProfile(UUID serverUUID) throws DBException;
List<PlayerProfile> getPlayers(UUID serverUUID) throws DBException;
PlayerProfile getPlayerProfile(UUID uuid) throws DBException;
// UUIDs
Set<UUID> getSavedUUIDs() throws DBException;
Set<UUID> getSavedUUIDs(UUID server) throws DBException;
@ -21,4 +27,14 @@ public interface FetchOperations {
Map<UUID, String> getServerNames() throws DBException;
Optional<UUID> getServerUUID(String serverName) throws DBException;
UUID getUuidOf(String playerName) throws DBException;
// WebUsers
WebUser getWebUser(String username) throws DBException;
// Raw Data
List<TPS> getTPSData(UUID serverUUID) throws DBException;
}

View File

@ -0,0 +1,11 @@
package com.djrapitops.plan.system.database.databases.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import java.util.List;
public interface SearchOperations {
List<String> matchingNames(String search) throws DBException;
}

View File

@ -57,8 +57,12 @@ public class MySQLDB extends SQLDB {
}
@Override
public void close() throws SQLException {
dataSource.close();
public void close() {
try {
dataSource.close();
} catch (SQLException e) {
Log.toLog(this.getClass(), e);
}
super.close();
}
}

View File

@ -2,14 +2,8 @@ package com.djrapitops.plan.system.database.databases.sql;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.operation.BackupOperations;
import com.djrapitops.plan.system.database.databases.operation.CheckOperations;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import com.djrapitops.plan.system.database.databases.operation.RemoveOperations;
import com.djrapitops.plan.system.database.databases.sql.operation.SQLBackupOps;
import com.djrapitops.plan.system.database.databases.sql.operation.SQLCheckOps;
import com.djrapitops.plan.system.database.databases.sql.operation.SQLFetchOps;
import com.djrapitops.plan.system.database.databases.sql.operation.SQLRemoveOps;
import com.djrapitops.plan.system.database.databases.operation.*;
import com.djrapitops.plan.system.database.databases.sql.operation.*;
import com.djrapitops.plan.system.database.databases.sql.tables.*;
import com.djrapitops.plan.system.database.databases.sql.tables.move.Version8TransferTable;
import com.djrapitops.plugin.api.Benchmark;
@ -50,6 +44,8 @@ public abstract class SQLDB extends Database {
private final SQLCheckOps checkOps;
private final SQLFetchOps fetchOps;
private final SQLRemoveOps removeOps;
private final SQLSearchOps searchOps;
private final SQLCountOps countOps;
private final boolean usingMySQL;
private boolean open = false;
@ -79,6 +75,8 @@ public abstract class SQLDB extends Database {
checkOps = new SQLCheckOps(this);
fetchOps = new SQLFetchOps(this);
removeOps = new SQLRemoveOps(this);
countOps = new SQLCountOps(this);
searchOps = new SQLSearchOps(this);
}
/**
@ -151,7 +149,7 @@ public abstract class SQLDB extends Database {
@Override
public void run() {
try {
new Version8TransferTable(db, isUsingMySQL()).alterTablesToV10();
new Version8TransferTable(db).alterTablesToV10();
} catch (DBInitException | SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
@ -368,4 +366,14 @@ public abstract class SQLDB extends Database {
public RemoveOperations remove() {
return removeOps;
}
@Override
public SearchOperations search() {
return searchOps;
}
@Override
public CountOperations count() {
return countOps;
}
}

View File

@ -0,0 +1,25 @@
package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.operation.CountOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import java.sql.SQLException;
import java.util.UUID;
public class SQLCountOps extends SQLOps implements CountOperations {
public SQLCountOps(SQLDB db) {
super(db);
}
@Override
public int serverPlayerCount(UUID server) throws DBException {
try {
return userInfoTable.getServerUserCount(server);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -3,6 +3,7 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.PlayerProfile;
import com.djrapitops.plan.data.ServerProfile;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.data.container.*;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
@ -171,4 +172,33 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
throw ErrorUtil.getExceptionFor(e);
}
}
@Override
public UUID getUuidOf(String playerName) throws DBException {
try {
return usersTable.getUuidOf(playerName);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
@Override
public WebUser getWebUser(String username) throws DBException {
try {
return securityTable.getWebUser(username);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
@Override
public List<TPS> getTPSData(UUID serverUUID) throws DBException {
try {
return tpsTable.getTPSData(serverUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -0,0 +1,25 @@
package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.operation.SearchOperations;
import com.djrapitops.plan.system.database.databases.sql.ErrorUtil;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import java.sql.SQLException;
import java.util.List;
public class SQLSearchOps extends SQLOps implements SearchOperations {
public SQLSearchOps(SQLDB db) {
super(db);
}
@Override
public List<String> matchingNames(String search) throws DBException {
try {
return usersTable.getMatchingNames(search);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -16,7 +16,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Select;
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
import com.djrapitops.plan.system.database.databases.sql.statements.Update;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import java.sql.PreparedStatement;
@ -316,31 +315,26 @@ public class UserInfoTable extends UserIDTable {
});
}
public int getServerUserCount(UUID serverUUID) {
try {
String sql = "SELECT " +
" COUNT(" + columnRegistered + ") as c" +
" FROM " + tableName +
" WHERE " + columnServerID + "=" + serverTable.statementSelectServerID;
public int getServerUserCount(UUID serverUUID) throws SQLException {
String sql = "SELECT " +
" COUNT(" + columnRegistered + ") as c" +
" FROM " + tableName +
" WHERE " + columnServerID + "=" + serverTable.statementSelectServerID;
return query(new QueryStatement<Integer>(sql, 20000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
return query(new QueryAllStatement<Integer>(sql, 20000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
@Override
public Integer processResults(ResultSet set) throws SQLException {
if (set.next()) {
return set.getInt("c");
}
return 0;
@Override
public Integer processResults(ResultSet set) throws SQLException {
if (set.next()) {
return set.getInt("c");
}
});
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
return 0;
}
return 0;
}
});
}
// TODO improve performance of this method.

View File

@ -1,30 +0,0 @@
package com.djrapitops.plan.system.database.sql;
public class Insert extends SqlParser {
public Insert(String table) {
super("INSERT INTO " + table);
addSpace();
}
public static String values(String table, String... columns) {
Insert parser = new Insert(table);
parser.append("(");
int size = columns.length;
for (int i = 0; i < size; i++) {
if (size > 1 && i > 0) {
parser.append(", ");
}
parser.append(columns[i]);
}
parser.append(") VALUES (");
for (int i = 0; i < size; i++) {
if (size > 1 && i > 0) {
parser.append(", ");
}
parser.append("?");
}
parser.append(")");
return parser.toString();
}
}

View File

@ -1,26 +0,0 @@
package com.djrapitops.plan.system.database.sql;
public class Select extends WhereParser {
public Select(String start) {
super(start);
}
public static Select from(String table, String... columns) {
Select parser = new Select("SELECT ");
int size = columns.length;
for (int i = 0; i < size; i++) {
if (size > 1 && i > 0) {
parser.append(", ");
}
parser.append(columns[i]);
}
parser.append(" FROM ").append(table);
return parser;
}
public static Select all(String table) {
return new Select("SELECT * FROM " + table);
}
}

View File

@ -1,16 +0,0 @@
package com.djrapitops.plan.system.database.sql;
public class Sql {
public static final String INT = "integer";
public static final String DOUBLE = "double";
public static final String LONG = "bigint";
public static final String BOOL = "boolean";
private Sql() {
throw new IllegalStateException("Variable Class");
}
public static String varchar(int length) {
return "varchar(" + length + ")";
}
}

View File

@ -1,35 +0,0 @@
package com.djrapitops.plan.system.database.sql;
/**
* Class for parsing different SQL strings.
*
* @author Rsl1122
* @since 3.7.0
*/
public class SqlParser {
private final StringBuilder s;
public SqlParser() {
s = new StringBuilder();
}
public SqlParser(String start) {
s = new StringBuilder(start);
}
public SqlParser addSpace() {
s.append(" ");
return this;
}
public SqlParser append(String string) {
s.append(string);
return this;
}
@Override
public String toString() {
return s.toString();
}
}

View File

@ -1,118 +0,0 @@
package com.djrapitops.plan.system.database.sql;
/**
* SqlParser Class for parsing table creation, removal and modification statements.
*
* @author Rsl1122
* @since 3.7.0
*/
public class TableSqlParser extends SqlParser {
private int columns = 0;
public TableSqlParser(String start) {
super(start);
}
public static TableSqlParser createTable(String tableName) {
return new TableSqlParser("CREATE TABLE IF NOT EXISTS " + tableName + " (");
}
public static String dropTable(String tableName) {
return "DROP TABLE IF EXISTS " + tableName;
}
/**
* Used for ALTER TABLE sql statements.
*
* @param column column to modify
* @return TableSqlParser object
*/
public static TableSqlParser newColumn(String column, String type) {
return new TableSqlParser("").column(column, type);
}
public TableSqlParser column(String column, String type) {
if (columns > 0) {
append(", ");
}
append(column).addSpace();
append(type);
columns++;
return this;
}
public TableSqlParser foreignKey(String column, String refrencedTable, String referencedColumn) {
if (columns > 0) {
append(", ");
}
append("FOREIGN KEY(")
.append(column)
.append(") REFERENCES ")
.append(refrencedTable)
.append("(")
.append(referencedColumn)
.append(")");
columns++;
return this;
}
public TableSqlParser notNull() {
addSpace();
append("NOT NULL");
return this;
}
public TableSqlParser unique() {
addSpace();
append("UNIQUE");
return this;
}
public TableSqlParser defaultValue(boolean value) {
return defaultValue(value ? "1" : "0");
}
public TableSqlParser defaultValue(String value) {
addSpace();
append("DEFAULT ").append(value);
return this;
}
public TableSqlParser primaryKeyIDColumn(boolean mySQL, String column) {
if (columns > 0) {
append(", ");
}
append(column).addSpace();
append(Sql.INT).addSpace();
append((mySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY");
columns++;
return this;
}
public TableSqlParser primaryKey(boolean mySQL, String column) {
if (mySQL) {
if (columns > 0) {
append(", ");
}
append("PRIMARY KEY (").append(column).append(")");
columns++;
}
return this;
}
public TableSqlParser charSetUTF8(boolean mySQL) {
if (mySQL) {
addSpace();
append("CHARACTER SET utf8 COLLATE utf8mb4_general_ci");
}
return this;
}
@Override
public String toString() {
append(")");
return super.toString();
}
}

View File

@ -1,30 +0,0 @@
/*
* 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 com.djrapitops.plan.system.database.sql;
/**
* @author Fuzzlemann
*/
public class Update extends WhereParser {
public Update(String table) {
super("UPDATE " + table + " SET");
addSpace();
}
public static Update values(String table, String... values) {
Update parser = new Update(table);
int size = values.length;
for (int i = 0; i < size; i++) {
if (size > 1 && i > 0) {
parser.append(", ");
}
parser.append(values[i] + "=?");
}
return parser;
}
}

View File

@ -1,48 +0,0 @@
/*
* 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 com.djrapitops.plan.system.database.sql;
/**
* @author Fuzzlemann
*/
public abstract class WhereParser extends SqlParser {
private int conditions = 0;
public WhereParser() {
super();
}
public WhereParser(String start) {
super(start);
}
public WhereParser where(String... conditions) {
append(" WHERE ");
for (String condition : conditions) {
if (this.conditions > 0) {
append(" AND ");
}
append("(").append(condition).append(")");
this.conditions++;
}
return this;
}
public WhereParser and(String condition) {
append(" AND ");
append("(").append(condition).append(")");
this.conditions++;
return this;
}
public WhereParser or(String condition) {
append(" OR ");
append("(").append(condition).append(")");
this.conditions++;
return this;
}
}

View File

@ -36,7 +36,7 @@ public class PlayerOnlineListener implements Listener {
String name = player.getName();
long now = MiscUtils.getTime();
plugin.getProcessingQueue().addToQueue(new BungeePlayerRegisterProcessor(uuid, name, now));
plugin.getSystem().getProcessingQueue().addToQueue(new BungeePlayerRegisterProcessor(uuid, name, now));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
}

View File

@ -4,10 +4,11 @@
*/
package com.djrapitops.plan.system.webserver.auth;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.PassEncryptException;
import com.djrapitops.plan.api.exceptions.WebUserAuthException;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.database.tables.SecurityTable;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.utilities.PassEncryptUtil;
import java.util.Base64;
@ -28,15 +29,7 @@ public class BasicAuthentication implements Authentication {
}
@Override
public boolean isAuthorized(String permission) throws WebUserAuthException {
if (user == null) {
user = getUser();
return user.hasPermission(permission);
}
return false;
}
public WebUser getUser() throws WebUserAuthException {
public WebUser getWebUser() throws WebUserAuthException {
Base64.Decoder decoder = Base64.getDecoder();
byte[] decoded = decoder.decode(authenticationString);
String[] userInfo = new String(decoded).split(":");
@ -48,19 +41,20 @@ public class BasicAuthentication implements Authentication {
String passwordRaw = userInfo[1];
try {
SecurityTable securityTable = PlanPlugin.getInstance().getDB().getSecurityTable();
if (!securityTable.userExists(user)) {
Database database = Database.getActive();
if (!database.check().doesWebUserExists(user)) {
throw new WebUserAuthException(FailReason.USER_DOES_NOT_EXIST);
}
WebUser webUser = securityTable.getWebUser(user);
WebUser webUser = database.fetch().getWebUser(user);
boolean correctPass = PassEncryptUtil.verifyPassword(passwordRaw, webUser.getSaltedPassHash());
if (!correctPass) {
throw new WebUserAuthException(FailReason.USER_PASS_MISMATCH);
}
return webUser;
} catch (Exception e) {
} catch (DBException | PassEncryptException e) {
throw new WebUserAuthException(e);
}
}

View File

@ -3,6 +3,7 @@ package com.djrapitops.plan.utilities;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.database.databases.Database;
@ -16,7 +17,6 @@ import com.djrapitops.plugin.command.ISender;
import java.io.Closeable;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
@ -99,9 +99,9 @@ public class MiscUtils {
Database db = PlanPlugin.getInstance().getDB();
List<String> matches;
try {
matches = db.getUsersTable().getMatchingNames(search);
} catch (SQLException e) {
Log.toLog("MiscUtils.getMatchingPlayerNames", e);
matches = db.search().matchingPlayerNames(search);
} catch (DBException e) {
Log.toLog(MiscUtils.class, e);
return new ArrayList<>();
}
Collections.sort(matches);

View File

@ -1,5 +1,7 @@
package com.djrapitops.plan.utilities;
import com.djrapitops.plan.api.exceptions.PassEncryptException;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.xml.bind.DatatypeConverter;
@ -167,7 +169,7 @@ public class PassEncryptUtil {
}
@SuppressWarnings("serial")
public static class InvalidHashException extends Exception {
public static class InvalidHashException extends PassEncryptException {
InvalidHashException(String message) {
super(message);
@ -179,7 +181,7 @@ public class PassEncryptUtil {
}
@SuppressWarnings("serial")
public static class CannotPerformOperationException extends Exception {
public static class CannotPerformOperationException extends PassEncryptException {
CannotPerformOperationException() {
super("Unsupported hash type.");

View File

@ -9,15 +9,16 @@ import com.djrapitops.plan.data.plugin.BanData;
import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.tasks.BukkitTaskSystem;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.systems.cache.DataCache;
import com.djrapitops.plan.systems.cache.SessionCache;
import com.djrapitops.plan.systems.info.BukkitInformationManager;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.system.tasks.BukkitTaskSystem;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
@ -114,7 +115,7 @@ public class Analysis {
Benchmark.stop("Analysis", "Create Empty dataset");
Benchmark.start("Fetch Phase");
ServerProfile profile = db.getServerProfile(Plan.getServerUUID());
ServerProfile profile = db.fetch().getServerProfile(Plan.getServerUUID());
DataCache dataCache = plugin.getDataCache();
profile.addActiveSessions(new HashMap<>(SessionCache.getActiveSessions()));
serverProfile = profile;

View File

@ -6,6 +6,7 @@ package com.djrapitops.plan.utilities.html;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.ServerVariableHolder;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Settings;
@ -17,7 +18,6 @@ import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import java.sql.SQLException;
import java.util.*;
/**
@ -122,11 +122,12 @@ public class HtmlStructure {
UUID serverUUID = plugin.getServerUuid();
String id = serverUUID.toString().replace("-", "");
int playerCount = db.getUserInfoTable().getServerUserCount(serverUUID);
int playerCount = 0;
String playerData = "[]";
try {
playerData = PlayerActivityGraph.createSeries(db.getTpsTable().getTPSData(serverUUID));
} catch (SQLException e) {
playerCount = db.count().serverPlayerCount(serverUUID);
playerData = PlayerActivityGraph.createSeries(db.fetch().getTPSData(serverUUID));
} catch (DBException e) {
Log.toLog(HtmlStructure.class.getClass().getName(), e);
}

View File

@ -6,12 +6,13 @@
package com.djrapitops.plan.utilities.uuid;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.FatalDBException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.UUIDFetcher;
import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.SQLException;
import java.util.UUID;
/**
@ -34,7 +35,7 @@ public class UUIDUtility {
*/
public static UUID getUUIDOf(String playerName) {
try {
return getUUIDOf(playerName, PlanPlugin.getInstance().getDB());
return getUUIDOf(playerName, Database.getActive());
} catch (Exception e) {
return null;
}
@ -47,7 +48,7 @@ public class UUIDUtility {
* @param db Database to check from.
* @return UUID of the player
*/
public static UUID getUUIDOf(String playerName, Database db) {
private static UUID getUUIDOf(String playerName, Database db) {
UUID uuid = null;
if (Check.isBukkitAvailable()) {
UUID uuidOf = Plan.getInstance().getDataCache().getUUIDof(playerName);
@ -56,9 +57,11 @@ public class UUIDUtility {
}
}
try {
uuid = db.getUsersTable().getUuidOf(playerName);
} catch (SQLException e) {
Log.toLog("UUIDUtility", e);
uuid = db.fetch().getUuidOf(playerName);
} catch (FatalDBException e) {
Log.toLog(UUIDUtility.class, e);
} catch (DBException e) {
/* Ignored */
}
try {
if (uuid == null) {