Removed some deprecated PlanPlugin methods

This commit is contained in:
Rsl1122 2018-01-18 14:13:44 +02:00
parent f5f488f16a
commit 45ba9d02c0
33 changed files with 221 additions and 131 deletions

View File

@ -5,13 +5,10 @@
package com.djrapitops.plan; package com.djrapitops.plan;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.ProcessingQueue;
import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.webserver.WebServer; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.systems.info.InformationManager; import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plugin.IPlugin; import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.settings.ColorScheme; import com.djrapitops.plugin.settings.ColorScheme;
import java.io.File; import java.io.File;
@ -54,17 +51,8 @@ public interface PlanPlugin extends IPlugin {
File getDataFolder(); File getDataFolder();
@Deprecated
ProcessingQueue getProcessingQueue();
@Deprecated
void addToProcessQueue(Processor... processors);
InputStream getResource(String resource); InputStream getResource(String resource);
@Deprecated
Config getMainConfig();
ColorScheme getColorScheme(); ColorScheme getColorScheme();
boolean isReloading(); boolean isReloading();

View File

@ -4,19 +4,19 @@
*/ */
package com.djrapitops.plan; package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.Actions; import com.djrapitops.plan.data.Actions;
import com.djrapitops.plan.data.container.Action; import com.djrapitops.plan.data.container.Action;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.cache.CacheSystem;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.databases.sql.SQLDB; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.tables.SessionsTable;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.SQLException;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -30,64 +30,57 @@ import java.util.UUID;
public class ShutdownHook extends Thread { public class ShutdownHook extends Thread {
private static boolean active = false; private static boolean active = false;
private static DataCache dataCache;
private static SQLDB db;
public ShutdownHook(Plan plugin) { public void register() {
if (!active) { if (!active) {
Runtime.getRuntime().addShutdownHook(this); Runtime.getRuntime().addShutdownHook(this);
} }
active = true; active = true;
db = (SQLDB) plugin.getDB();
dataCache = plugin.getDataCache();
} }
@Override @Override
public void run() { public void run() {
Log.debug("Shutdown hook triggered."); Log.debug("Shutdown hook triggered.");
Database db = null;
try { try {
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions(); Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
long now = MiscUtils.getTime(); long now = MiscUtils.getTime();
if (db == null) { db = Database.getActive();
return;
}
if (!db.isOpen()) { if (!db.isOpen()) {
db.init(); db.init();
} }
saveFirstSessionInformation(now); saveFirstSessionInformation(db, now);
saveActiveSessions(activeSessions, now); saveActiveSessions(db, activeSessions, now);
} catch (DBInitException e) { } catch (DBInitException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} finally { } finally {
if (db != null) { if (db != null) {
try { try {
db.close(); db.close();
} catch (SQLException e) { } catch (DBException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} }
} }
db = null;
dataCache = null;
StaticHolder.unRegister(Plan.class); StaticHolder.unRegister(Plan.class);
} }
} }
private void saveFirstSessionInformation(long now) { private void saveFirstSessionInformation(Database db, long now) {
DataCache dataCache = CacheSystem.getInstance().getDataCache();
for (Map.Entry<UUID, Integer> entry : dataCache.getFirstSessionMsgCounts().entrySet()) { for (Map.Entry<UUID, Integer> entry : dataCache.getFirstSessionMsgCounts().entrySet()) {
try { try {
UUID uuid = entry.getKey(); UUID uuid = entry.getKey();
int messagesSent = entry.getValue(); int messagesSent = entry.getValue();
db.getActionsTable().insertAction(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent)); db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent));
} catch (SQLException e) { } catch (DBException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} }
} }
} }
private void saveActiveSessions(Map<UUID, Session> activeSessions, long now) { private void saveActiveSessions(Database db, Map<UUID, Session> activeSessions, long now) {
SessionsTable sessionsTable = db.getSessionsTable();
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) { for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
UUID uuid = entry.getKey(); UUID uuid = entry.getKey();
Session session = entry.getValue(); Session session = entry.getValue();
@ -98,8 +91,8 @@ public class ShutdownHook extends Thread {
session.endSession(now); session.endSession(now);
try { try {
Log.debug("Shutdown: Saving a session: " + session.getSessionStart()); Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
sessionsTable.saveSession(uuid, session); db.save().session(uuid, session);
} catch (SQLException e) { } catch (DBException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} }
} }

View File

@ -3,20 +3,17 @@ package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg; import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.Condition; import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plan.utilities.ManageUtils;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import java.io.IOException;
/** /**
* This manage subcommand is used to swap to a different database and reload the * This manage subcommand is used to swap to a different database and reload the
* plugin if the connection to the new database can be established. * plugin if the connection to the new database can be established.
@ -66,7 +63,7 @@ public class ManageHotswapCommand extends SubCommand {
} }
try { try {
final Database database = ManageUtils.getDB(dbName); final Database database = DBSystem.getActiveDatabaseByName(dbName);
// If DB is null return // If DB is null return
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) { if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
@ -74,23 +71,19 @@ public class ManageHotswapCommand extends SubCommand {
return true; return true;
} }
assert database != null; if (!database.isOpen()) {
return true;
database.getVersion(); //Test db connection }
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString()); sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
return true; return true;
} }
Config config = plugin.getMainConfig(); Settings.DB_TYPE.set(dbName);
config.set(Settings.DB_TYPE.getPath(), dbName);
try { Settings.save();
config.save();
plugin.reloadPlugin(true); plugin.reloadPlugin(true);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return true; return true;
} }
} }

View File

@ -9,7 +9,6 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.webapi.bungee.RequestSetupWebAPI; import com.djrapitops.plan.system.webserver.webapi.bungee.RequestSetupWebAPI;
import com.djrapitops.plan.utilities.Condition; import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
@ -65,9 +64,8 @@ public class ManageSetupCommand extends SubCommand {
address = address.substring(0, address.length() - 1); address = address.substring(0, address.length() - 1);
} }
try { try {
Config config = plugin.getMainConfig(); Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.getPath(), false); Settings.BUNGEE_COPY_CONFIG.set(true);
config.set(Settings.BUNGEE_COPY_CONFIG.getPath(), true);
// plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address); // plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address);
plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address); plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address);
sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong."); sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong.");

View File

@ -5,8 +5,8 @@
package com.djrapitops.plan.settings; package com.djrapitops.plan.settings;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
@ -27,7 +27,7 @@ public class ServerSpecificSettings {
public static void updateSettings(Plan plugin, Map<String, String> settings) { public static void updateSettings(Plan plugin, Map<String, String> settings) {
Log.debug("Checking new settings.."); Log.debug("Checking new settings..");
Config config = plugin.getMainConfig(); Config config = ConfigSystem.getConfig();
boolean changedSomething = false; boolean changedSomething = false;
for (Map.Entry<String, String> setting : settings.entrySet()) { for (Map.Entry<String, String> setting : settings.entrySet()) {
@ -77,9 +77,9 @@ public class ServerSpecificSettings {
return value; return value;
} }
public void addOriginalBukkitSettings(PlanBungee plugin, UUID serverUUID, Map<String, Object> settings) { public void addOriginalBukkitSettings(UUID serverUUID, Map<String, Object> settings) {
try { try {
Config config = plugin.getMainConfig(); Config config = ConfigSystem.getConfig();
if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) { if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) {
return; return;
} }
@ -111,25 +111,25 @@ public class ServerSpecificSettings {
} }
public boolean getBoolean(UUID serverUUID, Settings setting) { public boolean getBoolean(UUID serverUUID, Settings setting) {
Config config = PlanBungee.getInstance().getMainConfig(); Config config = ConfigSystem.getConfig();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
return config.getBoolean(path); return config.getBoolean(path);
} }
public String getString(UUID serverUUID, Settings setting) { public String getString(UUID serverUUID, Settings setting) {
Config config = PlanBungee.getInstance().getMainConfig(); Config config = ConfigSystem.getConfig();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
return config.getString(path); return config.getString(path);
} }
public Integer getInt(UUID serverUUID, Settings setting) { public Integer getInt(UUID serverUUID, Settings setting) {
Config config = PlanBungee.getInstance().getMainConfig(); Config config = ConfigSystem.getConfig();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
return config.getInt(path); return config.getInt(path);
} }
public void set(UUID serverUUID, Settings setting, Object value) throws IOException { public void set(UUID serverUUID, Settings setting, Object value) throws IOException {
Config config = PlanBungee.getInstance().getMainConfig(); Config config = ConfigSystem.getConfig();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
config.set(path, value); config.set(path, value);
config.save(); config.save();

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.system; package com.djrapitops.plan.system;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.ShutdownHook;
import com.djrapitops.plan.system.database.BukkitDBSystem; import com.djrapitops.plan.system.database.BukkitDBSystem;
import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.listeners.BukkitListenerSystem; import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
@ -26,6 +27,8 @@ public class BukkitSystem extends PlanSystem {
databaseSystem = new BukkitDBSystem(); databaseSystem = new BukkitDBSystem();
listenerSystem = new BukkitListenerSystem(plugin); listenerSystem = new BukkitListenerSystem(plugin);
taskSystem = new BukkitTaskSystem(plugin); taskSystem = new BukkitTaskSystem(plugin);
new ShutdownHook().register();
} }
public static BukkitSystem getInstance() { public static BukkitSystem getInstance() {

View File

@ -1,11 +1,14 @@
package com.djrapitops.plan.system.cache; package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plan.system.processing.processors.Processor; import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.NullCheck;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.util.HashMap; import java.util.HashMap;
@ -32,6 +35,12 @@ public class SessionCache {
this.system = system; this.system = system;
} }
public static SessionCache getInstance() {
DataCache dataCache = CacheSystem.getInstance().getDataCache();
NullCheck.check(dataCache, new IllegalStateException("Data Cache was not initialized."));
return dataCache;
}
/** /**
* Used to get the Map of active sessions. * Used to get the Map of active sessions.
* <p> * <p>
@ -52,7 +61,11 @@ public class SessionCache {
new Processor<PlanSystem>(system) { new Processor<PlanSystem>(system) {
@Override @Override
public void process() { public void process() {
system.getInfoManager().cachePlayer(uuid); try {
system.getInfoSystem().generateAndCachePlayerPage(uuid);
} catch (WebException e) {
WebExceptionLogger.log(this.getClass(), e);
}
} }
}.queue(); }.queue();
} }
@ -69,7 +82,11 @@ public class SessionCache {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} finally { } finally {
activeSessions.remove(uuid); activeSessions.remove(uuid);
system.getInfoManager().cachePlayer(uuid); try {
system.getInfoSystem().generateAndCachePlayerPage(uuid);
} catch (WebException e) {
WebExceptionLogger.log(this.getClass(), e);
}
} }
} }

View File

@ -22,7 +22,7 @@ public class BukkitDBSystem extends DBSystem {
databases.add(new SQLiteDB()); databases.add(new SQLiteDB());
String dbType = Settings.DB_TYPE.toString().toLowerCase().trim(); String dbType = Settings.DB_TYPE.toString().toLowerCase().trim();
db = getActiveDatabase(dbType); db = getActiveDatabaseByName(dbType);
db.init(); db.init();
} }
} }

View File

@ -79,8 +79,8 @@ public abstract class DBSystem implements SubSystem {
return db; return db;
} }
public Database getActiveDatabase(String dbName) throws DBInitException { public static Database getActiveDatabaseByName(String dbName) throws DBInitException {
for (Database database : getDatabases()) { for (Database database : getInstance().getDatabases()) {
String dbConfigName = database.getConfigName(); String dbConfigName = database.getConfigName();
if (Verify.equalsIgnoreCase(dbName, dbConfigName)) { if (Verify.equalsIgnoreCase(dbName, dbConfigName)) {
database.init(); database.init();

View File

@ -1,5 +1,7 @@
package com.djrapitops.plan.system.database.databases.sql; package com.djrapitops.plan.system.database.databases.sql;
import com.djrapitops.plan.system.database.databases.operation.TransferOperations;
import com.djrapitops.plan.system.database.databases.sql.operation.SQLTransferOps;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSource;
@ -14,6 +16,17 @@ public class MySQLDB extends SQLDB {
private BasicDataSource dataSource; private BasicDataSource dataSource;
private final SQLTransferOps transferOps;
public MySQLDB() {
transferOps = new SQLTransferOps(this);
}
@Override
public TransferOperations transfer() {
return transferOps;
}
/** /**
* Setups the {@link BasicDataSource} * Setups the {@link BasicDataSource}
*/ */

View File

@ -79,6 +79,7 @@ public abstract class SQLDB extends Database {
countOps = new SQLCountOps(this); countOps = new SQLCountOps(this);
searchOps = new SQLSearchOps(this); searchOps = new SQLSearchOps(this);
saveOps = new SQLSaveOps(this); saveOps = new SQLSaveOps(this);
} }
/** /**

View File

@ -1,7 +1,9 @@
package com.djrapitops.plan.system.database.databases.sql; package com.djrapitops.plan.system.database.databases.sql;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.UnsupportedTransferDatabaseException;
import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.system.database.databases.operation.TransferOperations;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
@ -35,6 +37,11 @@ public class SQLiteDB extends SQLDB {
this.dbName = dbName; this.dbName = dbName;
} }
@Override
public TransferOperations transfer() throws UnsupportedTransferDatabaseException {
throw new UnsupportedTransferDatabaseException(this);
}
/** /**
* Setups the {@link BasicDataSource} * Setups the {@link BasicDataSource}
*/ */

