diff --git a/Plan/pom.xml b/Plan/pom.xml index 83cb26a18..9f2042a2b 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -15,20 +15,32 @@ plan-snapshot-repo http://repo.fuzzlemann.de/artifactory/libs-snapshot/ + + bungeecord-repo + https://oss.sonatype.org/content/repositories/snapshots + - + com.destroystokyo.paper paper 1.12-R0.1-20170725.202533-1 provided + + + net.md-5 + bungeecord-api + 1.12-SNAPSHOT + jar + provided + com.djrapitops abstract-plugin-framework - 2.0.4 + 2.0.5 compile diff --git a/Plan/src/main/java/com/djrapitops/plan/Log.java b/Plan/src/main/java/com/djrapitops/plan/Log.java index 7c27a253c..89886ffe5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Log.java +++ b/Plan/src/main/java/com/djrapitops/plan/Log.java @@ -1,6 +1,9 @@ package main.java.com.djrapitops.plan; +import com.djrapitops.plugin.utilities.Compatibility; import com.djrapitops.plugin.utilities.log.DebugInfo; +import com.djrapitops.plugin.utilities.log.PluginLog; +import main.java.com.djrapitops.plan.bungee.PlanBungee; import main.java.com.djrapitops.plan.utilities.MiscUtils; import java.util.Collection; @@ -28,7 +31,7 @@ public class Log { * @param message "Message" will show up as [INFO][Plan]: Message */ public static void info(String message) { - Plan.getInstance().getPluginLogger().info(message); + getPluginLogger().info(message); } /** @@ -37,7 +40,7 @@ public class Log { * @param message Message to send. */ public static void infoColor(String message) { - Plan.getInstance().getPluginLogger().infoColor(message); + getPluginLogger().infoColor(message); } /** @@ -46,7 +49,7 @@ public class Log { * @param message "Message" will show up as [ERROR][Plan]: Message */ public static void error(String message) { - Plan.getInstance().getPluginLogger().error(message); + getPluginLogger().error(message); } /** @@ -55,7 +58,7 @@ public class Log { * @param message "Message" will show up as [INFO][Plan]: [DEBUG] Message */ public static void debug(String message) { - Plan.getInstance().getPluginLogger().debug(message); + getPluginLogger().debug(message); } @@ -93,7 +96,7 @@ public class Log { * @return full debug complex so far. */ public static DebugInfo getDebug(String task) { - return Plan.getInstance().getPluginLogger().getDebug(task); + return getPluginLogger().getDebug(task); } /** @@ -122,7 +125,7 @@ public class Log { * @param e {@code Throwable}, eg NullPointerException */ public static void toLog(String source, Throwable e) { - Plan.getInstance().getPluginLogger().toLog(source, e); + getPluginLogger().toLog(source, e); } /** @@ -134,4 +137,12 @@ public class Log { public static void toLog(String source, Collection e) { Plan.getInstance().getPluginLogger().toLog(source, e); } + + private static PluginLog getPluginLogger() { + if (Compatibility.isBukkitAvailable()) { + return Plan.getInstance().getPluginLogger(); + } else { + return PlanBungee.getInstance().getPluginLogger(); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index d392e9a8a..81a032372 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -27,6 +27,7 @@ import com.djrapitops.plugin.task.ITask; import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.api.API; +import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.command.PlanCommand; import main.java.com.djrapitops.plan.command.commands.RegisterCommandFilter; import main.java.com.djrapitops.plan.data.additional.HookHandler; @@ -51,6 +52,7 @@ import org.apache.logging.log4j.LogManager; import org.bukkit.ChatColor; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -63,7 +65,7 @@ import java.util.UUID; * @author Rsl1122 * @since 1.0.0 */ -public class Plan extends BukkitPlugin { +public class Plan extends BukkitPlugin implements IPlan { private API api; @@ -141,7 +143,7 @@ public class Plan extends BukkitPlugin { Benchmark.start("Copy default config"); getConfig().options().copyDefaults(true); - getConfig().options().header("Plan Config | More info at https://www.spigotmc.org/wiki/plan-configuration/"); + getConfig().options().header("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md"); saveConfig(); Benchmark.stop("Enable", "Copy default config"); @@ -169,6 +171,8 @@ public class Plan extends BukkitPlugin { infoManager = new InformationManager(this); webServer.setInfoManager(infoManager); + Benchmark.stop("Enable", "WebServer Initialization"); + registerListeners(); registerTasks(); @@ -274,6 +278,12 @@ public class Plan extends BukkitPlugin { webServer.stop(); } + List processors = processingQueue.stopAndReturnLeftovers(); + Log.info("Processing unprocessed processors. (" + processors.size() + ")"); // TODO Move to Locale + for (Processor processor : processors) { + processor.process(); + } + getServer().getScheduler().cancelTasks(this); if (Verify.notNull(infoManager, db)) { diff --git a/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java b/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java index 04d3c69cb..172586dc1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java +++ b/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java @@ -1,7 +1,5 @@ package main.java.com.djrapitops.plan; -import org.bukkit.Server; - /** * Class responsible for holding server variable values that do not change * without a reload. @@ -11,6 +9,10 @@ import org.bukkit.Server; */ public class ServerVariableHolder { + private final String name; + private final int port; + private final String version; + private final String implVersion; private final String ip; private final boolean usingPaper; @@ -19,12 +21,29 @@ public class ServerVariableHolder { * * @param server instance the plugin is running on. */ - public ServerVariableHolder(Server server) { + public ServerVariableHolder(org.bukkit.Server server) { ip = server.getIp(); + name = server.getName(); + port = server.getPort(); + version = server.getVersion(); + implVersion = server.getBukkitVersion(); - String serverName = server.getName(); - usingPaper = serverName.equals("Paper") - || serverName.equals("TacoSpigot"); //Fork of Paper + usingPaper = name.equals("Paper") + || name.equals("TacoSpigot"); //Fork of Paper + } + + /** + * Constructor, grabs the variables. + * + * @param server instance the plugin is running on. + */ + public ServerVariableHolder(net.md_5.bungee.api.ProxyServer server) { + ip = Settings.BUNGEE_IP.toString(); + name = "BungeeCord"; + port = Settings.BUNGEE_PORT.getNumber(); + version = server.getVersion(); + implVersion = server.getVersion(); + usingPaper = false; } /** @@ -44,4 +63,20 @@ public class ServerVariableHolder { public boolean isUsingPaper() { return usingPaper; } + + public String getName() { + return name; + } + + public int getPort() { + return port; + } + + public String getVersion() { + return version; + } + + public String getImplVersion() { + return implVersion; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/Settings.java b/Plan/src/main/java/com/djrapitops/plan/Settings.java index aa18d5a8a..e9ddb56ae 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/Settings.java @@ -1,5 +1,11 @@ package main.java.com.djrapitops.plan; +import com.djrapitops.plugin.config.fileconfig.BukkitFileConfig; +import com.djrapitops.plugin.config.fileconfig.IFileConfig; +import com.djrapitops.plugin.utilities.Compatibility; +import main.java.com.djrapitops.plan.bungee.PlanBungee; + +import java.io.IOException; import java.util.List; /** @@ -78,7 +84,13 @@ public enum Settings { THEME_GRAPH_ENTITIES("Theme.Graphs.Entities"), // StringList HIDE_FACTIONS("Plugins.Factions.HideFactions"), - HIDE_TOWNS("Plugins.Towny.HideTowns"); + HIDE_TOWNS("Plugins.Towny.HideTowns"), + // + // Bungee + BUNGEE_IP("Server.IP"), + BUNGEE_PORT("Server.Port") + ; + private final String configPath; private Boolean value; @@ -96,7 +108,7 @@ public enum Settings { if (value != null) { return value; } - return Plan.getInstance().getConfig().getBoolean(configPath); + return getConfig().getBoolean(configPath); } public void setValue(Boolean value) { @@ -110,7 +122,7 @@ public enum Settings { */ @Override public String toString() { - return Plan.getInstance().getConfig().getString(configPath); + return getConfig().getString(configPath); } /** @@ -119,11 +131,11 @@ public enum Settings { * @return Integer value of the config setting */ public int getNumber() { - return Plan.getInstance().getConfig().getInt(configPath); + return getConfig().getInt(configPath); } public List getStringList() { - return Plan.getInstance().getConfig().getStringList(configPath); + return getConfig().getStringList(configPath); } /** @@ -135,4 +147,16 @@ public enum Settings { public String getPath() { return configPath; } + + private IFileConfig getConfig() { + try { + if (Compatibility.isBukkitAvailable()) { + return new BukkitFileConfig(Plan.getInstance().getConfig()); + } else { + return PlanBungee.getInstance().getIConfig().getConfig(); + } + } catch (IOException e) { + throw new IllegalStateException("Config could not be loaded.", e); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/api/IPlan.java b/Plan/src/main/java/com/djrapitops/plan/api/IPlan.java new file mode 100644 index 000000000..9649885de --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/api/IPlan.java @@ -0,0 +1,46 @@ +/* + * 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 main.java.com.djrapitops.plan.api; + +import com.djrapitops.plugin.IPlugin; +import com.djrapitops.plugin.config.IConfig; +import main.java.com.djrapitops.plan.ServerVariableHolder; +import main.java.com.djrapitops.plan.database.Database; +import main.java.com.djrapitops.plan.systems.info.InformationManager; +import main.java.com.djrapitops.plan.systems.info.server.ServerInfoManager; +import main.java.com.djrapitops.plan.systems.processing.Processor; +import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue; +import main.java.com.djrapitops.plan.systems.webserver.WebServer; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public interface IPlan extends IPlugin { + public Database getDB(); + + public ServerVariableHolder getVariable(); + + public ServerInfoManager getServerInfoManager(); + + public InformationManager getInfoManager(); + + public WebServer getWebServer(); + + public File getDataFolder(); + + public ProcessingQueue getProcessingQueue(); + + public void addToProcessQueue(Processor... processors); + + public InputStream getResource(String resource); + + public IConfig getIConfig() throws IOException; +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/bungee/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/bungee/PlanBungee.java new file mode 100644 index 000000000..1e947b269 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/bungee/PlanBungee.java @@ -0,0 +1,129 @@ +/* + * 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 main.java.com.djrapitops.plan.bungee; + +import com.djrapitops.plugin.BungeePlugin; +import com.djrapitops.plugin.settings.ColorScheme; +import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.ServerVariableHolder; +import main.java.com.djrapitops.plan.api.IPlan; +import main.java.com.djrapitops.plan.database.Database; +import main.java.com.djrapitops.plan.systems.info.InformationManager; +import main.java.com.djrapitops.plan.systems.info.server.ServerInfoManager; +import main.java.com.djrapitops.plan.systems.processing.Processor; +import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue; +import main.java.com.djrapitops.plan.systems.webserver.WebServer; +import main.java.com.djrapitops.plan.utilities.Benchmark; +import net.md_5.bungee.api.ChatColor; + +import java.io.InputStream; +import java.util.List; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class PlanBungee extends BungeePlugin implements IPlan { + + private WebServer webServer; + private Database db; + private ServerInfoManager serverInfoManager; + private InformationManager infoManager; + private ServerVariableHolder variableHolder; + + private ProcessingQueue processingQueue; + + public PlanBungee() { + } + + @Override + public void onEnable() { + super.setInstance(this); + + super.setColorScheme(new ColorScheme(ChatColor.GREEN, ChatColor.GRAY, ChatColor.WHITE)); + super.setLogPrefix("[Plan]"); + super.setUpdateCheckUrl("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml"); + super.setUpdateUrl("https://www.spigotmc.org/resources/plan-player-analytics.32536/"); + + super.copyDefaultConfig("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md"); + + super.onEnableDefaultTasks(); + + variableHolder = new ServerVariableHolder(getProxy()); + + Benchmark.start("WebServer Initialization"); + webServer = new WebServer(this); + webServer.initServer(); + + if (!webServer.isEnabled()) { + Log.error("WebServer was not successfully initialized."); + } + + serverInfoManager = new ServerInfoManager(this); + infoManager = new InformationManager(this); + webServer.setInfoManager(infoManager); + + Benchmark.stop("Enable", "WebServer Initialization"); + + processingQueue = new ProcessingQueue(); + } + + public static PlanBungee getInstance() { + return getInstance(PlanBungee.class); + } + + @Override + public void onDisable() { + List processors = processingQueue.stopAndReturnLeftovers(); + Log.info("Processing unprocessed processors. (" + processors.size() + ")"); + for (Processor processor : processors) { + processor.process(); + } + } + + @Override + public Database getDB() { + return db; + } + + @Override + public ServerInfoManager getServerInfoManager() { + return serverInfoManager; + } + + @Override + public InformationManager getInfoManager() { + return infoManager; + } + + @Override + public WebServer getWebServer() { + return webServer; + } + + + @Override + public ProcessingQueue getProcessingQueue() { + return processingQueue; + } + + @Override + public void addToProcessQueue(Processor... processors) { + for (Processor processor : processors) { + processingQueue.addToQueue(processor); + } + } + + @Override + public InputStream getResource(String resource) { + return getResourceAsStream(resource); + } + + @Override + public ServerVariableHolder getVariable() { + return variableHolder; + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java index 3a5b26a91..37da5a89e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java +++ b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java @@ -5,8 +5,8 @@ import com.djrapitops.plugin.settings.DefaultMessages; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Permissions; -import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; +import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.comparators.LocaleEntryComparator; import main.java.com.djrapitops.plan.utilities.comparators.StringLengthComparator; @@ -35,10 +35,10 @@ import java.util.stream.Collectors; */ public class Locale { - private final Plan plugin; + private final IPlan plugin; private final Map messages; - public Locale(Plan plugin) { + public Locale(IPlan plugin) { LocaleHolder.setLocale(this); this.plugin = plugin; messages = new EnumMap<>(Msg.class); @@ -98,7 +98,7 @@ public class Locale { .map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString()) .collect(Collectors.toList()); Files.write(new File(plugin.getDataFolder(), "locale.txt").toPath(), lines, StandardCharsets.UTF_8); - plugin.getConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false); + plugin.getIConfig().getConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false); } private String getSpacedIdentifier(String identifier, int length) { diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java index 4b7aa7f4c..1e9029378 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java @@ -6,6 +6,7 @@ package main.java.com.djrapitops.plan.systems.info; import com.djrapitops.plugin.command.ISender; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.bungee.PlanBungee; import main.java.com.djrapitops.plan.command.commands.AnalyzeCommand; import main.java.com.djrapitops.plan.data.AnalysisData; import main.java.com.djrapitops.plan.database.Database; @@ -27,14 +28,16 @@ import java.util.UUID; */ public class InformationManager { // TODO Class that manages ALL information for API, WebAPI requests, Command Caching etc. - private final Plan plugin; - private final Database db; + private Plan plugin; + private Database db; + + private DataCache dataCache; - private final DataCache dataCache; - private final Set analysisNotification; - private final Analysis analysis; private boolean usingBungeeWebServer; private String webServerAddress; + + private Set analysisNotification; + private Analysis analysis; private AnalysisData analysisData; private String analysisPluginsTab; private Long refreshDate; @@ -55,6 +58,10 @@ public class InformationManager { } } + public InformationManager(PlanBungee plugin) { + // TODO Init info manager. + } + public void attemptBungeeConnection() { // TODO WebAPI bungee connection check } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoFile.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoFile.java index 29319063d..14c4cb4be 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoFile.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoFile.java @@ -5,11 +5,10 @@ package main.java.com.djrapitops.plan.systems.info.server; import com.djrapitops.plugin.config.BukkitConfig; +import com.djrapitops.plugin.config.fileconfig.IFileConfig; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.FileConfigurationOptions; import java.io.IOException; import java.io.Serializable; @@ -26,13 +25,11 @@ import java.util.UUID; * * @author Rsl1122 */ -public class ServerInfoFile extends BukkitConfig { +public class ServerInfoFile extends BukkitConfig { public ServerInfoFile(Plan plugin) throws IOException, InvalidConfigurationException { super(plugin, "ServerInfoFile"); - FileConfiguration config = getConfig(); - FileConfigurationOptions options = config.options(); - options.copyDefaults(true); - options.header("IMPORTANT: Do not edit this file unless you want to lose your data!"); + IFileConfig config = super.getConfig(); + config.copyDefaults(); config.addDefault("Server.UUID", ""); config.addDefault("Bungee.WebAddress", ""); config.addDefault("Bungee.Fail", 0); @@ -40,7 +37,7 @@ public class ServerInfoFile extends BukkitConfig { } public void saveInfo(ServerInfo thisServer, ServerInfo bungee) throws IOException { - FileConfiguration config = getConfig(); + IFileConfig config = getConfig(); Map serverMap = new HashMap<>(); Map bungeeMap = new HashMap<>(); @@ -71,7 +68,7 @@ public class ServerInfoFile extends BukkitConfig { } public void markConnectionFail() throws IOException { - FileConfiguration config = getConfig(); + IFileConfig config = getConfig(); int fails = config.getInt("Bungee.Fail"); config.set("Bungee.Fail", fails + 1); save(); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoManager.java index 252150aa9..d69d05133 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/server/ServerInfoManager.java @@ -7,10 +7,12 @@ package main.java.com.djrapitops.plan.systems.info.server; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.ServerVariableHolder; import main.java.com.djrapitops.plan.Settings; +import main.java.com.djrapitops.plan.api.IPlan; +import main.java.com.djrapitops.plan.bungee.PlanBungee; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.tables.ServerTable; -import org.bukkit.Server; import org.bukkit.configuration.InvalidConfigurationException; import java.io.IOException; @@ -27,10 +29,10 @@ import java.util.UUID; */ public class ServerInfoManager { - private final Plan plugin; - private final ServerTable serverTable; + private final IPlan plugin; private ServerInfo serverInfo; private ServerInfoFile serverInfoFile; + private final ServerTable serverTable; public ServerInfoManager(Plan plugin) { this.plugin = plugin; @@ -60,6 +62,11 @@ public class ServerInfoManager { } } + public ServerInfoManager(PlanBungee plugin) { + this.plugin = plugin; + serverTable = plugin.getDB().getServerTable(); + } + private void updateDbInfo(UUID serverUUID) throws SQLException, IOException { Optional serverID = serverTable.getServerID(serverUUID); if (!serverID.isPresent()) { @@ -77,7 +84,7 @@ public class ServerInfoManager { } private void registerServer() throws SQLException, IOException { - registerServer(generateNewUUID(plugin.getServer())); + registerServer(generateNewUUID(plugin.getVariable())); } private void registerServer(UUID serverUUID) throws SQLException, IOException { @@ -96,8 +103,8 @@ public class ServerInfoManager { serverInfoFile.saveInfo(serverInfo, new ServerInfo(id, serverUUID, name, webAddress)); } - private UUID generateNewUUID(Server server) { - String seed = server.getName() + server.getIp() + server.getPort() + server.getVersion() + server.getBukkitVersion(); + private UUID generateNewUUID(ServerVariableHolder variableHolder) { + String seed = variableHolder.getName() + variableHolder.getIp() + variableHolder.getPort() + variableHolder.getVersion() + variableHolder.getImplVersion(); return UUID.nameUUIDFromBytes(seed.getBytes()); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java index ff30b9843..2561bc7f6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java @@ -5,6 +5,7 @@ import com.sun.net.httpserver.*; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; +import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.data.WebUser; import main.java.com.djrapitops.plan.database.tables.SecurityTable; import main.java.com.djrapitops.plan.locale.Locale; @@ -47,20 +48,20 @@ import java.util.zip.GZIPOutputStream; */ public class WebServer { - private final Plan plugin; - private final int port; + private final IPlan plugin; private InformationManager infoManager; + + private final int port; private boolean enabled = false; private HttpServer server; private boolean usingHttps = false; /** - * Class Constructor. * - * @param plugin Current instance of Plan + * @param plugin */ - public WebServer(Plan plugin) { + public WebServer(IPlan plugin) { this.plugin = plugin; this.port = Settings.WEBSERVER_PORT.getNumber(); @@ -410,7 +411,7 @@ public class WebServer { String page = args[1]; switch (page) { case "players": - return PageCache.loadPage("players", () -> new PlayersPageResponse(plugin)); + return PageCache.loadPage("players", PlayersPageResponse::new); case "player": return playerResponse(args); case "server": @@ -450,7 +451,7 @@ public class WebServer { case 0: return serverResponse(); case 1: - return PageCache.loadPage("players", () -> new PlayersPageResponse(plugin)); + return PageCache.loadPage("players", PlayersPageResponse::new); case 2: return playerResponse(new String[]{"", "", user.getName()}); default: diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/PlayersPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/PlayersPageResponse.java index f577e371d..e05aad6b1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/PlayersPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/PlayersPageResponse.java @@ -1,6 +1,5 @@ package main.java.com.djrapitops.plan.systems.webserver.response; -import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.UserInfo; import main.java.com.djrapitops.plan.utilities.comparators.UserDataNameComparator; import main.java.com.djrapitops.plan.utilities.html.Html; @@ -14,7 +13,7 @@ import java.util.List; */ public class PlayersPageResponse extends Response { - public PlayersPageResponse(Plan plugin) { + public PlayersPageResponse() { super.setHeader("HTTP/1.1 200 OK"); // super.setContent(buildContent(plugin.getInspectCache().getCachedUserData())); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 298a68d65..9320e62b8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -154,7 +154,7 @@ public class Analysis { PageCache.removeIf(identifier -> identifier.startsWith("inspectPage: ") || identifier.startsWith("inspectionJson: ")); PageCache.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getInfoManager())); PageCache.cachePage("analysisJson", () -> new JsonResponse(analysisData)); - PageCache.cachePage("players", () -> new PlayersPageResponse(plugin)); + PageCache.cachePage("players", PlayersPageResponse::new); // TODO Export // ExportUtility.export(analysisData, rawData); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java index 281a58215..5eb0967a1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java @@ -2,8 +2,8 @@ package main.java.com.djrapitops.plan.utilities.file; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.utilities.MiscUtils; -import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.FileNotFoundException; @@ -49,7 +49,7 @@ public class FileUtil { } } - public static List lines(JavaPlugin plugin, String resource) throws IOException { + public static List lines(IPlan plugin, String resource) throws IOException { List lines = new ArrayList<>(); Scanner scanner = null; try (InputStream inputStream = plugin.getResource(resource)) { diff --git a/Plan/src/main/resources/bungee.yml b/Plan/src/main/resources/bungee.yml new file mode 100644 index 000000000..289778854 --- /dev/null +++ b/Plan/src/main/resources/bungee.yml @@ -0,0 +1,4 @@ +name: Plan +author: Rsl1122 +main: main.java.com.djrapitops.plan.bungee.PlanBungee +version: 4.0.0 \ No newline at end of file diff --git a/Plan/test/test/java/utils/TestInit.java b/Plan/test/test/java/utils/TestInit.java index 6ac6a5c58..2ad32bfca 100644 --- a/Plan/test/test/java/utils/TestInit.java +++ b/Plan/test/test/java/utils/TestInit.java @@ -1,6 +1,8 @@ package test.java.utils; import com.djrapitops.plugin.StaticHolder; +import com.djrapitops.plugin.config.BukkitConfig; +import com.djrapitops.plugin.config.IConfig; import com.djrapitops.plugin.settings.ColorScheme; import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.IRunnable; @@ -81,12 +83,15 @@ public class TestInit { StaticHolder.setInstance(Plan.class, planMock); StaticHolder.setInstance(planMock.getClass(), planMock); - YamlConfiguration config = mockConfig(); - when(planMock.getConfig()).thenReturn(config); - File testFolder = getTestFolder(); when(planMock.getDataFolder()).thenReturn(testFolder); + YamlConfiguration config = mockConfig(); + when(planMock.getConfig()).thenReturn(config); + IConfig iConfig = new BukkitConfig(planMock, "config.yml"); + iConfig.copyFromStream(getClass().getResource("/config.yml").openStream()); + when(planMock.getIConfig()).thenReturn(iConfig); + // Html Files File analysis = new File(getClass().getResource("/server.html").getPath()); when(planMock.getResource("server.html")).thenReturn(new FileInputStream(analysis));