Merge pull request #478 from Rsl1122/RefactoringBranch

Pull request for 4.1.4
This commit is contained in:
Rsl1122 2017-12-16 14:11:02 +02:00 committed by GitHub
commit 1d5c162251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 992 additions and 440 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>Plan</artifactId>
<version>4.1.3</version>
<version>4.1.3.2</version>
<packaging>jar</packaging>
<repositories>
<repository>
@ -32,7 +32,7 @@
<dependency>
<groupId>com.djrapitops</groupId>
<artifactId>PlanPluginBridge</artifactId>
<version>4.1.3</version>
<version>4.1.3.2</version>
<scope>compile</scope>
</dependency>
<!-- Full PaperSpigot JAR -->

View File

@ -22,17 +22,13 @@ package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.BukkitPlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.Priority;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.systems.NotificationCenter;
import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.api.utility.Version;
import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.ITask;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.api.API;
import main.java.com.djrapitops.plan.api.IPlan;
@ -43,12 +39,14 @@ import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.settings.locale.Locale;
import main.java.com.djrapitops.plan.settings.locale.Msg;
import main.java.com.djrapitops.plan.settings.theme.PlanColorScheme;
import main.java.com.djrapitops.plan.settings.theme.Theme;
import main.java.com.djrapitops.plan.systems.DatabaseSystem;
import main.java.com.djrapitops.plan.systems.FileSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import main.java.com.djrapitops.plan.systems.file.database.DBSystem;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.info.ImporterManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
@ -57,13 +55,13 @@ import main.java.com.djrapitops.plan.systems.listeners.*;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.systems.processing.importing.importers.OfflinePlayerImporter;
import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue;
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.tasks.TaskSystem;
import main.java.com.djrapitops.plan.systems.update.VersionCheckSystem;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.utilities.file.export.HtmlExport;
import main.java.com.djrapitops.plan.utilities.metrics.BStats;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
@ -84,22 +82,15 @@ public class Plan extends BukkitPlugin implements IPlan {
private API api;
private Config config;
private Theme theme;
private Systems systems;
private ProcessingQueue processingQueue;
private HookHandler hookHandler; // Manages 3rd party data sources
private WebServer webServer;
private BukkitInformationManager infoManager;
private BukkitServerInfoManager serverInfoManager;
private ServerVariableHolder serverVariableHolder;
private TPSCountTimer tpsCountTimer;
private int bootAnalysisTaskID = -1;
/**
* Used to get the PlanAPI. @see API
@ -145,28 +136,11 @@ public class Plan extends BukkitPlugin implements IPlan {
try {
systems = new Systems(this);
FileSystem.getInstance().init();
config = new Config(FileSystem.getConfigFile());
config.copyDefaults(FileUtil.lines(this, "config.yml"));
config.save();
ConfigSystem.getInstance().init();
Log.setDebugMode(Settings.DEBUG.toString());
String currentVersion = getVersion();
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
try {
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
Log.infoColor("§a----------------------------------------");
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
Log.infoColor("§a----------------------------------------");
NotificationCenter.addNotification(Priority.HIGH, "New Version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
} else {
Log.info("You're using the latest version.");
}
} catch (IOException e) {
Log.error("Failed to check newest version number");
}
VersionCheckSystem.getInstance().init();
Benchmark.start("Enable");
@ -178,26 +152,23 @@ public class Plan extends BukkitPlugin implements IPlan {
throw new PlanEnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e);
}
new Locale(this).loadLocale();
new Locale().loadLocale();
theme = new Theme();
Theme.getInstance().init();
Benchmark.start("Reading server variables");
serverVariableHolder = new ServerVariableHolder(getServer());
Benchmark.stop("Enable", "Reading server variables");
DatabaseSystem.getInstance().init();
DBSystem.getInstance().init();
Benchmark.start("WebServer Initialization");
webServer = new WebServer(this);
processingQueue = new ProcessingQueue();
serverInfoManager = new BukkitServerInfoManager(this);
infoManager = new BukkitInformationManager(this);
webServer.initServer();
if (!webServer.isEnabled()) {
WebServerSystem.getInstance().init();
if (!WebServerSystem.isWebServerEnabled()) {
if (Settings.WEBSERVER_DISABLED.isTrue()) {
Log.warn("WebServer was not initialized. (WebServer.DisableWebServer: true)");
} else {
@ -206,6 +177,7 @@ public class Plan extends BukkitPlugin implements IPlan {
}
}
serverInfoManager.updateServerInfo();
infoManager.updateConnection();
Benchmark.stop("Enable", "WebServer Initialization");
@ -213,7 +185,8 @@ public class Plan extends BukkitPlugin implements IPlan {
registerListeners();
}
PlanPlayerListener.setCountKicks(true);
registerTasks();
TaskSystem.getInstance().init();
this.api = new API(this);
@ -254,62 +227,9 @@ public class Plan extends BukkitPlugin implements IPlan {
}
}
private void registerTasks() {
String bootAnalysisMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_INFO).toString();
String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString();
Benchmark.start("Task Registration");
tpsCountTimer = new TPSCountTimer(this);
RunnableFactory.createNew(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
// Analysis refresh settings
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
long analysisPeriod = analysisRefreshMinutes * TimeAmount.MINUTE.ticks();
Log.info(bootAnalysisMsg);
ITask bootAnalysisTask = RunnableFactory.createNew("BootAnalysisTask", new AbsRunnable() {
@Override
public void run() {
Log.info(bootAnalysisRunMsg);
infoManager.refreshAnalysis(getServerUUID());
this.cancel();
}
}).runTaskLaterAsynchronously(30 * TimeAmount.SECOND.ticks());
bootAnalysisTaskID = bootAnalysisTask.getTaskId();
if (analysisRefreshTaskIsEnabled) {
RunnableFactory.createNew("PeriodicalAnalysisTask", new AbsRunnable() {
@Override
public void run() {
infoManager.refreshAnalysis(getServerUUID());
}
}).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
}
RunnableFactory.createNew("PeriodicNetworkBoxRefreshTask", new AbsRunnable() {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(TimeAmount.SECOND.ticks(), TimeAmount.MINUTE.ticks() * 5L);
Benchmark.stop("Enable", "Task Registration");
}
@Override
public ColorScheme getColorScheme() {
try {
ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.toString().charAt(1));
ChatColor secColor = ChatColor.getByChar(Settings.COLOR_SEC.toString().charAt(1));
ChatColor terColor = ChatColor.getByChar(Settings.COLOR_TER.toString().charAt(1));
return new ColorScheme(mainColor, secColor, terColor);
} catch (Exception e) {
Log.infoColor(ChatColor.RED + "Customization, Chat colors set-up wrong, using defaults.");
return new ColorScheme(ChatColor.DARK_GREEN, ChatColor.GRAY, ChatColor.WHITE);
}
return PlanColorScheme.create();
}
/**
@ -320,11 +240,6 @@ public class Plan extends BukkitPlugin implements IPlan {
//Clears the page cache
PageCache.clearCache();
// Stop the UI Server
if (webServer != null) {
webServer.stop();
}
// Processes unprocessed processors
if (processingQueue != null) {
List<Processor> processors = processingQueue.stopAndReturnLeftovers();
@ -359,11 +274,7 @@ public class Plan extends BukkitPlugin implements IPlan {
@Override
public void onReload() {
try {
config.read();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
ConfigSystem.reload();
}
private void registerListeners() {
@ -393,7 +304,7 @@ public class Plan extends BukkitPlugin implements IPlan {
*/
@Deprecated
public Database getDB() {
return DatabaseSystem.getInstance().getActiveDatabase();
return DBSystem.getInstance().getActiveDatabase();
}
/**
@ -402,7 +313,7 @@ public class Plan extends BukkitPlugin implements IPlan {
* @return the WebServer
*/
public WebServer getWebServer() {
return webServer;
return WebServerSystem.getInstance().getWebServer();
}
/**
@ -414,15 +325,6 @@ public class Plan extends BukkitPlugin implements IPlan {
return hookHandler;
}
/**
* Used to get the ID of the BootAnalysisTask, so that it can be disabled.
*
* @return ID of the bootAnalysisTask
*/
public int getBootAnalysisTaskID() {
return bootAnalysisTaskID;
}
/**
* Used to get the object storing server variables that are constant after
* boot.
@ -448,10 +350,6 @@ public class Plan extends BukkitPlugin implements IPlan {
return processingQueue;
}
public TPSCountTimer getTpsCountTimer() {
return tpsCountTimer;
}
public void addToProcessQueue(Processor... processors) {
if (!reloading) {
for (Processor processor : processors) {
@ -473,7 +371,7 @@ public class Plan extends BukkitPlugin implements IPlan {
@Override
public Config getMainConfig() {
return config;
return ConfigSystem.getInstance().getConfig();
}
public InformationManager getInfoManager() {
@ -534,11 +432,6 @@ public class Plan extends BukkitPlugin implements IPlan {
return api;
}
@Override
public Theme getTheme() {
return theme;
}
public Systems getSystems() {
return systems;
}

View File

@ -7,14 +7,11 @@ package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.Priority;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.systems.NotificationCenter;
import com.djrapitops.plugin.api.utility.Version;
import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.command.PlanBungeeCommand;
@ -22,23 +19,24 @@ import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.settings.locale.Locale;
import main.java.com.djrapitops.plan.settings.locale.Msg;
import main.java.com.djrapitops.plan.settings.theme.PlanColorScheme;
import main.java.com.djrapitops.plan.settings.theme.Theme;
import main.java.com.djrapitops.plan.systems.DatabaseSystem;
import main.java.com.djrapitops.plan.systems.FileSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import main.java.com.djrapitops.plan.systems.file.database.DBSystem;
import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
import main.java.com.djrapitops.plan.systems.listeners.BungeePlayerListener;
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.tasks.TPSCountTimer;
import main.java.com.djrapitops.plan.systems.tasks.TaskSystem;
import main.java.com.djrapitops.plan.systems.update.VersionCheckSystem;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.utilities.file.export.HtmlExport;
import net.md_5.bungee.api.ChatColor;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
@ -49,55 +47,34 @@ import java.util.UUID;
*/
public class PlanBungee extends BungeePlugin implements IPlan {
private Config config;
private Theme theme;
private Systems systems;
private WebServer webServer;
private BungeeServerInfoManager serverInfoManager;
private BungeeInformationManager infoManager;
private ServerVariableHolder variableHolder;
private ProcessingQueue processingQueue;
private boolean setupAllowed = false;
@Override
public void onEnable() {
super.onEnable();
try {
systems = new Systems(this);
FileSystem.getInstance().init();
config = new Config(FileSystem.getConfigFile());
config.copyDefaults(FileUtil.lines(this, "bungeeconfig.yml"));
config.save();
ConfigSystem.getInstance().init();
Log.setDebugMode(Settings.DEBUG.toString());
String currentVersion = getVersion();
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
try {
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
Log.infoColor("§a----------------------------------------");
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
Log.infoColor("§a----------------------------------------");
NotificationCenter.addNotification(Priority.HIGH, "New Version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
} else {
Log.info("You're using the latest version.");
}
} catch (IOException e) {
Log.error("Failed to check newest version number");
}
VersionCheckSystem.getInstance().init();
variableHolder = new ServerVariableHolder(getProxy());
new Locale(this).loadLocale();
new Locale().loadLocale();
theme = new Theme();
DatabaseSystem.getInstance().init();
registerCommand("planbungee", new PlanBungeeCommand(this));
Theme.getInstance().init();
DBSystem.getInstance().init();
String ip = variableHolder.getIp();
if ("0.0.0.0".equals(ip)) {
@ -107,35 +84,14 @@ public class PlanBungee extends BungeePlugin implements IPlan {
}
Benchmark.start("WebServer Initialization");
webServer = new WebServer(this);
serverInfoManager = new BungeeServerInfoManager(this);
infoManager = new BungeeInformationManager(this);
webServer.initServer();
WebServerSystem.getInstance().init();
serverInfoManager.loadServerInfo();
if (!webServer.isEnabled()) {
Log.error("WebServer was not successfully initialized.");
onDisable();
return;
}
RunnableFactory.createNew("Enable Bukkit Connection Task", new AbsRunnable() {
@Override
public void run() {
infoManager.attemptConnection();
infoManager.sendConfigSettings();
}
}).runTaskAsynchronously();
RunnableFactory.createNew("Player Count task", new TPSCountTimer(this))
.runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
RunnableFactory.createNew("NetworkPageContentUpdateTask", new AbsRunnable("NetworkPageContentUpdateTask") {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
TaskSystem.getInstance().init();
processingQueue = new ProcessingQueue();
@ -149,8 +105,8 @@ public class PlanBungee extends BungeePlugin implements IPlan {
} catch (Exception e) {
Log.error("Plugin Failed to Initialize Correctly.");
Log.toLog(this.getClass().getName(), e);
onDisable();
}
registerCommand("planbungee", new PlanBungeeCommand(this));
}
public static PlanBungee getInstance() {
@ -166,12 +122,11 @@ public class PlanBungee extends BungeePlugin implements IPlan {
/*ignored*/
}
}
if (webServer != null) {
webServer.stop();
}
systems.close();
Log.info(Locale.get(Msg.DISABLED).toString());
super.onDisable();
Benchmark.pluginDisabled(PlanBungee.class);
DebugLog.pluginDisabled(PlanBungee.class);
TaskCenter.cancelAllKnownTasks(PlanBungee.class);
}
@Override
@ -181,17 +136,13 @@ public class PlanBungee extends BungeePlugin implements IPlan {
@Override
public void onReload() {
try {
config.read();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
ConfigSystem.reload();
}
@Override
@Deprecated
public Database getDB() {
return DatabaseSystem.getInstance().getActiveDatabase();
return DBSystem.getInstance().getActiveDatabase();
}
public BungeeServerInfoManager getServerInfoManager() {
@ -205,7 +156,7 @@ public class PlanBungee extends BungeePlugin implements IPlan {
@Override
public WebServer getWebServer() {
return webServer;
return WebServerSystem.getInstance().getWebServer();
}
@ -228,20 +179,12 @@ public class PlanBungee extends BungeePlugin implements IPlan {
@Override
public Config getMainConfig() {
return config;
return ConfigSystem.getInstance().getConfig();
}
@Override
public ColorScheme getColorScheme() {
try {
ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.toString().charAt(1));
ChatColor secColor = ChatColor.getByChar(Settings.COLOR_SEC.toString().charAt(1));
ChatColor terColor = ChatColor.getByChar(Settings.COLOR_TER.toString().charAt(1));
return new ColorScheme(mainColor, secColor, terColor);
} catch (Exception e) {
Log.infoColor(ChatColor.RED + "Customization, Chat colors set-up wrong, using defaults.");
return new ColorScheme(ChatColor.DARK_GREEN, ChatColor.GRAY, ChatColor.WHITE);
}
return PlanColorScheme.create();
}
@Override
@ -257,13 +200,16 @@ public class PlanBungee extends BungeePlugin implements IPlan {
return serverInfoManager.getServerUUID();
}
@Override
public Theme getTheme() {
return theme;
}
@Override
public Systems getSystems() {
return systems;
}
public boolean isSetupAllowed() {
return setupAllowed;
}
public void setSetupAllowed(boolean setupAllowed) {
this.setupAllowed = setupAllowed;
}
}

View File

@ -9,7 +9,6 @@ import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.settings.ColorScheme;
import main.java.com.djrapitops.plan.ServerVariableHolder;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.settings.theme.Theme;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.processing.Processor;
@ -48,7 +47,5 @@ public interface IPlan extends IPlugin {
ColorScheme getColorScheme();
Theme getTheme();
Systems getSystems();
}

View File

@ -27,7 +27,7 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
* @param plugin Current instance of Plan
*/
public PlanBungeeCommand(PlanBungee plugin) {
super(plugin, "planbungee", CommandType.CONSOLE, "", "", "planbungee");
super(plugin, "planbungee", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), "", "planbungee");
super.setDefaultCommand("help");
super.setColorScheme(plugin.getColorScheme());
}
@ -42,7 +42,8 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
add(
new ReloadCommand(plugin),
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
new ListCommand()
new ListCommand(),
new BungeeSetupToggleCommand(plugin)
);
RegisterCommand registerCommand = new RegisterCommand(plugin);
add(

View File

@ -131,10 +131,6 @@ public class AnalyzeCommand extends SubCommand {
}
private void updateCache(ISender sender, UUID serverUUID) {
int bootAnID = plugin.getBootAnalysisTaskID();
if (bootAnID != -1) {
plugin.getServer().getScheduler().cancelTask(bootAnID);
}
infoManager.addAnalysisNotification(sender, serverUUID);
infoManager.refreshAnalysis(serverUUID);
}

View File

@ -0,0 +1,39 @@
/*
* 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.command.commands;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.settings.Permissions;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class BungeeSetupToggleCommand extends SubCommand {
private final PlanBungee plugin;
public BungeeSetupToggleCommand(PlanBungee plugin) {
super("setup", CommandType.ALL, Permissions.MANAGE.getPermission(), "Toggle Setup mode for Bungee");
this.plugin = plugin;
}
@Override
public boolean onCommand(ISender sender, String s, String[] strings) {
boolean setupAllowed = plugin.isSetupAllowed();
if (setupAllowed) {
plugin.setSetupAllowed(false);
} else {
plugin.setSetupAllowed(true);
}
String msg = !setupAllowed ? "§aSet-up is now Allowed" : "§cSet-up is now Forbidden";
sender.sendMessage(msg);
return true;
}
}

View File

@ -63,16 +63,22 @@ public class RegisterCommandFilter extends AbstractFilter {
}
private Result validateMessage(String message) {
return isSensibleCommand(message)
if (message == null) {
return Result.NEUTRAL;
}
return commandShouldBeCensored(message)
? Result.DENY
: Result.NEUTRAL;
}
private boolean isSensibleCommand(String message) {
return message.toLowerCase().contains("issued server command:") && isSensible(message);
private boolean commandShouldBeCensored(String message) {
return message != null
&& (message.toLowerCase().contains("issued server command:")
&& shouldBeCensored(message));
}
private boolean isSensible(String message) {
return censoredCommands.stream().anyMatch(message::contains);
private boolean shouldBeCensored(String message) {
return message != null && censoredCommands.stream().anyMatch(message::contains);
}
}

View File

@ -38,10 +38,8 @@ public class ReloadCommand extends SubCommand {
try {
plugin.reloadPlugin(true);
} catch (Exception e) {
sender.sendMessage("§cSomething went wrong during reload of the plugin, a restart is recommended.");
String address = plugin.getWebServer().getAccessAddress() + "/debug";
sender.sendLink("More info can be found at ", address, address);
Log.toLog(this.getClass().getName(), e);
sender.sendMessage("§cSomething went wrong during reload of the plugin, a restart is recommended.");
}
sender.sendMessage(Locale.get(Msg.CMD_INFO_RELOAD_COMPLETE).toString());
return true;

View File

@ -7,6 +7,7 @@ import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIForbiddenException;
import main.java.com.djrapitops.plan.settings.Permissions;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.settings.locale.Locale;
@ -70,6 +71,8 @@ public class ManageSetupCommand extends SubCommand {
// 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.");
} catch (WebAPIForbiddenException e) {
sender.sendMessage("§eConnection succeeded, but Bungee has set-up mode disabled - use '/planbungee setup' to enable it.");
} catch (WebAPIException e) {
Log.toLog(this.getClass().getName(), e);
sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console");

View File

@ -69,7 +69,7 @@ public class AnalysisData extends RawData {
addValue("version", MiscUtils.getIPlan().getVersion());
addValue("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
addValue("gmPieColors", Theme.getValue(ThemeVal.GRAPH_GM_PIE));
addValue("serverName", Settings.SERVER_NAME.toString());
addValue("serverName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
addValue("refresh", FormatUtils.formatTimeStamp(refreshDate));

View File

@ -18,7 +18,7 @@ import java.util.List;
public class HookHandler {
private final List<PluginData> additionalDataSources;
private final PluginConfigSectionHandler configHandler;
private final PluginsConfigSection configHandler;
/**
* Class constructor, hooks to plugins.
@ -27,7 +27,7 @@ public class HookHandler {
*/
public HookHandler(Plan plugin) {
additionalDataSources = new ArrayList<>();
configHandler = new PluginConfigSectionHandler(plugin);
configHandler = new PluginsConfigSection();
try {
Bridge.hook(this);
} catch (Exception e) {

View File

@ -2,7 +2,7 @@ package main.java.com.djrapitops.plan.data.plugin;
import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import java.io.IOException;
@ -13,25 +13,17 @@ import java.io.IOException;
* @author Rsl1122
* @since 3.5.0
*/
public class PluginConfigSectionHandler {
private final Plan plan;
public PluginConfigSectionHandler(Plan plan) {
this.plan = plan;
}
public class PluginsConfigSection {
public boolean hasSection(PluginData dataSource) {
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.getChildren().containsKey(pluginName)) {
return false;
}
return section.getConfigNode(pluginName).getChildren().containsKey("Enabled");
return section.getChildren().containsKey(pluginName)
&& section.getConfigNode(pluginName).getChildren().containsKey("Enabled");
}
private ConfigNode getPluginsSection() {
return plan.getMainConfig().getConfigNode("Plugins");
return ConfigSystem.getInstance().getConfig().getConfigNode("Plugins");
}
public void createSection(PluginData dataSource) {

View File

@ -71,7 +71,6 @@ public abstract class SQLDB extends Database {
try {
setupDataSource();
setupDatabase();
scheduleClean(10L);
open = true;
} finally {
Benchmark.stop("Database", benchName);

View File

@ -2,7 +2,7 @@ package main.java.com.djrapitops.plan.settings;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.config.Config;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import java.util.List;
@ -154,7 +154,7 @@ public enum Settings {
}
private Config getConfig() {
return MiscUtils.getIPlan().getMainConfig();
return ConfigSystem.getInstance().getConfig();
}
public static ServerSpecificSettings serverSpecific() {

View File

@ -8,7 +8,7 @@ import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import java.io.IOException;
import java.util.HashMap;
@ -21,17 +21,6 @@ import java.util.Map;
*/
public class WorldAliasSettings {
private final Plan plugin;
/**
* Constructor.
*
* @param plugin Current instance of Plan.
*/
public WorldAliasSettings(Plan plugin) {
this.plugin = plugin;
}
/**
* Used to get all World aliases in the config
*
@ -48,7 +37,7 @@ public class WorldAliasSettings {
}
private ConfigNode getAliasSection() {
Config config = plugin.getMainConfig();
Config config = ConfigSystem.getInstance().getConfig();
return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
}

View File

@ -1,13 +1,16 @@
package main.java.com.djrapitops.plan.settings.locale;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.DefaultMessages;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.settings.Permissions;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.comparators.LocaleEntryComparator;
import main.java.com.djrapitops.plan.utilities.comparators.StringLengthComparator;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
@ -34,12 +37,10 @@ import java.util.stream.Collectors;
*/
public class Locale {
private final IPlan plugin;
private final Map<Msg, Message> messages;
public Locale(IPlan plugin) {
public Locale() {
LocaleHolder.setLocale(this);
this.plugin = plugin;
messages = new EnumMap<>(Msg.class);
}
@ -67,7 +68,7 @@ public class Locale {
if (Settings.WRITE_NEW_LOCALE.isTrue()) {
writeNewDefaultLocale();
}
File localeFile = new File(plugin.getDataFolder(), "locale.txt");
File localeFile = FileSystem.getLocaleFile();
if (localeFile.exists()) {
loadFromFile(localeFile);
} else if (locale.equals("DEFAULT")) {
@ -83,7 +84,6 @@ public class Locale {
}
private void writeNewDefaultLocale() throws IOException {
Optional<String> key = messages.keySet().stream()
.map(Msg::getIdentifier)
.sorted(new StringLengthComparator())
@ -96,9 +96,11 @@ public class Locale {
.sorted(new LocaleEntryComparator())
.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.getMainConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false);
plugin.getMainConfig().save();
Files.write(FileSystem.getLocaleFile().toPath(), lines, StandardCharsets.UTF_8);
Config config = ConfigSystem.getInstance().getConfig();
config.set(Settings.WRITE_NEW_LOCALE.getPath(), false);
config.save();
}
private String getSpacedIdentifier(String identifier, int length) {
@ -110,13 +112,15 @@ public class Locale {
}
private void loadDefault() {
// TODO Move to Msg as DefaultMessages
String analysis = "Analysis | ";
String prefix = "[Plan] ";
String green = "§a";
String yellow = "§e";
String red = "§c";
String arrowsRight = DefaultMessages.ARROWS_RIGHT.parse();
ColorScheme cs = plugin.getColorScheme();
ColorScheme cs = MiscUtils.getIPlan().getColorScheme();
String mCol = cs.getMainColor();
String sCol = cs.getSecondaryColor();
String tCol = cs.getTertiaryColor();
@ -310,7 +314,7 @@ public class Locale {
private void loadFromResource(String fileName) {
try {
loadFromContents(FileUtil.lines(plugin, fileName), fileName);
loadFromContents(FileSystem.readFromResource(fileName), fileName);
} catch (FileNotFoundException e) {
Log.error("Could not find file inside the jar: " + fileName);
Log.info("Using Locale: Default (EN)");

View File

@ -0,0 +1,35 @@
/*
* 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.settings.theme;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import main.java.com.djrapitops.plan.settings.Settings;
/**
* ColorScheme that uses values in config settings specific to Plan or PlanBungee.
*
* @author Rsl1122
*/
public class PlanColorScheme extends ColorScheme {
private PlanColorScheme(String... colors) {
super(colors);
}
public static PlanColorScheme create() {
try {
String main = "§" + Settings.COLOR_MAIN.toString().charAt(1);
String secondary = "§" + Settings.COLOR_SEC.toString().charAt(1);
String tertiary = "§" + Settings.COLOR_TER.toString().charAt(1);
return new PlanColorScheme(main, secondary, tertiary);
} catch (Exception e) {
Log.infoColor("§cCustomization, Chat colors set-up wrong, using defaults.");
return new PlanColorScheme("§2", "§7", "§f");
}
}
}

View File

@ -9,7 +9,8 @@ import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import java.io.IOException;
import java.util.List;
@ -21,11 +22,16 @@ import java.util.List;
*
* @author Rsl1122
*/
public class Theme {
public class Theme implements SubSystem {
private final ThemeConfig config;
private ThemeConfig config;
public Theme() throws PlanEnableException {
public static Theme getInstance() {
return Systems.getInstance().getThemeSystem();
}
@Override
public void init() throws PlanEnableException {
String themeName = Settings.THEME_BASE.toString();
try {
config = new ThemeConfig(themeName);
@ -34,6 +40,11 @@ public class Theme {
}
}
@Override
public void close() {
}
public String getColor(ThemeVal variable) {
String path = variable.getThemePath();
try {
@ -83,10 +94,10 @@ public class Theme {
}
public static String getValue(ThemeVal variable) {
return MiscUtils.getIPlan().getTheme().getThemeValue(variable);
return getInstance().getThemeValue(variable);
}
public static String replaceColors(String resourceString) {
return MiscUtils.getIPlan().getTheme().replaceThemeColors(resourceString);
return getInstance().replaceThemeColors(resourceString);
}
}

View File

@ -4,7 +4,22 @@
*/
package main.java.com.djrapitops.plan.systems;
import main.java.com.djrapitops.plan.api.IPlan;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.settings.theme.Theme;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import main.java.com.djrapitops.plan.systems.file.config.PlanBungeeConfigSystem;
import main.java.com.djrapitops.plan.systems.file.config.PlanConfigSystem;
import main.java.com.djrapitops.plan.systems.file.database.DBSystem;
import main.java.com.djrapitops.plan.systems.file.database.PlanBungeeDBSystem;
import main.java.com.djrapitops.plan.systems.file.database.PlanDBSystem;
import main.java.com.djrapitops.plan.systems.tasks.PlanBungeeTaskSystem;
import main.java.com.djrapitops.plan.systems.tasks.PlanTaskSystem;
import main.java.com.djrapitops.plan.systems.tasks.TaskSystem;
import main.java.com.djrapitops.plan.systems.update.VersionCheckSystem;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.apache.commons.lang3.ArrayUtils;
@ -15,18 +30,60 @@ import org.apache.commons.lang3.ArrayUtils;
*/
public class Systems {
FileSystem fileSystem;
DatabaseSystem databaseSystem;
private FileSystem fileSystem;
private ConfigSystem configSystem;
private DBSystem databaseSystem;
private Theme themeSystem;
public Systems(IPlan plugin) {
databaseSystem = new DatabaseSystem();
private WebServerSystem webServerSystem;
private TaskSystem taskSystem;
private VersionCheckSystem versionCheckSystem;
/**
* Constructor for Bukkit version.
*
* @param plugin Plan instance
*/
public Systems(Plan plugin) {
fileSystem = new FileSystem(plugin);
configSystem = new PlanConfigSystem();
databaseSystem = new PlanDBSystem();
versionCheckSystem = new VersionCheckSystem(plugin.getVersion());
taskSystem = new PlanTaskSystem();
webServerSystem = new WebServerSystem();
themeSystem = new Theme();
}
/**
* Constructor for Bungee version.
*
* @param plugin PlanBungee instance
*/
public Systems(PlanBungee plugin) {
fileSystem = new FileSystem(plugin);
configSystem = new PlanBungeeConfigSystem();
databaseSystem = new PlanBungeeDBSystem();
versionCheckSystem = new VersionCheckSystem(plugin.getVersion());
taskSystem = new PlanBungeeTaskSystem();
webServerSystem = new WebServerSystem();
themeSystem = new Theme();
}
private SubSystem[] getSubSystems() {
return new SubSystem[]{
fileSystem,
configSystem,
versionCheckSystem,
databaseSystem,
fileSystem
taskSystem,
webServerSystem,
themeSystem
};
}
@ -34,11 +91,43 @@ public class Systems {
SubSystem[] subSystems = getSubSystems();
ArrayUtils.reverse(subSystems);
for (SubSystem subSystem : subSystems) {
subSystem.close();
try {
subSystem.close();
} catch (Exception e) {
Log.toLog(Systems.class, e);
}
}
}
public static Systems getInstance() {
return MiscUtils.getIPlan().getSystems();
}
public FileSystem getFileSystem() {
return fileSystem;
}
public DBSystem getDatabaseSystem() {
return databaseSystem;
}
public ConfigSystem getConfigSystem() {
return configSystem;
}
public WebServerSystem getWebServerSystem() {
return webServerSystem;
}
public VersionCheckSystem getVersionCheckSystem() {
return versionCheckSystem;
}
public Theme getThemeSystem() {
return themeSystem;
}
public TaskSystem getTaskSystem() {
return taskSystem;
}
}

View File

@ -2,12 +2,18 @@
* 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.systems;
package main.java.com.djrapitops.plan.systems.file;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* //TODO Class Javadoc Comment
@ -20,11 +26,15 @@ public class FileSystem implements SubSystem {
private File configFile;
public FileSystem(IPlan plugin) {
dataFolder = plugin.getDataFolder();
this(plugin.getDataFolder());
}
public FileSystem(File dataFolder) {
this.dataFolder = dataFolder;
}
public static FileSystem getInstance() {
return Systems.getInstance().fileSystem;
return Systems.getInstance().getFileSystem();
}
public static File getDataFolder() {
@ -35,6 +45,14 @@ public class FileSystem implements SubSystem {
return getInstance().configFile;
}
public static File getLocaleFile() {
return new File(getInstance().dataFolder, "locale.txt");
}
public static List<String> readFromResource(String fileName) throws IOException {
return FileUtil.lines(MiscUtils.getIPlan(), fileName);
}
@Override
public void init() throws PlanEnableException {
dataFolder.mkdirs();

View File

@ -0,0 +1,58 @@
/*
* 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.systems.file.config;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import java.io.IOException;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public abstract class ConfigSystem implements SubSystem {
protected Config config;
public static ConfigSystem getInstance() {
return Systems.getInstance().getConfigSystem();
}
public Config getConfig() {
return config;
}
@Override
public void init() throws PlanEnableException {
try {
config = new Config(FileSystem.getConfigFile());
copyDefaults();
config.save();
} catch (IOException e) {
throw new PlanEnableException("Config Subsystem failed to initialize", e);
}
}
protected abstract void copyDefaults() throws IOException;
@Override
public void close() {
}
public static void reload() {
try {
getInstance().config.read();
} catch (IOException e) {
Log.toLog(ConfigSystem.class, 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 main.java.com.djrapitops.plan.systems.file.config;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import java.io.IOException;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PlanBungeeConfigSystem extends ConfigSystem {
@Override
protected void copyDefaults() throws IOException {
config.copyDefaults(FileSystem.readFromResource("bungeeconfig.yml"));
}
}

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 main.java.com.djrapitops.plan.systems.file.config;
import main.java.com.djrapitops.plan.systems.file.FileSystem;
import java.io.IOException;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PlanConfigSystem extends ConfigSystem {
@Override
protected void copyDefaults() throws IOException {
config.copyDefaults(FileSystem.readFromResource("config.yml"));
}
}

View File

@ -2,20 +2,19 @@
* 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.systems;
package main.java.com.djrapitops.plan.systems.file.database;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.settings.locale.Locale;
import main.java.com.djrapitops.plan.settings.locale.Msg;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import java.sql.SQLException;
import java.util.HashSet;
@ -26,10 +25,18 @@ import java.util.Set;
*
* @author Rsl1122
*/
public class DatabaseSystem implements SubSystem {
public abstract class DBSystem implements SubSystem {
private Database db;
private Set<Database> databases;
protected SQLDB db;
protected Set<SQLDB> databases;
public DBSystem() {
databases = new HashSet<>();
}
public static DBSystem getInstance() {
return Systems.getInstance().getDatabaseSystem();
}
@Override
public void init() throws PlanEnableException {
@ -37,38 +44,21 @@ public class DatabaseSystem implements SubSystem {
Benchmark.start("Init Database");
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
initDatabase();
db.scheduleClean(10L);
Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName()));
Benchmark.stop("Systems", "Init Database");
} catch (DatabaseInitException e) {
throw new PlanEnableException(db.getConfigName() + "-Database failed to initialize", e);
throw new PlanEnableException(db.getName() + "-Database failed to initialize", e);
}
}
private void initDatabase() throws DatabaseInitException {
if (Check.isBungeeAvailable()) {
db = new MySQLDB();
} else {
// Enables database on Bukkit
// Bukkit supports SQLite.
initPlanDatabase();
}
db.init();
}
protected abstract void initDatabase() throws DatabaseInitException;
private void initPlanDatabase() throws DatabaseInitException {
databases = new HashSet<>();
databases.add(new MySQLDB());
databases.add(new SQLiteDB());
String dbType = Settings.DB_TYPE.toString().toLowerCase().trim();
db = getActiveDatabase(dbType);
}
public Set<Database> getDatabases() {
public Set<SQLDB> getDatabases() {
return databases;
}
public void setDatabases(Set<Database> databases) {
public void setDatabases(Set<SQLDB> databases) {
this.databases = databases;
}
@ -83,16 +73,12 @@ public class DatabaseSystem implements SubSystem {
}
}
public static DatabaseSystem getInstance() {
return Systems.getInstance().databaseSystem;
}
public Database getActiveDatabase() {
return db;
}
public static Database getActiveDatabase(String dbName) throws DatabaseInitException {
for (Database database : DatabaseSystem.getInstance().getDatabases()) {
public static SQLDB getActiveDatabase(String dbName) throws DatabaseInitException {
for (SQLDB database : DBSystem.getInstance().getDatabases()) {
String dbConfigName = database.getConfigName();
if (Verify.equalsIgnoreCase(dbName, dbConfigName)) {
database.init();

View File

@ -0,0 +1,24 @@
/*
* 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.systems.file.database;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PlanBungeeDBSystem extends DBSystem {
@Override
protected void initDatabase() throws DatabaseInitException {
db = new MySQLDB();
databases.add(db);
db.init();
}
}

View File

@ -0,0 +1,28 @@
/*
* 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.systems.file.database;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.settings.Settings;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PlanDBSystem extends DBSystem {
@Override
protected void initDatabase() throws DatabaseInitException {
databases.add(new MySQLDB());
databases.add(new SQLiteDB());
String dbType = Settings.DB_TYPE.toString().toLowerCase().trim();
db = getActiveDatabase(dbType);
db.init();
}
}

View File

@ -19,8 +19,10 @@ import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.info.parsing.AnalysisPageParser;
import main.java.com.djrapitops.plan.systems.info.parsing.InspectPageParser;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
@ -62,8 +64,7 @@ public class BukkitInformationManager extends InformationManager {
dataCache = new DataCache(plugin);
analysis = new Analysis(plugin);
pluginsTabContents = new HashMap<>();
updateConnection();
usingAnotherWebServer = false;
}
public void updateConnection() {
@ -114,7 +115,7 @@ public class BukkitInformationManager extends InformationManager {
}
}
} else {
PageCache.cachePage("inspectPage: " + uuid, () -> {
PageCache.cachePage(PageId.PLAYER.of(uuid), () -> {
try {
return new InspectPageResponse(this, uuid);
} catch (ParseException e) {
@ -154,7 +155,6 @@ public class BukkitInformationManager extends InformationManager {
cacheInspectPluginsTab(uuid, origin);
}
} else {
String serverName = plugin.getServerInfoManager().getServerName();
HookHandler hookHandler = plugin.getHookHandler();
List<PluginData> plugins = hookHandler.getAdditionalDataSources();
Map<PluginData, InspectContainer> containers = new HashMap<>();
@ -188,7 +188,7 @@ public class BukkitInformationManager extends InformationManager {
}
} else {
pluginsTabContents.put(uuid, contents);
Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
Response inspectResponse = PageCache.loadPage(PageId.PLAYER.of(uuid));
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(contents);
}
@ -231,7 +231,7 @@ public class BukkitInformationManager extends InformationManager {
return isAnalysisCached(serverUUID);
}
}
return PageCache.isCached("analysisPage:" + serverUUID);
return PageCache.isCached(PageId.SERVER.of(serverUUID));
}
private WebAPIManager getWebAPI() {
@ -306,7 +306,7 @@ public class BukkitInformationManager extends InformationManager {
}
} else {
UUID serverUUID = Plan.getServerUUID();
PageCache.cachePage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(html));
PageCache.cachePage(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(html));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportServer(plugin, serverUUID);
}
@ -323,8 +323,7 @@ public class BukkitInformationManager extends InformationManager {
@Override
public boolean attemptConnection() {
WebServer webServer = plugin.getWebServer();
boolean webServerIsEnabled = webServer.isEnabled();
boolean webServerIsEnabled = WebServerSystem.isWebServerEnabled();
boolean previousState = usingAnotherWebServer;
try {
@ -350,6 +349,7 @@ public class BukkitInformationManager extends InformationManager {
} finally {
boolean changedState = previousState != usingAnotherWebServer;
if (webServerIsEnabled && changedState) {
WebServer webServer = WebServerSystem.getInstance().getWebServer();
webServer.stop();
webServer.initServer();
}

View File

@ -16,7 +16,8 @@ import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.info.parsing.NetworkPageParser;
import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
@ -233,11 +234,7 @@ public class BungeeInformationManager extends InformationManager {
*/
@Override
public boolean isAnalysisCached(UUID serverUUID) {
if (PlanBungee.getServerUUID().equals(serverUUID)) {
return PageCache.isCached("networkPage");
} else {
return PageCache.isCached("analysisPage:" + serverUUID);
}
return PageCache.isCached(PageId.SERVER.of(serverUUID));
}
/**
@ -250,7 +247,7 @@ public class BungeeInformationManager extends InformationManager {
*/
@Override
public String getPlayerHtml(UUID uuid) {
Response response = PageCache.copyPage("inspectPage:" + uuid,
Response response = PageCache.copyPage(PageId.PLAYER.of(uuid),
() -> new NotFoundResponse("No Bukkit Servers were online to process this request"));
if (response instanceof InspectPageResponse) {
((InspectPageResponse) response).setInspectPagePluginsTab(getPluginsTabContent(uuid));
@ -314,7 +311,7 @@ public class BungeeInformationManager extends InformationManager {
Map<UUID, String[]> perServerPluginsTab = pluginsTabContent.getOrDefault(uuid, new HashMap<>());
perServerPluginsTab.put(serverUUID, html);
pluginsTabContent.put(uuid, perServerPluginsTab);
Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
Response inspectResponse = PageCache.loadPage(PageId.PLAYER.of(uuid));
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(getPluginsTabContent(uuid));
}
@ -372,7 +369,7 @@ public class BungeeInformationManager extends InformationManager {
@Override
public void updateNetworkPageContent() {
UUID serverUUID = MiscUtils.getIPlan().getServerUuid();
PageCache.cachePage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(this));
PageCache.cachePage(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(this));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportServer(plugin, serverUUID);
}

View File

@ -8,7 +8,8 @@ import com.djrapitops.plugin.command.ISender;
import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import java.io.IOException;
import java.util.*;
@ -46,7 +47,7 @@ public abstract class InformationManager {
}
public boolean isCached(UUID uuid) {
return PageCache.isCached("inspectPage: " + uuid);
return PageCache.isCached(PageId.PLAYER.of(uuid));
}
public abstract String getPlayerHtml(UUID uuid) throws ParseException;

View File

@ -235,7 +235,7 @@ public class InspectPageParser extends PageParser {
addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp()));
if (!plugin.getInfoManager().isUsingAnotherWebServer()) {
addValue("networkName", Settings.SERVER_NAME.toString());
addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
}
return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/player.html"), placeHolders);

View File

@ -42,13 +42,6 @@ public class BukkitServerInfoManager {
} catch (IOException e) {
throw new PlanEnableException("Failed to read ServerInfoFile.yml", e);
}
try {
updateServerInfo();
} catch (SQLException e) {
throw new PlanEnableException("Failed to update Database server info", e);
} catch (IOException e) {
throw new PlanEnableException("Failed to write to ServerInfoFile.yml", e);
}
}
public void updateServerInfo() throws SQLException, IOException {
@ -66,7 +59,7 @@ public class BukkitServerInfoManager {
registerServer(serverUUID);
return;
}
String name = Settings.SERVER_NAME.toString();
String name = Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_");
String webAddress = plugin.getWebServer().getAccessAddress();
if ("plan".equalsIgnoreCase(name)) {
name = "Server " + serverID.get();
@ -83,7 +76,7 @@ public class BukkitServerInfoManager {
private void registerServer(UUID serverUUID) throws SQLException, IOException {
String webAddress = plugin.getWebServer().getAccessAddress();
String name = Settings.SERVER_NAME.toString();
String name = Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_");
int maxPlayers = plugin.getVariable().getMaxPlayers();
serverInfo = new ServerInfo(-1, serverUUID, name, webAddress, maxPlayers);
serverTable.saveCurrentServerInfo(serverInfo);

View File

@ -49,7 +49,7 @@ public class PlanGamemodeChangeListener implements Listener {
String gameMode = event.getNewGameMode().name();
String worldName = p.getWorld().getName();
new WorldAliasSettings(plugin).addWorld(worldName);
new WorldAliasSettings().addWorld(worldName);
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));

View File

@ -7,6 +7,7 @@ import main.java.com.djrapitops.plan.data.container.Session;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.processing.info.NetworkPageUpdateProcessor;
import main.java.com.djrapitops.plan.systems.processing.player.*;
import main.java.com.djrapitops.plan.systems.tasks.TaskSystem;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -103,7 +104,7 @@ public class PlanPlayerListener implements Listener {
String playerName = player.getName();
String displayName = player.getDisplayName();
int playersOnline = plugin.getTpsCountTimer().getLatestPlayersOnline();
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
cache.cacheSession(uuid, Session.start(time, world, gm));
plugin.addToProcessQueue(

View File

@ -31,7 +31,7 @@ public class PlanWorldChangeListener implements Listener {
String gameMode = p.getGameMode().name();
long time = MiscUtils.getTime();
new WorldAliasSettings(plugin).addWorld(worldName);
new WorldAliasSettings().addWorld(worldName);
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));

View File

@ -0,0 +1,44 @@
/*
* 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.systems.tasks;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PlanBungeeTaskSystem extends TaskSystem {
@Override
public void init() throws PlanEnableException {
registerTasks();
}
private void registerTasks() {
BungeeInformationManager infoManager = ((BungeeInformationManager) PlanBungee.getInstance().getInfoManager());
registerTask("Enable Bukkit Connection Task", new AbsRunnable() {
@Override
public void run() {
infoManager.attemptConnection();
infoManager.sendConfigSettings();
}
}).runTaskAsynchronously();
registerTask("Player Count task", new TPSCountTimer(PlanBungee.getInstance()))
.runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
registerTask("NetworkPageContentUpdateTask", new AbsRunnable("NetworkPageContentUpdateTask") {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.systems.tasks;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.ITask;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.settings.locale.Locale;
import main.java.com.djrapitops.plan.settings.locale.Msg;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PlanTaskSystem extends TaskSystem {
// TODO Remove Plan.getInstance requirement.
private ITask bootAnalysisTask;
@Override
public void init() throws PlanEnableException {
registerTasks();
}
// TODO Clean Up
private void registerTasks() {
String bootAnalysisMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_INFO).toString();
String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString();
Benchmark.start("Task Registration");
tpsCountTimer = new TPSCountTimer(Plan.getInstance());
registerTask(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
// Analysis refresh settings
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
long analysisPeriod = analysisRefreshMinutes * TimeAmount.MINUTE.ticks();
Log.info(bootAnalysisMsg);
InformationManager infoManager = Plan.getInstance().getInfoManager();
bootAnalysisTask = RunnableFactory.createNew("BootAnalysisTask", new AbsRunnable() {
@Override
public void run() {
Log.info(bootAnalysisRunMsg);
infoManager.refreshAnalysis(Plan.getServerUUID());
this.cancel();
}
}).runTaskLaterAsynchronously(30 * TimeAmount.SECOND.ticks());
if (analysisRefreshTaskIsEnabled) {
RunnableFactory.createNew("PeriodicalAnalysisTask", new AbsRunnable() {
@Override
public void run() {
infoManager.refreshAnalysis(Plan.getServerUUID());
}
}).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
}
registerTask("PeriodicNetworkBoxRefreshTask", new AbsRunnable() {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(TimeAmount.SECOND.ticks(), TimeAmount.MINUTE.ticks() * 5L);
Benchmark.stop("Enable", "Task Registration");
}
public void cancelBootAnalysis() {
try {
bootAnalysisTask.cancel();
} catch (Exception ignored) {
/* Ignored */
}
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.systems.tasks;
import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.IRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public abstract class TaskSystem implements SubSystem {
protected TPSCountTimer tpsCountTimer;
public static TaskSystem getInstance() {
return Systems.getInstance().getTaskSystem();
}
protected IRunnable registerTask(AbsRunnable runnable) {
String taskName = runnable.getName();
return registerTask(taskName != null ? taskName : runnable.getClass().getSimpleName(), runnable);
}
protected IRunnable registerTask(String name, AbsRunnable runnable) {
return RunnableFactory.createNew(name, runnable);
}
@Override
public void close() {
TaskCenter.cancelAllKnownTasks(MiscUtils.getIPlan().getClass());
}
public TPSCountTimer getTpsCountTimer() {
return tpsCountTimer;
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.systems.update;
import com.djrapitops.plugin.api.Priority;
import com.djrapitops.plugin.api.systems.NotificationCenter;
import com.djrapitops.plugin.api.utility.Version;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import java.io.IOException;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class VersionCheckSystem implements SubSystem {
private final String currentVersion;
private boolean newVersionAvailable = false;
public VersionCheckSystem(String currentVersion) {
this.currentVersion = currentVersion;
}
public static VersionCheckSystem getInstance() {
return Systems.getInstance().getVersionCheckSystem();
}
@Override
public void init() throws PlanEnableException {
checkForNewVersion();
}
private void checkForNewVersion() {
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
try {
newVersionAvailable = Version.checkVersion(currentVersion, githubVersionUrl)
|| Version.checkVersion(currentVersion, spigotUrl);
if (newVersionAvailable) {
String newVersionNotification = "New Version is available at " + spigotUrl;
Log.infoColor("§a----------------------------------------");
Log.infoColor("§a"+newVersionNotification);
Log.infoColor("§a----------------------------------------");
NotificationCenter.addNotification(Priority.HIGH, newVersionNotification);
} else {
Log.info("You're using the latest version.");
}
} catch (IOException e) {
Log.error("Failed to check newest version number");
}
}
@Override
public void close() {
/* Does not need to be closed */
}
public static boolean isNewVersionAvailable() {
return getInstance().newVersionAvailable;
}
}

View File

@ -5,6 +5,8 @@
package main.java.com.djrapitops.plan.systems.webserver;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
@ -39,29 +41,29 @@ public class APIResponseHandler {
String[] args = target.split("/");
if ("/favicon.ico".equalsIgnoreCase(target)) {
return PageCache.loadPage("Redirect: favicon", () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
return PageCache.loadPage(PageId.FAVICON_REDIRECT.id(), () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
}
if ("/debug".equalsIgnoreCase(target)) {
return new DebugPageResponse();
}
if (target.endsWith(".css")) {
return PageCache.loadPage(target + "css", () -> new CSSResponse(target));
return PageCache.loadPage(PageId.CSS.of(target), () -> new CSSResponse(target));
}
if (target.endsWith(".js")) {
return PageCache.loadPage(target + "js", () -> new JavaScriptResponse(target));
return PageCache.loadPage(PageId.JS.of(target), () -> new JavaScriptResponse(target));
}
if (args.length < 2 || !"api".equals(args[1])) {
String address = MiscUtils.getIPlan().getInfoManager().getWebServerAddress() + target;
String link = Html.LINK.parse(address, address);
return PageCache.loadPage("Non-API Request", () -> new NotFoundResponse("WebServer is in WebAPI-only mode, " +
return PageCache.loadPage(PageId.ERROR.of("Non-API Request"), () -> new NotFoundResponse("WebServer is in WebAPI-only mode, " +
"connect to the Bungee server instead: " + link));
}
if (args.length < 3) {
String error = "API Method not specified";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
}
String method = args[2];
@ -73,7 +75,7 @@ public class APIResponseHandler {
if (requestBody == null) {
String error = "Error at reading the POST request." +
"Note that the Encoding must be ISO-8859-1.";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
}
Map<String, String> variables = WebAPI.readVariables(requestBody);
@ -92,7 +94,7 @@ public class APIResponseHandler {
if (!checkKey(sender)) {
String error = "Server Key not given or invalid";
Log.debug("Request had invalid Server key: " + sender);
return PageCache.loadPage(error, () -> {
return PageCache.loadPage(PageId.ERROR.of(error), () -> {
ForbiddenResponse forbidden = new ForbiddenResponse();
forbidden.setContent(error);
return forbidden;
@ -102,7 +104,7 @@ public class APIResponseHandler {
if (!webAPI.isAuthorized(accessKey)) {
String error = "Access Key invalid";
Log.debug("Request had invalid Access key: " + accessKey);
return PageCache.loadPage(error, () -> {
return PageCache.loadPage(PageId.ERROR.of(error), () -> {
ForbiddenResponse forbidden = new ForbiddenResponse();
forbidden.setContent(error);
return forbidden;
@ -116,7 +118,7 @@ public class APIResponseHandler {
if (api == null) {
String error = "API Method not found";
Log.debug(error);
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
}
Response response = api.processRequest(MiscUtils.getIPlan(), variables);

View File

@ -10,6 +10,8 @@ import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.api.exceptions.WebUserAuthException;
import main.java.com.djrapitops.plan.data.WebUser;
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
@ -42,17 +44,17 @@ public class ResponseHandler extends APIResponseHandler {
String[] args = target.split("/");
try {
if ("/favicon.ico".equals(target)) {
return PageCache.loadPage("Redirect: favicon", () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
return PageCache.loadPage(PageId.FAVICON_REDIRECT.id(), () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
}
if (request.isAPIRequest()) {
return getAPIResponse(request);
}
if (target.endsWith(".css")) {
return PageCache.loadPage(target + "css", () -> new CSSResponse(target));
return PageCache.loadPage(PageId.CSS.of(target), () -> new CSSResponse(target));
}
if (target.endsWith(".js")) {
return PageCache.loadPage(target + "js", () -> new JavaScriptResponse(target));
return PageCache.loadPage(PageId.JS.of(target), () -> new JavaScriptResponse(target));
}
UUID serverUUID = MiscUtils.getIPlan().getServerUuid();
@ -81,7 +83,7 @@ public class ResponseHandler extends APIResponseHandler {
case "debug":
return new DebugPageResponse();
case "players":
return PageCache.loadPage("players", PlayersPageResponse::new);
return PageCache.loadPage(PageId.PLAYERS.id(), PlayersPageResponse::new);
case "player":
return playerResponse(args);
case "network":
@ -102,7 +104,7 @@ public class ResponseHandler extends APIResponseHandler {
}
} catch (WebUserAuthException e) {
return PageCache.loadPage("promptAuthorization", PromptAuthorizationResponse::new);
return PageCache.loadPage(PageId.AUTH_PROMPT.id(), PromptAuthorizationResponse::new);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
return new InternalErrorResponse(e, request.getTarget());
@ -110,7 +112,7 @@ public class ResponseHandler extends APIResponseHandler {
}
private Response forbiddenResponse(int required, int permLevel) {
return PageCache.loadPage("forbidden", () ->
return PageCache.loadPage(PageId.FORBIDDEN.id(), () ->
new ForbiddenResponse("Unauthorized User.<br>"
+ "Make sure your user has the correct access level.<br>"
+ "This page requires permission level of " + required + ",<br>"
@ -182,7 +184,7 @@ public class ResponseHandler extends APIResponseHandler {
case 0:
return serverResponse(serverUUID);
case 1:
return PageCache.loadPage("players", PlayersPageResponse::new);
return PageCache.loadPage(PageId.PLAYERS.id(), PlayersPageResponse::new);
case 2:
return playerResponse(new String[]{"", "", user.getName()});
default:
@ -191,12 +193,12 @@ public class ResponseHandler extends APIResponseHandler {
}
private Response serverResponse(UUID serverUUID) {
return PageCache.loadPage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(plugin.getInfoManager()));
return PageCache.loadPage(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(plugin.getInfoManager()));
}
private Response playerResponse(String[] args) {
if (args.length < 3) {
return PageCache.loadPage("notFound", NotFoundResponse::new);
return PageCache.loadPage(PageId.NOT_FOUND.id(), NotFoundResponse::new);
}
String playerName = args[2].trim();
@ -204,22 +206,22 @@ public class ResponseHandler extends APIResponseHandler {
if (uuid == null) {
String error = "Player has no UUID";
return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
return PageCache.loadPage(PageId.NOT_FOUND.of(error), () -> new NotFoundResponse(error));
}
if (plugin.getDB().wasSeenBefore(uuid)) {
plugin.getInfoManager().cachePlayer(uuid);
Response response = PageCache.loadPage("inspectPage: " + uuid);
Response response = PageCache.loadPage(PageId.PLAYER.of(uuid));
// TODO Create a new method that places NotFoundResponse to PageCache instead.
if (response == null || response.getContent().contains("No Bukkit Servers were online to process this request")) {
PageCache.cachePage("inspectPage: " + uuid, () -> {
PageCache.cachePage(PageId.PLAYER.of(uuid), () -> {
try {
return new InspectPageResponse(plugin.getInfoManager(), uuid);
} catch (ParseException e) {
return new InternalErrorResponse(e, this.getClass().getName());
}
});
response = PageCache.loadPage("inspectPage: " + uuid);
response = PageCache.loadPage(PageId.PLAYER.of(uuid));
}
return response;
}
@ -228,7 +230,7 @@ public class ResponseHandler extends APIResponseHandler {
private Response notFoundResponse() {
String error = "404 Not Found";
return PageCache.loadPage("notFound: " + error, () -> {
return PageCache.loadPage(PageId.NOT_FOUND.of("Wrong Page"), () -> {
String url = plugin.getInfoManager().getWebServerAddress();
return new NotFoundResponse("Make sure you're accessing a link given by a command, Examples:</p>"
+ "<p>" + url + "/player/Playername<br>" +

View File

@ -0,0 +1,55 @@
/*
* 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.systems.webserver;
import com.djrapitops.plugin.api.Check;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class WebServerSystem implements SubSystem {
private WebServer webServer;
public WebServerSystem() {
}
public static WebServerSystem getInstance() {
return Systems.getInstance().getWebServerSystem();
}
@Override
public void init() throws PlanEnableException {
webServer = new WebServer(MiscUtils.getIPlan());
webServer.initServer();
if (Check.isBungeeAvailable() && !webServer.isEnabled()) {
throw new PlanEnableException("WebServer did not initialize!");
}
}
@Override
public void close() {
// TODO Remove after WebServer setting requirement is gone.
if (webServer != null) {
webServer.stop();
}
}
public static boolean isWebServerEnabled() {
WebServer webServer = getInstance().webServer;
return webServer != null && webServer.isEnabled();
}
public WebServer getWebServer() {
return webServer;
}
}

View File

@ -1,4 +1,4 @@
package main.java.com.djrapitops.plan.systems.webserver;
package main.java.com.djrapitops.plan.systems.webserver.pagecache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

View File

@ -0,0 +1,50 @@
/*
* 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.systems.webserver.pagecache;
import java.util.UUID;
/**
* Enum class for "magic" PageCache identifier values.
*
* @author Rsl1122
*/
public enum PageId {
SERVER("serverPage:"),
PLAYER("playerPage:"),
PLAYERS("playersPage"),
//
ERROR("error:"),
FORBIDDEN(ERROR.of("Forbidden")),
NOT_FOUND(ERROR.of("Not Found")),
TRUE("true"),
FALSE("false"),
//
JS("js:"),
CSS("css:"),
//
FAVICON_REDIRECT("Redirect:Favicon"),
AUTH_PROMPT("PromptAuth")
;
private final String id;
PageId(String id) {
this.id = id;
}
public String of(String additionalInfo) {
return id + additionalInfo;
}
public String of(UUID uuid) {
return of(uuid.toString());
}
public String id() {
return id;
}
}

View File

@ -1,4 +1,4 @@
package main.java.com.djrapitops.plan.systems.webserver;
package main.java.com.djrapitops.plan.systems.webserver.pagecache;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;

View File

@ -13,7 +13,7 @@ public class ForbiddenResponse extends ErrorResponse {
}
public ForbiddenResponse(String msg) {
super.setHeader("HTTP/1.1 404 Not Found");
super.setHeader("HTTP/1.1 403 Forbidden");
super.setTitle("403 Forbidden - Access Denied");
super.setParagraph(msg);
super.replacePlaceholders();

View File

@ -37,7 +37,7 @@ public class PlayersPageResponse extends Response {
Collections.sort(names);
Map<String, String> replace = new HashMap<>();
if (Check.isBukkitAvailable()) {
replace.put("networkName", Settings.SERVER_NAME.toString());
replace.put("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
} else {
replace.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString());
}

View File

@ -9,7 +9,8 @@ import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.*;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.NotFoundResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
@ -165,11 +166,11 @@ public abstract class WebAPI {
};
protected Response success() {
return PageCache.loadPage("success", SuccessResponse::new);
return PageCache.loadPage(PageId.TRUE.id(), SuccessResponse::new);
}
protected Response fail(String reason) {
return PageCache.loadPage("fail", () -> {
return PageCache.loadPage(PageId.FALSE.id(), () -> {
NotFoundResponse notFoundResponse = new NotFoundResponse("");
notFoundResponse.setContent(reason);
return notFoundResponse;
@ -177,7 +178,7 @@ public abstract class WebAPI {
}
protected Response badRequest(String error) {
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
}
private String parseVariables() {

View File

@ -9,7 +9,8 @@ import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
@ -54,14 +55,14 @@ public class PostHtmlWebAPI extends WebAPI {
Map<String, String> map = new HashMap<>();
map.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString());
PageCache.cachePage("inspectPage:" + uuid, () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), StrSubstitutor.replace(html, map)));
PageCache.cachePage(PageId.PLAYER.of(uuid), () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), StrSubstitutor.replace(html, map)));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportPlayer(plugin, UUID.fromString(uuid));
}
break;
case "analysisPage":
String sender = variables.get("sender");
PageCache.cachePage("analysisPage:" + sender, () -> new AnalysisPageResponse(html));
PageCache.cachePage(PageId.SERVER.of(sender), () -> new AnalysisPageResponse(html));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportServer(plugin, UUID.fromString(sender));
}

View File

@ -50,7 +50,7 @@ public class PostOriginalBukkitSettingsWebAPI extends WebAPI {
@Override
public void sendRequest(String address) throws WebAPIException {
addVariable("WebServerPort", Integer.toString(Settings.WEBSERVER_PORT.getNumber()));
addVariable("ServerName", Settings.SERVER_NAME.toString());
addVariable("ServerName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
addVariable("ThemeBase", Settings.THEME_BASE.toString());
super.sendRequest(address);
}

View File

@ -1,4 +1,4 @@
/*
/*
* 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
*/
@ -13,6 +13,7 @@ import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import main.java.com.djrapitops.plan.systems.webserver.response.ForbiddenResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
@ -31,6 +32,11 @@ public class RequestSetupWebAPI extends WebAPI {
if (!Check.isBungeeAvailable()) {
return badRequest("Called a Bukkit server.");
}
if (!((PlanBungee) plugin).isSetupAllowed()) {
return new ForbiddenResponse("Setup mode disabled, use /planbungee setup to enable");
}
String serverUUIDS = variables.get("sender");
String webAddress = variables.get("webAddress");
String accessCode = variables.get("accessKey");
@ -38,7 +44,8 @@ public class RequestSetupWebAPI extends WebAPI {
return badRequest("Variable was null");
}
ServerInfo serverInfo = new ServerInfo(-1, UUID.fromString(serverUUIDS), "", webAddress, 0);
PlanBungee.getInstance().getServerInfoManager().attemptConnection(serverInfo, accessCode);
((PlanBungee) plugin).getServerInfoManager().attemptConnection(serverInfo, accessCode);
return success();
}

View File

@ -6,7 +6,7 @@ import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.database.tables.move.BatchOperationTable;
import main.java.com.djrapitops.plan.systems.DatabaseSystem;
import main.java.com.djrapitops.plan.systems.file.database.DBSystem;
import java.sql.SQLException;
import java.util.*;
@ -76,6 +76,6 @@ public class ManageUtils {
@Deprecated
public static Database getDB(String dbName) throws DatabaseInitException {
return DatabaseSystem.getActiveDatabase(dbName);
return DBSystem.getActiveDatabase(dbName);
}
}

View File

@ -20,6 +20,8 @@ import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.tasks.PlanTaskSystem;
import main.java.com.djrapitops.plan.systems.tasks.TaskSystem;
import main.java.com.djrapitops.plan.systems.webserver.response.ErrorResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse;
@ -54,6 +56,8 @@ public class Analysis {
return;
}
((PlanTaskSystem) TaskSystem.getInstance()).cancelBootAnalysis();
Benchmark.start("Analysis");
log(Locale.get(Msg.ANALYSIS_START).toString());
// Async task for Analysis
@ -218,10 +222,6 @@ public class Analysis {
return taskId != -1;
}
public void setTaskId(int id) {
taskId = id;
}
/**
* Only available during Analysis.
*

View File

@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.utilities.comparators;
import java.util.Comparator;
/**
* Compares Strings and sorts them by length
* Compares Strings and sorts them by length (Longest fist).
*
* @author Rsl1122
* @since 3.6.2

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.utilities.file;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -80,6 +81,8 @@ public class FileUtil {
lines.add(scanner.nextLine());
}
} catch (NullPointerException e) {
Log.infoColor("§ea Resource was not found inside the jar, Plan does not support /reload or updates using " +
"Plugin Managers, restart the server and see if the error persists.");
throw new FileNotFoundException("File not found inside jar: " + resource);
} finally {
MiscUtils.close(scanner);
@ -100,5 +103,4 @@ public class FileUtil {
}
return lines;
}
}
}

View File

@ -182,7 +182,7 @@ public class HtmlExport extends SpecificExport {
List<String> lines = FileUtil.lines(plugin, new File(plugin.getDataFolder(), possibleFile), resource);
String outputFile = possibleFile.replace("web/", "");
File to = new File(outputFolder, outputFile);
to.mkdirs();
to.getParentFile().mkdirs();
if (to.exists()) {
to.delete();
to.createNewFile();

View File

@ -8,7 +8,8 @@ import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -73,7 +74,7 @@ public abstract class SpecificExport extends AbsRunnable {
}
protected void exportAvailablePlayerPage(UUID uuid, String name) throws IOException {
Response response = PageCache.loadPage("inspectPage: " + uuid);
Response response = PageCache.loadPage(PageId.PLAYER.of(uuid));
if (response == null) {
return;
}
@ -90,7 +91,7 @@ public abstract class SpecificExport extends AbsRunnable {
protected void exportAvailableServerPage(UUID serverUUID, String serverName) throws IOException {
Response response = PageCache.loadPage("analysisPage:" + serverUUID);
Response response = PageCache.loadPage(PageId.SERVER.of(serverUUID));
if (response == null) {
return;
}

View File

@ -1,12 +1,11 @@
package main.java.com.djrapitops.plan.utilities.html.graphs.pie;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.time.GMTimes;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.settings.WorldAliasSettings;
import main.java.com.djrapitops.plan.settings.theme.ThemeVal;
import main.java.com.djrapitops.plan.settings.theme.Theme;
import main.java.com.djrapitops.plan.settings.theme.ThemeVal;
import main.java.com.djrapitops.plan.utilities.comparators.PieSliceComparator;
import java.util.*;
@ -64,14 +63,14 @@ public class WorldPie {
}
private static Map<String, Long> transformToAliases(Map<String, Long> playtimePerWorld) {
WorldAliasSettings aliasSettings = new WorldAliasSettings(Plan.getInstance());
WorldAliasSettings aliasSettings = new WorldAliasSettings();
Map<String, String> aliases = aliasSettings.getAliases();
return transformToAliases(playtimePerWorld, aliases);
}
public static Map<String, Long> transformToAliases(Map<String, Long> playtimePerWorld, Map<String, String> aliases) {
// TODO Optimization is possible
WorldAliasSettings aliasSettings = new WorldAliasSettings(Plan.getInstance());
WorldAliasSettings aliasSettings = new WorldAliasSettings();
Map<String, Long> playtimePerAlias = new HashMap<>();
for (Map.Entry<String, Long> entry : playtimePerWorld.entrySet()) {
@ -121,7 +120,7 @@ public class WorldPie {
private static Map<String, GMTimes> transformToGMAliases(Map<String, GMTimes> gmTimesMap) {
// TODO Optimization is possible
WorldAliasSettings aliasSettings = new WorldAliasSettings(Plan.getInstance());
WorldAliasSettings aliasSettings = new WorldAliasSettings();
Map<String, String> aliases = aliasSettings.getAliases();
Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();

View File

@ -38,9 +38,10 @@ public class ServerAccordionCreator {
"</div>", ""};
}
int i = 0;
for (Map.Entry<UUID, WorldTimes> entry : worldTimesPerServer.entrySet()) {
UUID serverUUID = entry.getKey();
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
WorldTimes worldTimes = entry.getValue();
List<Session> sessions = profile.getSessions(serverUUID);
@ -60,7 +61,8 @@ public class ServerAccordionCreator {
String longest = sessionCount != 0 ? FormatUtils.formatTimeAmount(longestSession) : "-";
String sanitizedServerName = new Format(serverName)
.removeSymbols().removeWhitespace().toString();
.removeSymbols()
.removeWhitespace().toString() + i;
String htmlID = "server_" + sanitizedServerName;
String worldId = "worldPieServer" + sanitizedServerName;
@ -116,6 +118,8 @@ public class ServerAccordionCreator {
.append(worldId).append("series, ")
.append(worldId).append("gmseries")
.append(");");
i++;
}
return new String[]{html.append("</div>").toString(), viewScript.toString()};
}

View File

@ -105,7 +105,7 @@ public class SessionsTableCreator {
}
public static String getLongestWorldPlayed(Session session) {
WorldAliasSettings aliasSettings = new WorldAliasSettings(Plan.getInstance());
WorldAliasSettings aliasSettings = new WorldAliasSettings();
Map<String, String> aliases = aliasSettings.getAliases();
if (session.getSessionEnd() == -1) {
return "Current: " + aliases.get(session.getWorldTimes().getCurrentWorld());

View File

@ -1,4 +1,4 @@
name: Plan
author: Rsl1122
main: main.java.com.djrapitops.plan.PlanBungee
version: 4.1.3.1
version: 4.1.4

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: main.java.com.djrapitops.plan.Plan
version: 4.1.3.1
version: 4.1.4
softdepend:
- EssentialsX
- Towny

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.data.cache;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.PageLoader;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageLoader;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import org.junit.Test;
import test.java.utils.RandomData;

View File

@ -51,7 +51,7 @@ public class TestInit {
* Does not load any messages from anywhere because that would cause exceptions.
*/
public static void initEmptyLocale() {
new Locale(null);
new Locale();
}
/**
@ -62,7 +62,7 @@ public class TestInit {
* @param plan Mocked Plan
*/
public static void initLocale(Plan plan) {
new Locale(plan).loadLocale();
new Locale().loadLocale();
}
public static TestInit init() throws Exception {
@ -139,7 +139,7 @@ public class TestInit {
when(planMock.getServerInfoManager()).thenReturn(bukkitServerInfoManager);
ColorScheme cs = new ColorScheme(ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK);
when(planMock.getColorScheme()).thenReturn(cs);
initLocale(planMock);
initLocale(null);
RunnableFactory.activateTestMode();
}

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 test.java.utils.testsystem;
import main.java.com.djrapitops.plan.systems.file.config.ConfigSystem;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class TestConfigSystem extends ConfigSystem {
@Override
protected void copyDefaults() throws IOException {
File file = new File(getClass().getResource("/config.yml").getPath());
Scanner scanner = new Scanner(new FileInputStream(file));
List<String> lines = new ArrayList<>();
while (scanner.hasNextLine()) {
lines.add(scanner.nextLine());
}
config.copyDefaults(lines);
}
}

Binary file not shown.

View File

@ -33,7 +33,7 @@ public class HackerTable extends Table {
private final String columnViolations;
public HackerTable(SQLDB db) {
super("plan_viaversion_protocol", db, db.isUsingMySQL());
super("plan_aac_hack_table", db, db.isUsingMySQL());
columnUUID = "uuid";
columnDate = "date";
columnHackType = "hack_type";
@ -43,7 +43,7 @@ public class HackerTable extends Table {
@Override
public void createTable() throws DBCreateTableException {
createTable("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnUUID + " varchar(36) NOT NULL UNIQUE, "
+ columnUUID + " varchar(36) NOT NULL, "
+ columnDate + " bigint NOT NULL, "
+ columnHackType + " varchar(100) NOT NULL, "
+ columnViolations + " integer NOT NULL"
@ -107,7 +107,7 @@ public class HackerTable extends Table {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, hackObject.getUuid().toString());
statement.setLong(2, hackObject.getDate());
statement.setString(3, hackObject.getHackType().getName());
statement.setString(3, hackObject.getHackType().name());
statement.setInt(4, hackObject.getViolationLevel());
}
});

View File

@ -50,7 +50,7 @@ public class PlayerHackKickListener implements Listener {
try {
new HackerTable((SQLDB) plan.getDB()).insertHackRow(hackObject);
} catch (SQLException e) {
Log.toLog(this.getClass().getName() + ":PlanViaVersionJoinListener", e);
Log.toLog(this.getClass().getName(), e);
}
}
});

View File

@ -46,7 +46,7 @@ public class PlayerVersionListener implements Listener {
try {
new ProtocolTable((SQLDB) plan.getDB()).saveProtocolVersion(uuid, playerVersion);
} catch (SQLException e) {
Log.toLog(this.getClass().getName() + ":PlanViaVersionJoinListener", e);
Log.toLog(this.getClass().getName(), e);
}
}
});

View File

@ -32,7 +32,7 @@ public class ProtocolTable extends Table {
private final String columnProtocolVersion;
public ProtocolTable(SQLDB db) {
super("plan_viaversion_protocol", db, db.isUsingMySQL());
super("plan_version_protocol", db, db.isUsingMySQL());
columnUUID = "uuid";
columnProtocolVersion = "protocol_version";
}