View File

@ -318,4 +318,31 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
throw ErrorUtil.getExceptionFor(e); throw ErrorUtil.getExceptionFor(e);
} }
} }
@Override
public String getPlayerName(UUID playerUUID) throws DBException {
try {
return usersTable.getPlayerName(playerUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
@Override
public Optional<String> getServerName(UUID serverUUID) throws DBException {
try {
return serverTable.getServerName(serverUUID);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
@Override
public List<String> getNicknames(UUID uuid) throws DBException {
try {
return nicknamesTable.getNicknames(uuid);
} catch (SQLException e) {
throw ErrorUtil.getExceptionFor(e);
}
}
} }

View File

@ -0,0 +1,22 @@
/*
* 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.databases.sql.operation;
import com.djrapitops.plan.system.database.databases.operation.TransferOperations;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
/**
* TransferOperations for MySQL Database.
*
* @author Rsl1122
*/
public class SQLTransferOps extends SQLOps implements TransferOperations {
public SQLTransferOps(SQLDB db) {
super(db);
}
// TODO create Transfer table
}

View File

@ -6,7 +6,7 @@ package com.djrapitops.plan.system.info;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
@ -14,16 +14,9 @@ import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest; import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.utilities.NullCheck; import com.djrapitops.plan.utilities.NullCheck;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.UUID; import java.util.UUID;
interface ExceptionLoggingAction {
void performAction() throws WebException;
}
/** /**
* Information management system. * Information management system.
* <p> * <p>
@ -86,15 +79,4 @@ public abstract class InfoSystem implements SubSystem {
} }
public abstract void updateNetworkPage(); public abstract void updateNetworkPage();
public void handlePossibleException(ExceptionLoggingAction action) {
try {
action.performAction();
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
| NotFoundException | NoServersException e) {
Log.warn(e.getMessage());
} catch (WebException e) {
Log.toLog(this.getClass().getName(), e);
}
}
} }

View File

@ -0,0 +1,34 @@
/*
* 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.info.connection;
import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plugin.api.utility.log.Log;
/**
* Class that decides what to do with WebExceptions.
*
* @author Rsl1122
*/
public class WebExceptionLogger {
public static void log(Class c, ExceptionLoggingAction action) {
try {
action.performAction();
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
| NotFoundException | NoServersException e) {
Log.warn(e.getMessage());
} catch (WebException e) {
Log.toLog(WebExceptionLogger.class, e);
}
}
public interface ExceptionLoggingAction {
void performAction() throws WebException;
}
}

View File

@ -22,6 +22,7 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables {
@Override @Override
public void placeDataToDatabase() { public void placeDataToDatabase() {
// No data required in a Generate request
} }
@Override @Override

View File

@ -26,6 +26,7 @@ public class GenerateInspectPageRequest extends InfoRequestWithVariables {
@Override @Override
public void placeDataToDatabase() { public void placeDataToDatabase() {
// No data required in a Generate request
} }
@Override @Override

View File

@ -46,7 +46,7 @@ public class DeathEventListener implements Listener {
LivingEntity dead = event.getEntity(); LivingEntity dead = event.getEntity();
if (dead instanceof Player) { if (dead instanceof Player) {
plugin.addToProcessQueue(new DeathProcessor(dead.getUniqueId())); new DeathProcessor(dead.getUniqueId()).queue();
} }
try { try {

View File

@ -3,6 +3,7 @@ package com.djrapitops.plan.system.listeners.bukkit;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor;
import com.djrapitops.plan.system.processing.processors.player.*; import com.djrapitops.plan.system.processing.processors.player.*;
import com.djrapitops.plan.system.tasks.TaskSystem; import com.djrapitops.plan.system.tasks.TaskSystem;
@ -53,11 +54,8 @@ public class PlayerOnlineListener implements Listener {
PlayerLoginEvent.Result result = event.getResult(); PlayerLoginEvent.Result result = event.getResult();
UUID uuid = event.getPlayer().getUniqueId(); UUID uuid = event.getPlayer().getUniqueId();
boolean op = event.getPlayer().isOp(); boolean op = event.getPlayer().isOp();
if (result == PlayerLoginEvent.Result.KICK_BANNED) { boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED;
plugin.addToProcessQueue(new BanAndOpProcessor(uuid, true, op)); new BanAndOpProcessor(uuid, banned, op).queue();
} else {
plugin.addToProcessQueue(new BanAndOpProcessor(uuid, false, op));
}
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }
@ -78,7 +76,7 @@ public class PlayerOnlineListener implements Listener {
return; return;
} }
UUID uuid = event.getPlayer().getUniqueId(); UUID uuid = event.getPlayer().getUniqueId();
plugin.addToProcessQueue(new KickProcessor(uuid)); new KickProcessor(uuid).queue();
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }
@ -111,13 +109,13 @@ public class PlayerOnlineListener implements Listener {
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline(); int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
cache.cacheSession(uuid, Session.start(time, world, gm)); cache.cacheSession(uuid, Session.start(time, world, gm));
plugin.addToProcessQueue(
Processor.queueMany(
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline, new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
new IPUpdateProcessor(uuid, ip, time), new IPUpdateProcessor(uuid, ip, time),
new NameProcessor(uuid, playerName, displayName) new NameProcessor(uuid, playerName, displayName)
), ),
new NetworkPageUpdateProcessor(plugin.getInfoManager()) new NetworkPageUpdateProcessor());
);
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }
@ -137,15 +135,15 @@ public class PlayerOnlineListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
plugin.addToProcessQueue( Processor.queueMany(
new BanAndOpProcessor(uuid, player.isBanned(), player.isOp()), new BanAndOpProcessor(uuid, player.isBanned(), player.isOp()),
new EndSessionProcessor(uuid, time), new EndSessionProcessor(uuid, time),
new NetworkPageUpdateProcessor(plugin.getInfoManager()) new NetworkPageUpdateProcessor()
); );
if (cache.isFirstSession(uuid)) { if (cache.isFirstSession(uuid)) {
int messagesSent = plugin.getDataCache().getFirstSessionMsgCount(uuid); int messagesSent = plugin.getDataCache().getFirstSessionMsgCount(uuid);
plugin.addToProcessQueue(new FirstLeaveProcessor(uuid, time, messagesSent)); new FirstLeaveProcessor(uuid, time, messagesSent).queue();
} }
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);

View File

@ -72,7 +72,7 @@ public class ProcessingQueue extends Queue<Processor> implements SubSystem {
*/ */
public void queue(Processor processor) { public void queue(Processor processor) {
if (!queue.offer(processor)) { if (!queue.offer(processor)) {
Log.toLog("ProcessingQueue.queue", new IllegalStateException("Processor was not added to Queue")); Log.toLog(Processor.class, new IllegalStateException("Processor was not added to Queue"));
} }
} }
} }

View File

@ -18,7 +18,7 @@ public abstract class Processor<T> {
this.object = object; this.object = object;
} }
public static void queue(Processor... processors) { public static void queueMany(Processor... processors) {
ProcessingQueue processingQueue = ProcessingQueue.getInstance(); ProcessingQueue processingQueue = ProcessingQueue.getInstance();
for (Processor processor : processors) { for (Processor processor : processors) {
processingQueue.queue(processor); processingQueue.queue(processor);
@ -32,6 +32,6 @@ public abstract class Processor<T> {
} }
public void queue() { public void queue() {
queue(this); queueMany(this);
} }
} }

View File

@ -56,7 +56,7 @@ public class RegisterProcessor extends PlayerProcessor {
} catch (DBException e) { } catch (DBException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} finally { } finally {
Processor.queue(afterProcess); Processor.queueMany(afterProcess);
} }
} }
} }

