From a60f77f06f89636eec927b62d2e1ff112bdf41eb Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 24 Jan 2018 21:59:53 +0200 Subject: [PATCH] Fixed some enable issues on Bukkit version. More: Tested functioning: - Enable - Reload - Analysis & Inspect command - Debug page - WebServer functions partially Tested not functioning: - /player/playername (Null response) - Some PageHandlers return null Response (Not supposed to) - /server/ (Endless "Refreshing" page) - /server/name - Style responses not found in sub folders (eg /server/page) - /players (jquery.dataTables.js Unexpected token) - Internal InfoRequests do not work as intended - Internal errors in RequestHandler - /plan manage backup, restore, setup Not Tested, probably not functioning: - Bungee - /plan manage setup Not implemented: - Player online information to transfer table - Config setting transfer - Bukkit - Bungee Set-up --- .../main/java/com/djrapitops/plan/Plan.java | 2 +- .../java/com/djrapitops/plan/PlanPlugin.java | 4 +- .../com/djrapitops/plan/api/BukkitAPI.java | 69 +++++++++++++++++++ .../java/com/djrapitops/plan/api/PlanAPI.java | 3 +- .../plan/data/plugin/HookHandler.java | 32 ++++++--- .../djrapitops/plan/system/BukkitSystem.java | 7 ++ .../djrapitops/plan/system/BungeeSystem.java | 4 +- .../djrapitops/plan/system/PlanSystem.java | 15 ++++ .../plan/system/cache/CacheSystem.java | 14 +--- .../plan/system/cache/DataCache.java | 15 +++- .../plan/system/cache/GeolocationCache.java | 23 ++++++- .../plan/system/database/DBSystem.java | 2 +- .../database/databases/sql/MySQLDB.java | 10 --- .../system/database/databases/sql/SQLDB.java | 8 ++- .../database/databases/sql/SQLiteDB.java | 7 -- .../databases/sql/tables/TransferTable.java | 2 +- .../plan/system/info/BukkitInfoSystem.java | 3 + .../plan/system/info/InfoSystem.java | 13 +++- .../connection/BukkitConnectionSystem.java | 2 +- .../connection/BungeeConnectionSystem.java | 2 +- .../system/info/connection/ConnectionOut.java | 2 +- .../info/connection/ConnectionSystem.java | 2 + .../system/settings/config/ConfigSystem.java | 4 +- .../plan/system/webserver/RequestHandler.java | 3 +- .../system/webserver/ResponseHandler.java | 7 +- .../plan/system/webserver/WebServer.java | 23 +++++-- .../system/webserver/WebServerSystem.java | 15 +--- 27 files changed, 208 insertions(+), 85 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/api/BukkitAPI.java diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 88d3bd4a8..fad8fb473 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -81,7 +81,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin { registerCommand("plan", new PlanCommand(this)); Benchmark.start("Hook to 3rd party plugins"); - hookHandler = new HookHandler(this); + hookHandler = new HookHandler(); Benchmark.stop("Enable", "Hook to 3rd party plugins"); ImporterManager.registerImporter(new OfflinePlayerImporter()); diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java b/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java index 3659b6a16..cfe50bd5e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java @@ -24,9 +24,9 @@ public interface PlanPlugin extends IPlugin { boolean bungeeAvailable = Check.isBungeeAvailable(); if (bukkitAvailable && bungeeAvailable) { // TODO Test Plugin - } else if (bungeeAvailable) { - return Plan.getInstance(); } else if (bukkitAvailable) { + return Plan.getInstance(); + } else if (bungeeAvailable) { return PlanBungee.getInstance(); } throw new IllegalAccessError("Plugin instance not available"); diff --git a/Plan/src/main/java/com/djrapitops/plan/api/BukkitAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/BukkitAPI.java new file mode 100644 index 000000000..2bb305721 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/api/BukkitAPI.java @@ -0,0 +1,69 @@ +/* + * 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.api; + +import com.djrapitops.plan.api.exceptions.database.DBException; +import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.system.BukkitSystem; +import com.djrapitops.plan.system.database.databases.operation.FetchOperations; +import com.djrapitops.plugin.api.utility.log.Log; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class BukkitAPI implements PlanAPI { + + private final BukkitSystem bukkitSystem; + + public BukkitAPI(BukkitSystem bukkitSystem) { + this.bukkitSystem = bukkitSystem; + } + + @Override + public void addPluginDataSource(PluginData pluginData) { + bukkitSystem.getHookHandler().addPluginDataSource(pluginData); + } + + @Override + public String getPlayerInspectPageLink(UUID uuid) { + return getPlayerInspectPageLink(getPlayerName(uuid)); + } + + @Override + public String getPlayerInspectPageLink(String playerName) { + return "../player/" + playerName; + } + + @Override + public String getPlayerName(UUID uuid) { + return bukkitSystem.getCacheSystem().getDataCache().getName(uuid); + } + + @Override + public UUID playerNameToUUID(String playerName) { + return bukkitSystem.getCacheSystem().getDataCache().getUUIDof(playerName); + } + + @Override + public Map getKnownPlayerNames() { + try { + return bukkitSystem.getDatabaseSystem().getActiveDatabase().fetch().getPlayerNames(); + } catch (DBException e) { + Log.toLog(this.getClass(), e); + return new HashMap<>(); + } + } + + @Override + public FetchOperations fetchFromPlanDB() { + return bukkitSystem.getDatabaseSystem().getActiveDatabase().fetch(); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java index 879315e14..9793049cd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java @@ -5,6 +5,7 @@ package com.djrapitops.plan.api; import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import java.util.Map; @@ -18,7 +19,7 @@ import java.util.UUID; public interface PlanAPI { static PlanAPI getInstance() { - throw new IllegalAccessError("Not yet implemented"); // TODO + return PlanSystem.getInstance().getPlanAPI(); } void addPluginDataSource(PluginData pluginData); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java index ed0f3b7d7..1d30e0d7d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java @@ -2,8 +2,12 @@ package com.djrapitops.plan.data.plugin; import com.djrapitops.plan.Plan; import com.djrapitops.plan.data.element.InspectContainer; +import com.djrapitops.plan.system.PlanSystem; +import com.djrapitops.plan.system.SubSystem; +import com.djrapitops.plan.utilities.NullCheck; import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.pluginbridge.plan.Bridge; import java.util.*; @@ -14,29 +18,35 @@ import java.util.*; * @author Rsl1122 * @since 2.6.0 */ -public class HookHandler { +public class HookHandler implements SubSystem { private final List additionalDataSources; - private final PluginsConfigSection configHandler; + private PluginsConfigSection configHandler; - /** - * Class constructor, hooks to plugins. - * - * @param plugin Current instance of plan. - */ - public HookHandler(Plan plugin) { + public HookHandler() { additionalDataSources = new ArrayList<>(); + } + + public static HookHandler getInstance() { + HookHandler hookHandler = PlanSystem.getInstance().getHookHandler(); + NullCheck.check(hookHandler, new IllegalStateException("Plugin Hooks were not initialized.")); + return hookHandler; + } + + @Override + public void enable() { 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."); } } - public static HookHandler getInstance() { - return null;// TODO + @Override + public void disable() { + } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java index bdda879db..9563b4385 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java @@ -6,8 +6,11 @@ package com.djrapitops.plan.system; import com.djrapitops.plan.Plan; import com.djrapitops.plan.ShutdownHook; +import com.djrapitops.plan.api.BukkitAPI; +import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.system.database.BukkitDBSystem; import com.djrapitops.plan.system.file.FileSystem; +import com.djrapitops.plan.system.info.BukkitInfoSystem; import com.djrapitops.plan.system.info.server.BukkitServerInfo; import com.djrapitops.plan.system.listeners.BukkitListenerSystem; import com.djrapitops.plan.system.settings.config.BukkitConfigSystem; @@ -30,8 +33,12 @@ public class BukkitSystem extends PlanSystem { listenerSystem = new BukkitListenerSystem(plugin); taskSystem = new BukkitTaskSystem(plugin); + infoSystem = new BukkitInfoSystem(); serverInfo = new BukkitServerInfo(plugin); + hookHandler = new HookHandler(); + planAPI = new BukkitAPI(this); + StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass()); new ShutdownHook().register(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java index d31e3a1a3..86fc6525f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java @@ -7,7 +7,7 @@ package com.djrapitops.plan.system; import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.system.database.BungeeDBSystem; import com.djrapitops.plan.system.file.FileSystem; -import com.djrapitops.plan.system.info.BukkitInfoSystem; +import com.djrapitops.plan.system.info.BungeeInfoSystem; import com.djrapitops.plan.system.info.server.BungeeServerInfo; import com.djrapitops.plan.system.listeners.BungeeListenerSystem; import com.djrapitops.plan.system.settings.config.BungeeConfigSystem; @@ -29,7 +29,7 @@ public class BungeeSystem extends PlanSystem { listenerSystem = new BungeeListenerSystem(plugin); taskSystem = new BungeeTaskSystem(plugin); - infoSystem = new BukkitInfoSystem(); + infoSystem = new BungeeInfoSystem(); serverInfo = new BungeeServerInfo(plugin); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java index 2be10b239..6e185baa2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/PlanSystem.java @@ -4,7 +4,9 @@ */ package com.djrapitops.plan.system; +import com.djrapitops.plan.api.PlanAPI; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.system.cache.CacheSystem; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.file.FileSystem; @@ -44,6 +46,9 @@ public abstract class PlanSystem implements SubSystem { protected TaskSystem taskSystem; protected ServerInfo serverInfo; + protected HookHandler hookHandler; + protected PlanAPI planAPI; + public PlanSystem() { processingQueue = new ProcessingQueue(); webServerSystem = new WebServerSystem(); @@ -117,6 +122,8 @@ public abstract class PlanSystem implements SubSystem { NullCheck.check(serverInfo, new IllegalStateException("ServerInfo was not initialized.")); NullCheck.check(listenerSystem, new IllegalStateException("Listener system was not initialized.")); NullCheck.check(taskSystem, new IllegalStateException("Task system was not initialized.")); + NullCheck.check(hookHandler, new IllegalStateException("Plugin Hooks were not initialized.")); + NullCheck.check(planAPI, new IllegalStateException("Plan API was not initialized.")); } catch (Exception e) { throw new EnableException("One of the subsystems is not initialized on enable for " + this.getClass().getSimpleName() + ".", e); } @@ -167,4 +174,12 @@ public abstract class PlanSystem implements SubSystem { public InfoSystem getInfoSystem() { return infoSystem; } + + public HookHandler getHookHandler() { + return hookHandler; + } + + public PlanAPI getPlanAPI() { + return planAPI; + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java index 7d578ed84..bf4ee8883 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java @@ -8,10 +8,6 @@ import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.utilities.NullCheck; -import com.djrapitops.plugin.api.utility.log.Log; - -import java.io.IOException; -import java.net.UnknownHostException; /** * System that holds data caches of the plugin. @@ -36,13 +32,9 @@ public class CacheSystem implements SubSystem { @Override public void enable() throws EnableException { - try { - GeolocationCache.checkDB(); - } catch (UnknownHostException e) { - Log.error("Plan Requires internet access on first run to download GeoLite2 Geolocation database."); - } catch (IOException e) { - throw new EnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e); - } + dataCache.enable(); + geolocationCache.enable(); + } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java index a2d907d92..d3fb5d21c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java @@ -2,6 +2,7 @@ package com.djrapitops.plan.system.cache; import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.system.PlanSystem; +import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.utilities.NullCheck; import com.djrapitops.plugin.api.utility.log.Log; @@ -21,9 +22,9 @@ import java.util.*; * @author Rsl1122 * @since 4.0.0 */ -public class DataCache extends SessionCache { +public class DataCache extends SessionCache implements SubSystem { - private final Database db; + private Database db; private final Map playerNames; private final Map uuids; private final Map displayNames; @@ -35,13 +36,21 @@ public class DataCache extends SessionCache { */ public DataCache(PlanSystem system) { super(system); - db = system.getDatabaseSystem().getActiveDatabase(); playerNames = new HashMap<>(); displayNames = new HashMap<>(); uuids = new HashMap<>(); } + @Override + public void enable() { + db = system.getDatabaseSystem().getActiveDatabase(); + } + + @Override + public void disable() { + } + public static DataCache getInstance() { DataCache dataCache = CacheSystem.getInstance().getDataCache(); NullCheck.check(dataCache, new IllegalStateException("Data Cache was not initialized.")); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java index 20f43d04b..7cbd1978f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/GeolocationCache.java @@ -1,7 +1,10 @@ package com.djrapitops.plan.system.cache; +import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.utilities.NullCheck; +import com.djrapitops.plugin.api.utility.log.Log; import com.google.common.cache.Cache; import com.maxmind.geoip2.DatabaseReader; import com.maxmind.geoip2.exception.GeoIp2Exception; @@ -13,6 +16,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.InetAddress; import java.net.URL; +import java.net.UnknownHostException; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.HashMap; @@ -29,14 +33,29 @@ import java.util.zip.GZIPInputStream; * @author Fuzzlemann * @since 3.5.5 */ -public class GeolocationCache { +public class GeolocationCache implements SubSystem { private final Map geolocationCache; - private final File geolocationDB; + private File geolocationDB; public GeolocationCache() { geolocationCache = new HashMap<>(); + } + + @Override + public void enable() throws EnableException { geolocationDB = new File(FileSystem.getDataFolder(), "GeoIP.dat"); + try { + GeolocationCache.checkDB(); + } catch (UnknownHostException e) { + Log.error("Plan Requires internet access on first run to download GeoLite2 Geolocation database."); + } catch (IOException e) { + throw new EnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e); + } + } + + @Override + public void disable() { } private static GeolocationCache getInstance() { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java index ed4e92798..a8c99af8c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java @@ -50,7 +50,7 @@ public abstract class DBSystem implements SubSystem { Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName())); Benchmark.stop("Enable", "Init Database"); } catch (DBInitException e) { - throw new EnableException(db.getName() + "-Database failed to initialize", e); + throw new EnableException("Database failed to initialize", e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java index b1709ac5a..34cf4fed0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java @@ -1,7 +1,5 @@ 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; @@ -16,15 +14,7 @@ public class MySQLDB extends SQLDB { private BasicDataSource dataSource; - private final SQLTransferOps transferOps; - public MySQLDB() { - transferOps = new SQLTransferOps(this); - } - - @Override - public TransferOperations transfer() { - return transferOps; } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java index 01808fb47..35c73d24e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java @@ -48,6 +48,7 @@ public abstract class SQLDB extends Database { private final SQLSearchOps searchOps; private final SQLCountOps countOps; private final SQLSaveOps saveOps; + private final SQLTransferOps transferOps; private final boolean usingMySQL; private boolean open = false; @@ -81,7 +82,7 @@ public abstract class SQLDB extends Database { countOps = new SQLCountOps(this); searchOps = new SQLSearchOps(this); saveOps = new SQLSaveOps(this); - + transferOps = new SQLTransferOps(this); } /** @@ -390,4 +391,9 @@ public abstract class SQLDB extends Database { public SaveOperations save() { return saveOps; } + + @Override + public TransferOperations transfer() { + return transferOps; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java index b140d0ceb..e9a1f1fd1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java @@ -1,9 +1,7 @@ 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; @@ -37,11 +35,6 @@ public class SQLiteDB extends SQLDB { this.dbName = dbName; } - @Override - public TransferOperations transfer() throws UnsupportedTransferDatabaseException { - throw new UnsupportedTransferDatabaseException(this); - } - /** * Setups the {@link BasicDataSource} */ diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java index e74d95933..985db34e7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java @@ -69,7 +69,7 @@ public class TransferTable extends Table { .column(columnSenderID, Sql.INT).notNull() .column(columnExpiry, Sql.LONG).notNull().defaultValue("0") .column(columnInfoType, Sql.varchar(100)).notNull() - .column(columnExtraVariables, Sql.varchar(255)).defaultValue("") + .column(columnExtraVariables, Sql.varchar(255)).defaultValue("''") .column(columnContent, usingMySQL ? "MEDIUMTEXT" : Sql.varchar(1)) // SQLite does not enforce varchar limits. .foreignKey(columnSenderID, serverTable.toString(), serverTable.getColumnID()) .toString() diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java index c7dad76ad..997a9df4c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java @@ -27,6 +27,9 @@ public class BukkitInfoSystem extends InfoSystem { @Override protected void runLocally(InfoRequest infoRequest) throws WebException { + if (infoRequest instanceof CacheNetworkPageContentRequest) { + return; + } if (infoRequest instanceof InfoRequestWithVariables) { infoRequest.handleRequest(((InfoRequestWithVariables) infoRequest).getVariables()); } else { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java index ac0ada236..4f6045e0b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java @@ -5,6 +5,7 @@ package com.djrapitops.plan.system.info; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.SubSystem; @@ -57,10 +58,14 @@ public abstract class InfoSystem implements SubSystem { } public void sendRequest(InfoRequest infoRequest) throws WebException { - if (!connectionSystem.isServerAvailable()) { + try { + if (!connectionSystem.isServerAvailable()) { + runLocally(infoRequest); + } + connectionSystem.sendInfoRequest(infoRequest); + } catch (NoServersException e) { runLocally(infoRequest); } - connectionSystem.sendInfoRequest(infoRequest); } protected abstract void runLocally(InfoRequest infoRequest) throws WebException; @@ -70,6 +75,8 @@ public abstract class InfoSystem implements SubSystem { connectionSystem.enable(); try { updateNetworkPage(); + } catch (NoServersException e) { + /* Ignored */ } catch (WebException e) { // TODO Exception handling Log.toLog(this.getClass().getName(), e); @@ -87,7 +94,7 @@ public abstract class InfoSystem implements SubSystem { public abstract void updateNetworkPage() throws WebException; - public void requestSetUp(String address) throws WebException { + public void requestSetUp(String address) { // TODO } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java index 71e675d03..c9a58b115 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java @@ -77,7 +77,7 @@ public class BukkitConnectionSystem extends ConnectionSystem { } } if (server == null) { - throw new NoServersException("Proper server is not available to process requests."); + throw new NoServersException("Proper server is not available to process request: " + infoRequest.getClass().getSimpleName()); } return server; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java index 1273d6de6..5c256b395 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java @@ -63,7 +63,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { } } if (server == null) { - throw new NoServersException("Proper server is not available to process requests."); + throw new NoServersException("Proper server is not available to process request: " + infoRequest.getClass().getSimpleName()); } return server; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java index a51ff1eaf..11dfc3b7e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java @@ -67,7 +67,7 @@ public class ConnectionOut { public void sendRequest() throws WebException { String address = toServer.getWebAddress(); try { - URL url = new URL(address + "/info/" + this.getClass().getSimpleName().toLowerCase()); + URL url = new URL(address + "/info/" + infoRequest.getClass().getSimpleName().toLowerCase()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (address.startsWith("https")) { HttpsURLConnection httpsConn = (HttpsURLConnection) connection; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java index d83bf9a63..982f6bea5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java @@ -54,11 +54,13 @@ public abstract class ConnectionSystem implements SubSystem { private Map loadDataRequests() { Map requests = new HashMap<>(); putRequest(requests, CacheInspectPageRequest.createHandler()); + putRequest(requests, CacheInspectPluginsTabRequest.createHandler()); putRequest(requests, CacheAnalysisPageRequest.createHandler()); putRequest(requests, CacheNetworkPageContentRequest.createHandler()); putRequest(requests, GenerateAnalysisPageRequest.createHandler()); putRequest(requests, GenerateInspectPageRequest.createHandler()); + putRequest(requests, GenerateInspectPluginsTabRequest.createHandler()); return requests; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java index 9f02cb10f..a79b52af5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java @@ -24,12 +24,11 @@ import java.io.IOException; */ public abstract class ConfigSystem implements SubSystem { - protected final Config config; + protected Config config; protected final Locale locale; protected final Theme theme; public ConfigSystem() { - config = new Config(FileSystem.getConfigFile()); locale = new Locale(); theme = new Theme(); } @@ -50,6 +49,7 @@ public abstract class ConfigSystem implements SubSystem { @Override public void enable() throws EnableException { + config = new Config(FileSystem.getConfigFile()); try { copyDefaults(); config.save(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java index 73326d38d..93ece4bc6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java @@ -16,7 +16,6 @@ import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; -import java.io.IOException; import java.util.List; /** @@ -50,7 +49,7 @@ public class RequestHandler implements HttpHandler { } response.setResponseHeaders(responseHeaders); response.send(exchange); - } catch (IOException e) { + } catch (Exception e) { if (Settings.DEV_MODE.isTrue()) { e.printStackTrace(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java index 5a33ea9bf..e5a5a4c5a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java @@ -18,6 +18,7 @@ import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse; import com.djrapitops.plan.system.webserver.response.errors.UnauthorizedServerResponse; import com.djrapitops.plugin.api.utility.log.Log; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -79,8 +80,10 @@ public class ResponseHandler extends TreePageHandler { public Response getResponse(Request request) { String targetString = request.getTarget(); - List target = Arrays.asList(targetString.split("/")); - target.remove(0); + List target = new ArrayList<>(Arrays.asList(targetString.split("/"))); + if (!target.isEmpty()) { + target.remove(0); + } try { return getResponse(request, targetString, target); } catch (WebUserAuthException e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java index fc6470315..24e925518 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java @@ -1,6 +1,7 @@ package com.djrapitops.plan.system.webserver; import com.djrapitops.plan.PlanPlugin; +import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.settings.Settings; @@ -44,17 +45,28 @@ public class WebServer implements SubSystem { private ResponseHandler responseHandler; @Override - public void enable() { + public void enable() throws EnableException { this.port = Settings.WEBSERVER_PORT.getNumber(); + requestHandler = new RequestHandler(this); + responseHandler = requestHandler.getResponseHandler(); + PlanPlugin plugin = PlanPlugin.getInstance(); StaticHolder.saveInstance(RequestHandler.class, plugin.getClass()); StaticHolder.saveInstance(ResponseHandler.class, plugin.getClass()); - requestHandler = new RequestHandler(this); - responseHandler = requestHandler.getResponseHandler(); - initServer(); + + if (!isEnabled()) { + if (Check.isBungeeAvailable()) { + throw new EnableException("WebServer did not initialize!"); + } + if (Settings.WEBSERVER_DISABLED.isTrue()) { + Log.warn("WebServer was not initialized. (WebServer.DisableWebServer: true)"); + } else { + Log.error("WebServer was not initialized successfully. Is the port (" + Settings.WEBSERVER_PORT.getNumber() + ") in use?"); + } + } } @Override @@ -65,7 +77,7 @@ public class WebServer implements SubSystem { /** * Starts up the WebServer in a new Thread Pool. */ - public void initServer() { + private void initServer() { // Check if Bukkit WebServer has been disabled. if (!Check.isBungeeAvailable() && Settings.WEBSERVER_DISABLED.isTrue()) { return; @@ -86,7 +98,6 @@ public class WebServer implements SubSystem { Log.infoColor("§eUser Authorization Disabled! (Not possible over http)"); server = HttpServer.create(new InetSocketAddress(Settings.WEBSERVER_IP.toString(), port), 10); } - server.createContext("/", requestHandler); server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100))); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServerSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServerSystem.java index 7d22df88c..b1f5c4ee0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServerSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServerSystem.java @@ -7,11 +7,8 @@ package com.djrapitops.plan.system.webserver; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.SubSystem; -import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.webserver.response.cache.ResponseCache; import com.djrapitops.plugin.api.Benchmark; -import com.djrapitops.plugin.api.Check; -import com.djrapitops.plugin.api.utility.log.Log; /** * WebServer subsystem for managing WebServer initialization. @@ -38,17 +35,7 @@ public class WebServerSystem implements SubSystem { @Override public void enable() throws EnableException { Benchmark.start("WebServer Initialization"); - webServer.initServer(); - if (!webServer.isEnabled()) { - if (Check.isBungeeAvailable()) { - throw new EnableException("WebServer did not initialize!"); - } - if (Settings.WEBSERVER_DISABLED.isTrue()) { - Log.warn("WebServer was not initialized. (WebServer.DisableWebServer: true)"); - } else { - Log.error("WebServer was not initialized successfully. Is the port (" + Settings.WEBSERVER_PORT.getNumber() + ") in use?"); - } - } + webServer.enable(); Benchmark.stop("Enable", "WebServer Initialization"); ResponseHandler responseHandler = webServer.getResponseHandler(); responseHandler.registerWebAPIPages();