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;
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.systems.info.InformationManager;
import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.settings.ColorScheme;
import java.io.File;
@ -54,17 +51,8 @@ public interface PlanPlugin extends IPlugin {
File getDataFolder();
@Deprecated
ProcessingQueue getProcessingQueue();
@Deprecated
void addToProcessQueue(Processor... processors);
InputStream getResource(String resource);
@Deprecated
Config getMainConfig();
ColorScheme getColorScheme();
boolean isReloading();

View File

@ -4,19 +4,19 @@
*/
package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.Actions;
import com.djrapitops.plan.data.container.Action;
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.SessionCache;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.tables.SessionsTable;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
@ -30,64 +30,57 @@ import java.util.UUID;
public class ShutdownHook extends Thread {
private static boolean active = false;
private static DataCache dataCache;
private static SQLDB db;
public ShutdownHook(Plan plugin) {
public void register() {
if (!active) {
Runtime.getRuntime().addShutdownHook(this);
}
active = true;
db = (SQLDB) plugin.getDB();
dataCache = plugin.getDataCache();
}
@Override
public void run() {
Log.debug("Shutdown hook triggered.");
Database db = null;
try {
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
long now = MiscUtils.getTime();
if (db == null) {
return;
}
db = Database.getActive();
if (!db.isOpen()) {
db.init();
}
saveFirstSessionInformation(now);
saveActiveSessions(activeSessions, now);
saveFirstSessionInformation(db, now);
saveActiveSessions(db, activeSessions, now);
} catch (DBInitException e) {
Log.toLog(this.getClass().getName(), e);
} finally {
if (db != null) {
try {
db.close();
} catch (SQLException e) {
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
}
}
db = null;
dataCache = null;
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()) {
try {
UUID uuid = entry.getKey();
int messagesSent = entry.getValue();
db.getActionsTable().insertAction(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent));
} catch (SQLException e) {
db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent));
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
}
}
}
private void saveActiveSessions(Map<UUID, Session> activeSessions, long now) {
SessionsTable sessionsTable = db.getSessionsTable();
private void saveActiveSessions(Database db, Map<UUID, Session> activeSessions, long now) {
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
UUID uuid = entry.getKey();
Session session = entry.getValue();
@ -98,8 +91,8 @@ public class ShutdownHook extends Thread {
session.endSession(now);
try {
Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
sessionsTable.saveSession(uuid, session);
} catch (SQLException e) {
db.save().session(uuid, session);
} catch (DBException 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.settings.locale.Locale;
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.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
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.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.utilities.Verify;
import java.io.IOException;
/**
* 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.
@ -66,7 +63,7 @@ public class ManageHotswapCommand extends SubCommand {
}
try {
final Database database = ManageUtils.getDB(dbName);
final Database database = DBSystem.getActiveDatabaseByName(dbName);
// If DB is null return
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;
}
assert database != null;
database.getVersion(); //Test db connection
if (!database.isOpen()) {
return true;
}
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
return true;
}
Config config = plugin.getMainConfig();
config.set(Settings.DB_TYPE.getPath(), dbName);
try {
config.save();
Settings.DB_TYPE.set(dbName);
Settings.save();
plugin.reloadPlugin(true);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
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.webserver.webapi.bungee.RequestSetupWebAPI;
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.command.CommandType;
import com.djrapitops.plugin.command.ISender;
@ -65,9 +64,8 @@ public class ManageSetupCommand extends SubCommand {
address = address.substring(0, address.length() - 1);
}
try {
Config config = plugin.getMainConfig();
config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.getPath(), false);
config.set(Settings.BUNGEE_COPY_CONFIG.getPath(), true);
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
Settings.BUNGEE_COPY_CONFIG.set(true);
// plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.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.");

View File

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

View File

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

View File

@ -1,11 +1,14 @@
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.data.container.Session;
import com.djrapitops.plan.system.PlanSystem;
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.utilities.MiscUtils;
import com.djrapitops.plan.utilities.NullCheck;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.HashMap;
@ -32,6 +35,12 @@ public class SessionCache {
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.
* <p>
@ -52,7 +61,11 @@ public class SessionCache {
new Processor<PlanSystem>(system) {
@Override
public void process() {
system.getInfoManager().cachePlayer(uuid);
try {
system.getInfoSystem().generateAndCachePlayerPage(uuid);
} catch (WebException e) {
WebExceptionLogger.log(this.getClass(), e);
}
}
}.queue();
}
@ -69,7 +82,11 @@ public class SessionCache {
Log.toLog(this.getClass().getName(), e);
} finally {
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());
String dbType = Settings.DB_TYPE.toString().toLowerCase().trim();
db = getActiveDatabase(dbType);
db = getActiveDatabaseByName(dbType);
db.init();
}
}

View File

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

View File

@ -1,5 +1,7 @@
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.plugin.api.utility.log.Log;
import org.apache.commons.dbcp2.BasicDataSource;
@ -14,6 +16,17 @@ public class MySQLDB extends SQLDB {
private BasicDataSource dataSource;
private final SQLTransferOps transferOps;
public MySQLDB() {
transferOps = new SQLTransferOps(this);
}
@Override
public TransferOperations transfer() {
return transferOps;
}
/**
* Setups the {@link BasicDataSource}
*/

View File

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

View File

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

View File

@ -318,4 +318,31 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
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.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.SubSystem;
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.InfoRequest;
import com.djrapitops.plan.utilities.NullCheck;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.UUID;
interface ExceptionLoggingAction {
void performAction() throws WebException;
}
/**
* Information management system.
* <p>
@ -86,15 +79,4 @@ public abstract class InfoSystem implements SubSystem {
}
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
public void placeDataToDatabase() {
// No data required in a Generate request
}
@Override

View File

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

View File

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

View File

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

View File

@ -56,7 +56,7 @@ public class RegisterProcessor extends PlayerProcessor {
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
} 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.plugin.api.Check;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import java.io.IOException;
import java.util.List;
/**
@ -125,8 +127,12 @@ public enum Settings {
return !isTrue();
}
public void setValue(Boolean value) {
this.value = value;
public static void save() {
try {
ConfigSystem.getConfig().save();
} catch (IOException e) {
Log.toLog(Settings.class, e);
}
}
/**
@ -162,7 +168,15 @@ public enum Settings {
return configPath;
}
public void setTemporaryValue(Boolean value) {
this.value = value;
}
public void set(Object value) {
getConfig().set(getPath(), value);
}
private Config getConfig() {
return ConfigSystem.getInstance().getConfig();
return ConfigSystem.getConfig();
}
}

View File

@ -39,12 +39,12 @@ public abstract class ConfigSystem implements SubSystem {
return configSystem;
}
public Theme getThemeSystem() {
return theme;
public static Config getConfig() {
return getInstance().config;
}
public Config getConfig() {
return config;
public Theme getThemeSystem() {
return getInstance().theme;
}
@Override
@ -81,6 +81,6 @@ public abstract class ConfigSystem implements SubSystem {
}
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);
if (history.size() >= 60) {
plugin.addToProcessQueue(new TPSInsertProcessor(new ArrayList<>(history)));
new TPSInsertProcessor(new ArrayList<>(history)).queue();
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.settings.ServerSpecificSettings;
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.webapi.WebAPI;
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()) {
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();
}
ServerSpecificSettings.updateSettings((Plan) plugin, variables);

View File

@ -4,8 +4,6 @@
*/
package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.settings.Settings;
@ -43,7 +41,7 @@ public class PostOriginalBukkitSettingsWebAPI extends WebAPI {
settings.put("WebServerPort", webServerPort);
settings.put("ServerName", serverName);
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();
}

View File

@ -4,14 +4,13 @@
*/
package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanPlugin;
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.webserver.response.Response;
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
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.utility.log.Log;
@ -59,7 +58,7 @@ public class RequestPluginsTabWebAPI extends WebAPI {
}
public void sendRequestsToBukkitServers(PlanPlugin plugin, UUID uuid) {
plugin.addToProcessQueue(new Processor<UUID>(uuid) {
new Processor<UUID>(uuid) {
@Override
public void process() {
try {
@ -76,6 +75,6 @@ public class RequestPluginsTabWebAPI extends WebAPI {
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.settings.theme.Theme;
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.info.InfoSystem;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.MiscUtils;
@ -85,7 +87,7 @@ public class InspectPage extends Page {
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
String online = "Offline";
Optional<Session> activeSession = plugin.getInfoManager().getDataCache().getCachedSession(uuid);
Optional<Session> activeSession = SessionCache.getInstance().getCachedSession(uuid);
if (activeSession.isPresent()) {
Session session = activeSession.get();
session.setSessionID(Integer.MAX_VALUE);
@ -234,7 +236,7 @@ public class InspectPage extends Page {
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]", "_"));
}

View File

@ -78,6 +78,6 @@ public class ManageUtils {
@Deprecated
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() {
Settings gatherCommands = Settings.LOG_UNKNOWN_COMMANDS;
gatherCommands.setValue(false);
gatherCommands.setTemporaryValue(false);
assertFalse(gatherCommands.isTrue());
gatherCommands.setValue(true);
gatherCommands.setTemporaryValue(true);
assertTrue(gatherCommands.isTrue());
}

View File

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