View File

@ -4,7 +4,9 @@ import com.djrapitops.plan.settings.ServerSpecificSettings;
import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -125,8 +127,12 @@ public enum Settings {
return !isTrue(); return !isTrue();
} }
public void setValue(Boolean value) { public static void save() {
this.value = value; try {
ConfigSystem.getConfig().save();
} catch (IOException e) {
Log.toLog(Settings.class, e);
}
} }
/** /**
@ -162,7 +168,15 @@ public enum Settings {
return configPath; return configPath;
} }
public void setTemporaryValue(Boolean value) {
this.value = value;
}
public void set(Object value) {
getConfig().set(getPath(), value);
}
private Config getConfig() { private Config getConfig() {
return ConfigSystem.getInstance().getConfig(); return ConfigSystem.getConfig();
} }
} }

View File

@ -39,12 +39,12 @@ public abstract class ConfigSystem implements SubSystem {
return configSystem; return configSystem;
} }
public Theme getThemeSystem() { public static Config getConfig() {
return theme; return getInstance().config;
} }
public Config getConfig() { public Theme getThemeSystem() {
return config; return getInstance().theme;
} }
@Override @Override
@ -81,6 +81,6 @@ public abstract class ConfigSystem implements SubSystem {
} }
public Locale getLocale() { public Locale getLocale() {
return locale; return getInstance().locale;
} }
} }

View File

@ -36,7 +36,7 @@ public abstract class TPSCountTimer<T extends PlanPlugin> extends AbsRunnable {
addNewTPSEntry(nanoTime, now); addNewTPSEntry(nanoTime, now);
if (history.size() >= 60) { if (history.size() >= 60) {
plugin.addToProcessQueue(new TPSInsertProcessor(new ArrayList<>(history))); new TPSInsertProcessor(new ArrayList<>(history)).queue();
history.clear(); history.clear();
} }
} }

View File

@ -10,6 +10,7 @@ import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.settings.ServerSpecificSettings; import com.djrapitops.plan.settings.ServerSpecificSettings;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.webapi.WebAPI; import com.djrapitops.plan.system.webserver.webapi.WebAPI;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
@ -33,7 +34,7 @@ public class ConfigurationWebAPI extends WebAPI {
} }
if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) { if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) {
Log.info("Bungee Config settings overridden on this server."); Log.info("Bungee Config settings overridden on this server.");
Log.debug(plugin.getMainConfig().getConfigNode("Plugin.Bungee-Override").getChildren().toString()); Log.debug(ConfigSystem.getConfig().getConfigNode("Plugin.Bungee-Override").getChildren().toString());
return success(); return success();
} }
ServerSpecificSettings.updateSettings((Plan) plugin, variables); ServerSpecificSettings.updateSettings((Plan) plugin, variables);

View File

@ -4,8 +4,6 @@
*/ */
package com.djrapitops.plan.system.webserver.webapi.bungee; package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
@ -43,7 +41,7 @@ public class PostOriginalBukkitSettingsWebAPI extends WebAPI {
settings.put("WebServerPort", webServerPort); settings.put("WebServerPort", webServerPort);
settings.put("ServerName", serverName); settings.put("ServerName", serverName);
settings.put("ThemeBase", themeBase); settings.put("ThemeBase", themeBase);
Settings.serverSpecific().addOriginalBukkitSettings((PlanBungee) plugin, UUID.fromString(variables.get("sender")), settings); Settings.serverSpecific().addOriginalBukkitSettings(UUID.fromString(variables.get("sender")), settings);
return success(); return success();
} }

View File

@ -4,14 +4,13 @@
*/ */
package com.djrapitops.plan.system.webserver.webapi.bungee; package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.processors.Processor; import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.webapi.WebAPI; import com.djrapitops.plan.system.webserver.webapi.WebAPI;
import com.djrapitops.plan.system.webserver.webapi.bukkit.RequestInspectPluginsTabBukkitWebAPI; import com.djrapitops.plan.system.webserver.webapi.bukkit.RequestInspectPluginsTabBukkitWebAPI;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
@ -59,7 +58,7 @@ public class RequestPluginsTabWebAPI extends WebAPI {
} }
public void sendRequestsToBukkitServers(PlanPlugin plugin, UUID uuid) { public void sendRequestsToBukkitServers(PlanPlugin plugin, UUID uuid) {
plugin.addToProcessQueue(new Processor<UUID>(uuid) { new Processor<UUID>(uuid) {
@Override @Override
public void process() { public void process() {
try { try {
@ -76,6 +75,6 @@ public class RequestPluginsTabWebAPI extends WebAPI {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} }
} }
}); }.queue();
} }
} }

View File

@ -13,7 +13,9 @@ import com.djrapitops.plan.data.element.ActivityIndex;
import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.settings.theme.ThemeVal; import com.djrapitops.plan.settings.theme.ThemeVal;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
@ -85,7 +87,7 @@ public class InspectPage extends Page {
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
String online = "Offline"; String online = "Offline";
Optional<Session> activeSession = plugin.getInfoManager().getDataCache().getCachedSession(uuid); Optional<Session> activeSession = SessionCache.getInstance().getCachedSession(uuid);
if (activeSession.isPresent()) { if (activeSession.isPresent()) {
Session session = activeSession.get(); Session session = activeSession.get();
session.setSessionID(Integer.MAX_VALUE); session.setSessionID(Integer.MAX_VALUE);
@ -234,7 +236,7 @@ public class InspectPage extends Page {
addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp())); addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp()));
if (!plugin.getInfoManager().isUsingAnotherWebServer()) { if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable()) {
addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_")); addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
} }

View File

@ -78,6 +78,6 @@ public class ManageUtils {
@Deprecated @Deprecated
public static Database getDB(String dbName) throws DBInitException { public static Database getDB(String dbName) throws DBInitException {
return DBSystem.getInstance().getActiveDatabase(dbName); return DBSystem.getActiveDatabaseByName(dbName);
} }
} }

View File

@ -40,10 +40,10 @@ public class SettingsTest {
public void testSetValue() { public void testSetValue() {
Settings gatherCommands = Settings.LOG_UNKNOWN_COMMANDS; Settings gatherCommands = Settings.LOG_UNKNOWN_COMMANDS;
gatherCommands.setValue(false); gatherCommands.setTemporaryValue(false);
assertFalse(gatherCommands.isTrue()); assertFalse(gatherCommands.isTrue());
gatherCommands.setValue(true); gatherCommands.setTemporaryValue(true);
assertTrue(gatherCommands.isTrue()); assertTrue(gatherCommands.isTrue());
} }

View File

@ -4,8 +4,8 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.ServerVariableHolder; import com.djrapitops.plan.ServerVariableHolder;
import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.info.server.BukkitServerInfoManager; import com.djrapitops.plan.system.info.server.BukkitServerInfoManager;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.file.FileUtil; import com.djrapitops.plan.utilities.file.FileUtil;
import com.djrapitops.plugin.IPlugin; import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
@ -111,15 +111,13 @@ public class TestInit {
public void save() { public void save() {
} }
}; };
when(planMock.getMainConfig()).thenReturn(iConfig);
Server mockServer = mockServer(); Server mockServer = mockServer();
when(planMock.getServer()).thenReturn(mockServer); when(planMock.getServer()).thenReturn(mockServer);
// Test log settings // Test log settings
when(planMock.getLogger()).thenReturn(Logger.getGlobal()); when(planMock.getLogger()).thenReturn(Logger.getGlobal());
Settings.DEBUG.setValue(true); Settings.DEBUG.setTemporaryValue(true);
ServerVariableHolder serverVariableHolder = new ServerVariableHolder(mockServer); ServerVariableHolder serverVariableHolder = new ServerVariableHolder(mockServer);