mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Remove redundant code
This commit is contained in:
parent
a60f77f06f
commit
cefe17ead8
@ -43,9 +43,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* Main class for Bukkit that manages the plugin.
|
||||
* <p>
|
||||
* Everything can be accessed through this class. Use Plan.getInstance() to get
|
||||
* the initialised instance of Plan.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
|
@ -8,8 +8,7 @@ import com.djrapitops.plan.command.PlanBungeeCommand;
|
||||
import com.djrapitops.plan.system.BungeeSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.ServerProperties;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||
@ -34,9 +33,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||
|
||||
private BungeeSystem system;
|
||||
|
||||
private BungeeServerInfo serverInfoManager;
|
||||
private ServerProperties variableHolder;
|
||||
|
||||
@Deprecated
|
||||
private boolean setupAllowed = false;
|
||||
|
||||
@ -52,7 +48,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||
system.enable();
|
||||
|
||||
// TODO BungeeServerInfo & move there.
|
||||
String ip = variableHolder.getIp();
|
||||
String ip = ServerInfo.getServerProperties().getIp();
|
||||
if ("0.0.0.0".equals(ip)) {
|
||||
Log.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
|
||||
Log.info("Player Analytics partially enabled (Use /planbungee to reload config)");
|
||||
@ -108,11 +104,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||
return PlanColorScheme.create();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerProperties getVariable() {
|
||||
return variableHolder;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isSetupAllowed() {
|
||||
return setupAllowed;
|
||||
|
@ -2,9 +2,6 @@ package com.djrapitops.plan.api.exceptions;
|
||||
|
||||
public class PassEncryptException extends Exception {
|
||||
|
||||
public PassEncryptException() {
|
||||
}
|
||||
|
||||
public PassEncryptException(String s) {
|
||||
super(s);
|
||||
}
|
||||
@ -13,11 +10,4 @@ public class PassEncryptException extends Exception {
|
||||
super(s, throwable);
|
||||
}
|
||||
|
||||
public PassEncryptException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public PassEncryptException(String s, Throwable throwable, boolean b, boolean b1) {
|
||||
super(s, throwable, b, b1);
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
|
||||
new ListCommand(),
|
||||
new BungeeSetupToggleCommand(plugin)
|
||||
);
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
RegisterCommand registerCommand = new RegisterCommand();
|
||||
add(
|
||||
registerCommand,
|
||||
new WebUserCommand(plugin, registerCommand),
|
||||
new NetworkCommand(plugin),
|
||||
new NetworkCommand(),
|
||||
new ListServersCommand(plugin)
|
||||
);
|
||||
}
|
||||
|
@ -43,23 +43,23 @@ public class PlanCommand extends TreeCommand<Plan> {
|
||||
add(
|
||||
new InspectCommand(plugin),
|
||||
new QInspectCommand(plugin),
|
||||
new AnalyzeCommand(plugin),
|
||||
new SearchCommand(plugin),
|
||||
new AnalyzeCommand(),
|
||||
new SearchCommand(),
|
||||
new InfoCommand(plugin),
|
||||
new ReloadCommand(plugin),
|
||||
new ManageCommand(plugin),
|
||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
||||
new ListCommand()
|
||||
);
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
RegisterCommand registerCommand = new RegisterCommand();
|
||||
add(
|
||||
registerCommand,
|
||||
new WebUserCommand(plugin, registerCommand),
|
||||
new NetworkCommand(plugin),
|
||||
new NetworkCommand(),
|
||||
new ListServersCommand(plugin));
|
||||
|
||||
if (Settings.DEV_MODE.isTrue()) {
|
||||
add(new DevCommand(plugin));
|
||||
add(new DevCommand());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
@ -9,7 +8,7 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
@ -20,8 +19,6 @@ import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.SubCommand;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Map;
|
||||
@ -39,9 +36,8 @@ public class AnalyzeCommand extends SubCommand {
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public AnalyzeCommand(Plan plugin) {
|
||||
public AnalyzeCommand() {
|
||||
super("analyze, analyse, analysis, a",
|
||||
CommandType.CONSOLE,
|
||||
Permissions.ANALYZE.getPermission(),
|
||||
@ -58,24 +54,21 @@ public class AnalyzeCommand extends SubCommand {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
|
||||
|
||||
new Processor<ISender>(sender) {
|
||||
@Override
|
||||
public void process() {
|
||||
try {
|
||||
Server server = getServer(args).orElseGet(ServerInfo::getServer);
|
||||
UUID serverUUID = server.getUuid();
|
||||
if (!ServerInfo.getServerUUID().equals(serverUUID) || !Analysis.isAnalysisBeingRun()) {
|
||||
InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(serverUUID));
|
||||
}
|
||||
sendWebUserNotificationIfNecessary(sender);
|
||||
sendLink(server, sender);
|
||||
} catch (DBException | WebException e) {
|
||||
// TODO Exception handling
|
||||
sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString());
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
Processor.queue(() -> {
|
||||
try {
|
||||
Server server = getServer(args).orElseGet(ServerInfo::getServer);
|
||||
UUID serverUUID = server.getUuid();
|
||||
if (!ServerInfo.getServerUUID().equals(serverUUID) || !Analysis.isAnalysisBeingRun()) {
|
||||
InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(serverUUID));
|
||||
}
|
||||
sendWebUserNotificationIfNecessary(sender);
|
||||
sendLink(server, sender);
|
||||
} catch (DBException | WebException e) {
|
||||
// TODO Exception handling
|
||||
sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString());
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}.queue();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -97,21 +90,17 @@ public class AnalyzeCommand extends SubCommand {
|
||||
|
||||
private void sendWebUserNotificationIfNecessary(ISender sender) {
|
||||
if (WebServerSystem.getInstance().getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
|
||||
RunnableFactory.createNew(new AbsRunnable("WebUser exist check task") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + getName(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
|
||||
Processor.queue(() -> {
|
||||
try {
|
||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + getName(), e);
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
@ -20,11 +19,8 @@ import com.djrapitops.plugin.command.SubCommand;
|
||||
*/
|
||||
public class DevCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
public DevCommand(Plan plugin) {
|
||||
public DevCommand() {
|
||||
super("dev", CommandType.PLAYER_OR_ARGS, "plan.*", "Test Plugin functions not testable with unit tests.", "<feature to test>");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.SubCommand;
|
||||
@ -40,10 +42,13 @@ public class InfoCommand extends SubCommand {
|
||||
String sColor = cs.getSecondaryColor();
|
||||
String tColor = cs.getTertiaryColor();
|
||||
String ball = Locale.get(Msg.CMD_CONSTANT_LIST_BALL).toString();
|
||||
|
||||
String upToDate = VersionCheckSystem.isNewVersionAvailable() ? "Update Available" : "Up to date";
|
||||
String[] messages = {
|
||||
Locale.get(Msg.CMD_HEADER_INFO).toString(),
|
||||
ball + mColor + " Version: " + sColor + plugin.getDescription().getVersion(),
|
||||
ball + mColor + " Active Database: " + tColor + plugin.getDB().getConfigName(),
|
||||
ball + mColor + " Up to date: " + sColor + upToDate,
|
||||
ball + mColor + " Active Database: " + tColor + Database.getActive().getConfigName(),
|
||||
Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()
|
||||
};
|
||||
sender.sendMessage(messages);
|
||||
|
@ -83,13 +83,12 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
new InspectCacheRequestProcessor(uuid, sender, playerName).queue();
|
||||
} catch (FatalDBException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage());
|
||||
} catch (DBException ex) {
|
||||
if (ex instanceof FatalDBException) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Non-Fatal database exception occurred: " + ex.getMessage());
|
||||
}
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Non-Fatal database exception occurred: " + ex.getMessage());
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ public class ManageCommand extends TreeCommand<Plan> {
|
||||
add(
|
||||
new ManageMoveCommand(plugin),
|
||||
new ManageHotswapCommand(plugin),
|
||||
new ManageBackupCommand(plugin),
|
||||
new ManageBackupCommand(),
|
||||
new ManageRestoreCommand(plugin),
|
||||
new ManageImportCommand(plugin),
|
||||
new ManageImportCommand(),
|
||||
new ManageRemoveCommand(plugin),
|
||||
new ManageClearCommand(plugin),
|
||||
new ManageSetupCommand(plugin),
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
@ -20,17 +19,14 @@ import com.djrapitops.plugin.command.SubCommand;
|
||||
*/
|
||||
public class NetworkCommand extends SubCommand {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*/
|
||||
public NetworkCommand(PlanPlugin plugin) {
|
||||
public NetworkCommand() {
|
||||
super("network, n, netw",
|
||||
CommandType.CONSOLE,
|
||||
Permissions.ANALYZE.getPermission(),
|
||||
"Get the link to the network page");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
@ -31,15 +30,12 @@ import com.djrapitops.plugin.task.RunnableFactory;
|
||||
*/
|
||||
public class RegisterCommand extends SubCommand {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
|
||||
public RegisterCommand(PlanPlugin plugin) {
|
||||
public RegisterCommand() {
|
||||
super("register",
|
||||
CommandType.PLAYER_OR_ARGS,
|
||||
"", // No Permission Requirement
|
||||
Locale.get(Msg.CMD_USG_WEB_REGISTER).toString(),
|
||||
"<password> [name] [access lvl]");
|
||||
this.plugin = plugin;
|
||||
if (Check.isBukkitAvailable()) {
|
||||
setupFilter();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
@ -28,9 +27,8 @@ public class SearchCommand extends SubCommand {
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public SearchCommand(Plan plugin) {
|
||||
public SearchCommand() {
|
||||
super("search",
|
||||
CommandType.PLAYER_OR_ARGS,
|
||||
Permissions.SEARCH.getPermission(),
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
@ -24,21 +23,13 @@ import com.djrapitops.plugin.utilities.Verify;
|
||||
*/
|
||||
public class ManageBackupCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageBackupCommand(Plan plugin) {
|
||||
public ManageBackupCommand() {
|
||||
super("backup",
|
||||
CommandType.CONSOLE,
|
||||
Permissions.MANAGE.getPermission(),
|
||||
Locale.get(Msg.CMD_USG_MANAGE_BACKUP).toString(),
|
||||
"<DB>");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.system.processing.importing.ImporterManager;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
@ -25,9 +24,8 @@ public class ManageImportCommand extends SubCommand {
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageImportCommand(Plan plugin) {
|
||||
public ManageImportCommand() {
|
||||
super("import",
|
||||
CommandType.CONSOLE,
|
||||
Permissions.MANAGE.getPermission(),
|
||||
|
@ -17,7 +17,6 @@ import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.WorldMap;
|
||||
@ -26,7 +25,7 @@ import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.CommandUseTableCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.CommandUseTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
@ -88,10 +87,6 @@ public class AnalysisData extends RawData {
|
||||
addValue("playersOnline", ServerProfile.getPlayersOnline());
|
||||
}
|
||||
|
||||
public long getRefreshDate() {
|
||||
return refreshDate;
|
||||
}
|
||||
|
||||
public void analyze(ServerProfile profile) {
|
||||
long now = MiscUtils.getTime();
|
||||
refreshDate = now;
|
||||
@ -167,7 +162,7 @@ public class AnalysisData extends RawData {
|
||||
private void commandUsage(Map<String, Integer> commandUsage) {
|
||||
addValue("commandUniqueCount", String.valueOf(commandUsage.size()));
|
||||
addValue("commandCount", MathUtils.sumInt(commandUsage.values().stream().map(i -> (int) i)));
|
||||
addValue("tableBodyCommands", HtmlUtils.removeXSS(CommandUseTableCreator.createTable(commandUsage)));
|
||||
addValue("tableBodyCommands", new CommandUseTable(commandUsage).parseBody());
|
||||
}
|
||||
|
||||
private void geolocationsTab(List<String> geoLocations) {
|
||||
|
@ -128,12 +128,7 @@ public class PlayerProfile implements OfflinePlayer {
|
||||
|
||||
// Calculating Getters
|
||||
public ActivityIndex getActivityIndex(long date) {
|
||||
ActivityIndex index = activityIndexCache.get(date);
|
||||
if (index == null) {
|
||||
index = new ActivityIndex(this, date);
|
||||
activityIndexCache.put(date, index);
|
||||
}
|
||||
return index;
|
||||
return activityIndexCache.computeIfAbsent(date, dateValue -> new ActivityIndex(this, dateValue));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,18 +38,10 @@ public class UserInfo {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
public void setRegistered(long registered) {
|
||||
this.registered = registered;
|
||||
}
|
||||
|
||||
public long getLastSeen() {
|
||||
return lastSeen;
|
||||
}
|
||||
@ -62,10 +54,6 @@ public class UserInfo {
|
||||
return banned;
|
||||
}
|
||||
|
||||
public void setBanned(boolean banned) {
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
public boolean isOpped() {
|
||||
return opped;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public final class TableContainer {
|
||||
public class TableContainer {
|
||||
|
||||
private final String[] header;
|
||||
private List<Serializable[]> values;
|
||||
@ -38,18 +38,18 @@ public final class TableContainer {
|
||||
values = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addRow(Serializable... values) {
|
||||
public final void addRow(Serializable... values) {
|
||||
this.values.add(values);
|
||||
}
|
||||
|
||||
public String parseHtml() {
|
||||
public final String parseHtml() {
|
||||
return Html.TABLE_SCROLL.parse() +
|
||||
parseHeader() +
|
||||
parseBody() +
|
||||
"</table>";
|
||||
}
|
||||
|
||||
private String parseBody() {
|
||||
public final String parseBody() {
|
||||
StringBuilder body = new StringBuilder();
|
||||
|
||||
if (values.isEmpty()) {
|
||||
@ -73,11 +73,11 @@ public final class TableContainer {
|
||||
return Html.TABLE_BODY.parse(body.toString());
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
public final void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String parseHeader() {
|
||||
public final String parseHeader() {
|
||||
StringBuilder header = new StringBuilder("<thead" + (color != null ? " class=\"bg-" + color + "\"" : "") + "><tr>");
|
||||
for (String title : this.header) {
|
||||
header.append("<th>").append(title).append("</th>");
|
||||
|
@ -23,7 +23,7 @@ public class PluginsConfigSection {
|
||||
}
|
||||
|
||||
private ConfigNode getPluginsSection() {
|
||||
return ConfigSystem.getInstance().getConfig().getConfigNode("Plugins");
|
||||
return ConfigSystem.getConfig().getConfigNode("Plugins");
|
||||
}
|
||||
|
||||
public void createSection(PluginData dataSource) {
|
||||
|
@ -5,7 +5,7 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.NullCheck;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -57,12 +57,9 @@ public class SessionCache {
|
||||
|
||||
public void cacheSession(UUID uuid, Session session) {
|
||||
activeSessions.put(uuid, session);
|
||||
new Processor<PlanSystem>(system) {
|
||||
@Override
|
||||
public void process() {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> system.getInfoSystem().generateAndCachePlayerPage(uuid));
|
||||
}
|
||||
}.queue();
|
||||
Processor.queue(() -> WebExceptionLogger.logIfOccurs(this.getClass(), () ->
|
||||
system.getInfoSystem().generateAndCachePlayerPage(uuid))
|
||||
);
|
||||
}
|
||||
|
||||
public void endSession(UUID uuid, long time) {
|
||||
|
@ -46,7 +46,7 @@ public abstract class DBSystem implements SubSystem {
|
||||
Benchmark.start("Init Database");
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
initDatabase();
|
||||
db.scheduleClean(10L);
|
||||
db.scheduleClean(1L);
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName()));
|
||||
Benchmark.stop("Enable", "Init Database");
|
||||
} catch (DBInitException e) {
|
||||
@ -60,10 +60,6 @@ public abstract class DBSystem implements SubSystem {
|
||||
return databases;
|
||||
}
|
||||
|
||||
public void setDatabases(Set<Database> databases) {
|
||||
this.databases = databases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
try {
|
||||
|
@ -17,7 +17,7 @@ import com.djrapitops.plan.utilities.NullCheck;
|
||||
*/
|
||||
public abstract class Database {
|
||||
|
||||
private boolean open;
|
||||
protected boolean open = false;
|
||||
|
||||
public static Database getActive() {
|
||||
Database database = DBSystem.getInstance().getActiveDatabase();
|
||||
|
@ -51,7 +51,6 @@ public abstract class SQLDB extends Database {
|
||||
private final SQLTransferOps transferOps;
|
||||
|
||||
private final boolean usingMySQL;
|
||||
private boolean open = false;
|
||||
private ITask dbCleanTask;
|
||||
|
||||
public SQLDB() {
|
||||
@ -103,7 +102,6 @@ public abstract class SQLDB extends Database {
|
||||
try {
|
||||
setupDataSource();
|
||||
setupDatabase();
|
||||
open = true;
|
||||
} finally {
|
||||
Benchmark.stop("Database", benchName);
|
||||
Log.logDebug("Database");
|
||||
@ -229,8 +227,8 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
setStatus("Closed");
|
||||
open = false;
|
||||
setStatus("Closed");
|
||||
Log.logDebug("Database"); // Log remaining Debug info if present
|
||||
if (dbCleanTask != null) {
|
||||
dbCleanTask.cancel();
|
||||
@ -248,6 +246,7 @@ public abstract class SQLDB extends Database {
|
||||
private void clean() throws SQLException {
|
||||
Log.info("Cleaning the database.");
|
||||
tpsTable.clean();
|
||||
transferTable.clean();
|
||||
Log.info("Clean complete.");
|
||||
}
|
||||
|
||||
|
@ -412,12 +412,7 @@ public class ServerTable extends Table {
|
||||
public int getMaxPlayers() throws SQLException {
|
||||
String sql = "SELECT SUM(" + columnMaxPlayers + ") AS max FROM " + tableName;
|
||||
|
||||
return query(new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) {
|
||||
|
||||
}
|
||||
|
||||
return query(new QueryAllStatement<Integer>(sql) {
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
|
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebFailException;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
@ -94,7 +95,8 @@ public abstract class InfoSystem implements SubSystem {
|
||||
|
||||
public abstract void updateNetworkPage() throws WebException;
|
||||
|
||||
public void requestSetUp(String address) {
|
||||
public void requestSetUp(String address) throws WebException {
|
||||
// TODO
|
||||
throw new WebFailException("");
|
||||
}
|
||||
}
|
@ -20,8 +20,6 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -35,10 +33,8 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
||||
private long latestServerMapRefresh;
|
||||
|
||||
private Server mainServer;
|
||||
private Map<UUID, Server> servers;
|
||||
|
||||
public BukkitConnectionSystem() {
|
||||
servers = new HashMap<>();
|
||||
latestServerMapRefresh = 0;
|
||||
}
|
||||
|
||||
@ -48,7 +44,7 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
||||
Database database = Database.getActive();
|
||||
Optional<Server> bungeeInformation = database.fetch().getBungeeInformation();
|
||||
bungeeInformation.ifPresent(server -> mainServer = server);
|
||||
servers = database.fetch().getBukkitServers();
|
||||
bukkitServers = database.fetch().getBukkitServers();
|
||||
latestServerMapRefresh = MiscUtils.getTime();
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
@ -60,7 +56,7 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
||||
protected Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException {
|
||||
refreshServerMap();
|
||||
|
||||
if (mainServer == null && servers.isEmpty()) {
|
||||
if (mainServer == null && bukkitServers.isEmpty()) {
|
||||
throw new NoServersException("No Servers available to process requests.");
|
||||
}
|
||||
|
||||
@ -69,11 +65,11 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
||||
server = mainServer;
|
||||
} else if (infoRequest instanceof GenerateAnalysisPageRequest) {
|
||||
UUID serverUUID = ((GenerateAnalysisPageRequest) infoRequest).getServerUUID();
|
||||
server = servers.get(serverUUID);
|
||||
server = bukkitServers.get(serverUUID);
|
||||
} else if (infoRequest instanceof GenerateInspectPageRequest) {
|
||||
Optional<UUID> serverUUID = getServerWherePlayerIsOnline((GenerateInspectPageRequest) infoRequest);
|
||||
if (serverUUID.isPresent()) {
|
||||
server = servers.getOrDefault(serverUUID.get(), ServerInfo.getServer());
|
||||
server = bukkitServers.getOrDefault(serverUUID.get(), ServerInfo.getServer());
|
||||
}
|
||||
}
|
||||
if (server == null) {
|
||||
@ -84,10 +80,10 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
||||
|
||||
@Override
|
||||
public void sendWideInfoRequest(WideRequest infoRequest) throws NoServersException {
|
||||
if (servers.isEmpty()) {
|
||||
if (bukkitServers.isEmpty()) {
|
||||
throw new NoServersException("No Servers Available to make process request.");
|
||||
}
|
||||
for (Server server : servers.values()) {
|
||||
for (Server server : bukkitServers.values()) {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server));
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -30,17 +28,15 @@ import java.util.UUID;
|
||||
public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
|
||||
private long latestServerMapRefresh;
|
||||
private Map<UUID, Server> servers;
|
||||
|
||||
public BungeeConnectionSystem() {
|
||||
servers = new HashMap<>();
|
||||
latestServerMapRefresh = 0;
|
||||
}
|
||||
|
||||
private void refreshServerMap() {
|
||||
if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.MINUTE.ms() * 2L) {
|
||||
try {
|
||||
servers = Database.getActive().fetch().getBukkitServers();
|
||||
bukkitServers = Database.getActive().fetch().getBukkitServers();
|
||||
latestServerMapRefresh = MiscUtils.getTime();
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
@ -55,11 +51,11 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
throw new NoServersException("Bungee should not send Cache requests.");
|
||||
} else if (infoRequest instanceof GenerateAnalysisPageRequest) {
|
||||
UUID serverUUID = ((GenerateAnalysisPageRequest) infoRequest).getServerUUID();
|
||||
server = servers.get(serverUUID);
|
||||
server = bukkitServers.get(serverUUID);
|
||||
} else if (infoRequest instanceof GenerateInspectPageRequest) {
|
||||
Optional<UUID> serverUUID = getServerWherePlayerIsOnline((GenerateInspectPageRequest) infoRequest);
|
||||
if (serverUUID.isPresent()) {
|
||||
server = servers.getOrDefault(serverUUID.get(), ServerInfo.getServer());
|
||||
server = bukkitServers.getOrDefault(serverUUID.get(), ServerInfo.getServer());
|
||||
}
|
||||
}
|
||||
if (server == null) {
|
||||
@ -70,10 +66,10 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
|
||||
@Override
|
||||
public void sendWideInfoRequest(WideRequest infoRequest) throws NoServersException {
|
||||
if (servers.isEmpty()) {
|
||||
if (bukkitServers.isEmpty()) {
|
||||
throw new NoServersException("No Servers Available to make process request.");
|
||||
}
|
||||
for (Server server : servers.values()) {
|
||||
for (Server server : bukkitServers.values()) {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server));
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +43,8 @@ public class ConnectionLog {
|
||||
}
|
||||
|
||||
Map<String, Entry> serverLog = getInstance().getLog().get(server);
|
||||
if (Verify.isEmpty(serverLog)) {
|
||||
return true;
|
||||
}
|
||||
return Verify.isEmpty(serverLog) || hasConnectionSucceeded(serverLog);
|
||||
|
||||
return hasConnectionSucceeded(serverLog);
|
||||
}
|
||||
|
||||
public static boolean hasConnectionSucceeded(Server server) {
|
||||
@ -55,11 +52,9 @@ public class ConnectionLog {
|
||||
return false;
|
||||
}
|
||||
Map<String, Entry> serverLog = getInstance().getLog().get(server);
|
||||
if (Verify.isEmpty(serverLog)) {
|
||||
return false;
|
||||
}
|
||||
return !Verify.isEmpty(serverLog)
|
||||
&& hasConnectionSucceeded(serverLog);
|
||||
|
||||
return hasConnectionSucceeded(serverLog);
|
||||
}
|
||||
|
||||
private static boolean hasConnectionSucceeded(Map<String, Entry> serverLog) {
|
||||
|
@ -33,10 +33,10 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
|
||||
protected final ConnectionLog connectionLog;
|
||||
protected final Map<String, InfoRequest> dataRequests;
|
||||
protected Map<UUID, Server> servers;
|
||||
protected Map<UUID, Server> bukkitServers;
|
||||
|
||||
public ConnectionSystem() {
|
||||
servers = new HashMap<>();
|
||||
bukkitServers = new HashMap<>();
|
||||
dataRequests = loadDataRequests();
|
||||
connectionLog = new ConnectionLog();
|
||||
}
|
||||
|
@ -8,12 +8,15 @@ import com.djrapitops.plan.api.exceptions.connection.TransferDatabaseException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.webserver.pages.DefaultResponses;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
|
||||
import com.djrapitops.plan.utilities.Base64Util;
|
||||
import com.djrapitops.plan.utilities.file.export.HtmlExport;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Map;
|
||||
@ -63,11 +66,15 @@ public class CacheAnalysisPageRequest implements CacheRequest {
|
||||
try {
|
||||
Map<UUID, String> pages = Database.getActive().transfer().getEncodedServerHtml();
|
||||
|
||||
boolean export = Settings.ANALYSIS_EXPORT.isTrue();
|
||||
for (Map.Entry<UUID, String> entry : pages.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
String html = Base64Util.decode(entry.getValue());
|
||||
|
||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(html));
|
||||
if (export) {
|
||||
Processor.queue(() -> HtmlExport.exportServer(serverUUID));
|
||||
}
|
||||
}
|
||||
} catch (DBException e) {
|
||||
throw new TransferDatabaseException(e);
|
||||
|
@ -8,12 +8,15 @@ import com.djrapitops.plan.api.exceptions.connection.TransferDatabaseException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.webserver.pages.DefaultResponses;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse;
|
||||
import com.djrapitops.plan.utilities.Base64Util;
|
||||
import com.djrapitops.plan.utilities.file.export.HtmlExport;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Map;
|
||||
@ -63,11 +66,15 @@ public class CacheInspectPageRequest implements CacheRequest {
|
||||
try {
|
||||
Map<UUID, String> pages = Database.getActive().transfer().getEncodedPlayerHtml();
|
||||
|
||||
boolean export = Settings.ANALYSIS_EXPORT.isTrue();
|
||||
for (Map.Entry<UUID, String> entry : pages.entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
String html = Base64Util.decode(entry.getValue());
|
||||
|
||||
ResponseCache.cacheResponse(PageId.PLAYER.of(uuid), () -> new InspectPageResponse(uuid, html));
|
||||
if (export) {
|
||||
Processor.queue(() -> HtmlExport.exportPlayer(uuid));
|
||||
}
|
||||
}
|
||||
} catch (DBException e) {
|
||||
throw new TransferDatabaseException(e);
|
||||
|
@ -17,7 +17,7 @@ public class Server {
|
||||
private int id;
|
||||
private String name;
|
||||
private String webAddress;
|
||||
private int maxPlayers = -1;
|
||||
private int maxPlayers;
|
||||
|
||||
public Server(int id, UUID uuid, String name, String webAddress, int maxPlayers) {
|
||||
this.id = id;
|
||||
|
@ -6,7 +6,6 @@ package com.djrapitops.plan.system.info.server;
|
||||
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plugin.api.config.Config;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.io.File;
|
||||
@ -42,28 +41,4 @@ public class ServerInfoFile extends Config {
|
||||
return Optional.of(UUID.fromString(uuidString));
|
||||
}
|
||||
|
||||
public String getBungeeWebAddress() {
|
||||
return getString("Bungee.WebAddress");
|
||||
}
|
||||
|
||||
public int markConnectionFail() {
|
||||
try {
|
||||
int fails = getInt("Bungee.Fail");
|
||||
set("Bungee.Fail", fails + 1);
|
||||
save();
|
||||
return fails;
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void resetConnectionFails() {
|
||||
try {
|
||||
set("Bungee.Fail", 0);
|
||||
save();
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,10 +17,10 @@ public class BukkitListenerSystem extends ListenerSystem {
|
||||
plugin.registerListener(
|
||||
new PlayerOnlineListener(),
|
||||
new ChatListener(),
|
||||
new GamemodeChangeListener(plugin),
|
||||
new GamemodeChangeListener(),
|
||||
new WorldChangeListener(),
|
||||
new CommandPreprocessListener(plugin),
|
||||
new DeathEventListener(plugin)
|
||||
new DeathEventListener()
|
||||
);
|
||||
PlayerOnlineListener.setCountKicks(true);
|
||||
}
|
||||
|
@ -1,18 +1,10 @@
|
||||
package com.djrapitops.plan.system.listeners;
|
||||
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.utilities.NullCheck;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
|
||||
public abstract class ListenerSystem implements SubSystem {
|
||||
|
||||
public static ListenerSystem getInstance() {
|
||||
ListenerSystem listenerSystem = PlanSystem.getInstance().getListenerSystem();
|
||||
NullCheck.check(listenerSystem, new IllegalStateException("Listener system was not initialized."));
|
||||
return listenerSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
Benchmark.start("Register Listeners");
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.djrapitops.plan.system.listeners.bukkit;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.system.processing.processors.player.DeathProcessor;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.processing.processors.player.KillProcessor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -23,17 +24,6 @@ import org.bukkit.projectiles.ProjectileSource;
|
||||
*/
|
||||
public class DeathEventListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public DeathEventListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command use listener.
|
||||
*
|
||||
@ -46,7 +36,8 @@ public class DeathEventListener implements Listener {
|
||||
LivingEntity dead = event.getEntity();
|
||||
|
||||
if (dead instanceof Player) {
|
||||
new DeathProcessor(dead.getUniqueId()).queue();
|
||||
// Process Death
|
||||
Processor.queue(() -> SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(Session::died));
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.system.listeners.bukkit;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
@ -22,17 +21,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public class GamemodeChangeListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public GamemodeChangeListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* GM Change Event Listener.
|
||||
*
|
||||
@ -52,7 +40,7 @@ public class GamemodeChangeListener implements Listener {
|
||||
|
||||
new WorldAliasSettings().addWorld(worldName);
|
||||
|
||||
Optional<Session> cachedSession = SessionCache.getInstance().getCachedSession(uuid);
|
||||
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
|
@ -2,7 +2,7 @@ package com.djrapitops.plan.system.listeners.bukkit;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor;
|
||||
import com.djrapitops.plan.system.processing.processors.player.*;
|
||||
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||
@ -101,7 +101,8 @@ public class PlayerOnlineListener implements Listener {
|
||||
new IPUpdateProcessor(uuid, ip, time),
|
||||
new NameProcessor(uuid, playerName, displayName)
|
||||
),
|
||||
new NetworkPageUpdateProcessor());
|
||||
new NetworkPageUpdateProcessor()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.system.processing;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.utilities.NullCheck;
|
||||
import com.djrapitops.plan.utilities.queue.Consumer;
|
||||
import com.djrapitops.plan.utilities.queue.Queue;
|
||||
@ -98,10 +97,6 @@ class ProcessConsumer extends Consumer<Processor> {
|
||||
Log.toLog(this.getTaskName() + ":" + process.getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearVariables() {
|
||||
}
|
||||
}
|
||||
|
||||
class ProcessSetup extends Setup<Processor> {
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing;
|
||||
|
||||
/**
|
||||
* Interface for ProcessingQueue.
|
||||
* <p>
|
||||
* Allows lambda Processor creation.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public interface Processor {
|
||||
|
||||
static void queueMany(Processor... processors) {
|
||||
ProcessingQueue processingQueue = ProcessingQueue.getInstance();
|
||||
for (Processor processor : processors) {
|
||||
processingQueue.queue(processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A way to run code Async in ProcessingQueue.
|
||||
* <p>
|
||||
* Good for lambdas.
|
||||
*
|
||||
* @param processor Processor.
|
||||
*/
|
||||
static void queue(Processor processor) {
|
||||
ProcessingQueue.getInstance().queue(processor);
|
||||
}
|
||||
|
||||
void process();
|
||||
|
||||
}
|
@ -13,7 +13,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CommandProcessor extends Processor<String> {
|
||||
public class CommandProcessor extends ObjectProcessor<String> {
|
||||
|
||||
public CommandProcessor(String object) {
|
||||
super(object);
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing.processors;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.data.Actions;
|
||||
import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.processing.processors.player.PlayerProcessor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Processor for inserting a Name Change action to the Actions table.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class NewNickActionProcessor extends PlayerProcessor {
|
||||
|
||||
private final String displayName;
|
||||
|
||||
public NewNickActionProcessor(UUID uuid, String displayName) {
|
||||
super(uuid);
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
|
||||
String info = HtmlUtils.removeXSS(displayName);
|
||||
|
||||
Action action = new Action(MiscUtils.getTime(), Actions.NEW_NICKNAME, info);
|
||||
|
||||
try {
|
||||
Database.getActive().save().action(uuid, action);
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,34 +4,27 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing.processors;
|
||||
|
||||
import com.djrapitops.plan.system.processing.ProcessingQueue;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
|
||||
/**
|
||||
* Abstract class for processing different objects using Generics.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class Processor<T> {
|
||||
public abstract class ObjectProcessor<T> implements Processor {
|
||||
protected final T object;
|
||||
|
||||
public Processor(T object) {
|
||||
public ObjectProcessor(T object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public static void queueMany(Processor... processors) {
|
||||
ProcessingQueue processingQueue = ProcessingQueue.getInstance();
|
||||
for (Processor processor : processors) {
|
||||
processingQueue.queue(processor);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void process();
|
||||
|
||||
public T getObject() {
|
||||
protected T getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void queue() {
|
||||
queueMany(this);
|
||||
Processor.queue(this);
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TPSInsertProcessor extends Processor<List<TPS>> {
|
||||
public class TPSInsertProcessor extends ObjectProcessor<List<TPS>> {
|
||||
|
||||
public TPSInsertProcessor(List<TPS> object) {
|
||||
super(object);
|
||||
|
@ -35,7 +35,7 @@ public class InspectCacheRequestProcessor extends PlayerProcessor {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
SessionCache.getInstance().refreshActiveSessionsState();
|
||||
SessionCache.refreshActiveSessionsState();
|
||||
try {
|
||||
InfoSystem.getInstance().generateAndCachePlayerPage(getUUID());
|
||||
sendInspectMsg(sender, playerName);
|
||||
|
@ -6,7 +6,7 @@ package com.djrapitops.plan.system.processing.processors.info;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
/**
|
||||
@ -14,11 +14,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class NetworkPageUpdateProcessor extends Processor<InfoSystem> {
|
||||
|
||||
public NetworkPageUpdateProcessor() {
|
||||
super(null);
|
||||
}
|
||||
public class NetworkPageUpdateProcessor implements Processor {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
|
@ -1,32 +0,0 @@
|
||||
package com.djrapitops.plan.system.processing.processors.player;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Updates death count of the current session.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class DeathProcessor extends PlayerProcessor {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param uuid UUID of the dead player.
|
||||
*/
|
||||
public DeathProcessor(UUID uuid) {
|
||||
super(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
cachedSession.ifPresent(Session::died);
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.system.processing.processors.player;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
@ -44,8 +43,6 @@ public class KillProcessor extends PlayerProcessor {
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
|
||||
Plan plugin = Plan.getInstance();
|
||||
|
||||
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
if (!cachedSession.isPresent()) {
|
||||
return;
|
||||
|
@ -4,13 +4,15 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing.processors.player;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.data.Actions;
|
||||
import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.ProcessingQueue;
|
||||
import com.djrapitops.plan.system.processing.processors.NewNickActionProcessor;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.List;
|
||||
@ -36,7 +38,6 @@ public class NameProcessor extends PlayerProcessor {
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
Plan plugin = Plan.getInstance();
|
||||
DataCache dataCache = DataCache.getInstance();
|
||||
String cachedName = dataCache.getName(uuid);
|
||||
String cachedDisplayName = dataCache.getDisplayName(uuid);
|
||||
@ -64,6 +65,19 @@ public class NameProcessor extends PlayerProcessor {
|
||||
if (nicknames.contains(displayName)) {
|
||||
return;
|
||||
}
|
||||
ProcessingQueue.getInstance().queue(new NewNickActionProcessor(uuid, displayName));
|
||||
|
||||
long time = MiscUtils.getTime();
|
||||
|
||||
Processor.queue(() -> {
|
||||
String info = HtmlUtils.removeXSS(displayName);
|
||||
|
||||
Action action = new Action(time, Actions.NEW_NICKNAME, info);
|
||||
|
||||
try {
|
||||
Database.getActive().save().action(uuid, action);
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing.processors.player;
|
||||
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.system.processing.processors.ObjectProcessor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class PlayerProcessor extends Processor<UUID> {
|
||||
public abstract class PlayerProcessor extends ObjectProcessor<UUID> {
|
||||
|
||||
public PlayerProcessor(UUID uuid) {
|
||||
super(uuid);
|
||||
|
@ -9,7 +9,8 @@ import com.djrapitops.plan.data.Actions;
|
||||
import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.processing.processors.Processor;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.processing.processors.ObjectProcessor;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -25,9 +26,9 @@ public class RegisterProcessor extends PlayerProcessor {
|
||||
private final long time;
|
||||
private final int playersOnline;
|
||||
private final String name;
|
||||
private final Processor[] afterProcess;
|
||||
private final ObjectProcessor[] afterProcess;
|
||||
|
||||
public RegisterProcessor(UUID uuid, long registered, long time, String name, int playersOnline, Processor... afterProcess) {
|
||||
public RegisterProcessor(UUID uuid, long registered, long time, String name, int playersOnline, ObjectProcessor... afterProcess) {
|
||||
super(uuid);
|
||||
this.registered = registered;
|
||||
this.time = time;
|
||||
|
@ -37,7 +37,7 @@ public class WorldAliasSettings {
|
||||
}
|
||||
|
||||
private ConfigNode getAliasSection() {
|
||||
Config config = ConfigSystem.getInstance().getConfig();
|
||||
Config config = ConfigSystem.getConfig();
|
||||
return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public abstract class ConfigSystem implements SubSystem {
|
||||
/**
|
||||
* Copies default values from file in jar to Config.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException If file can't be read or written.
|
||||
*/
|
||||
protected abstract void copyDefaults() throws IOException;
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class Locale {
|
||||
.collect(Collectors.toList());
|
||||
Files.write(FileSystem.getLocaleFile().toPath(), lines, StandardCharsets.UTF_8);
|
||||
|
||||
Config config = ConfigSystem.getInstance().getConfig();
|
||||
Config config = ConfigSystem.getConfig();
|
||||
config.set(Settings.WRITE_NEW_LOCALE.getPath(), false);
|
||||
config.save();
|
||||
}
|
||||
|
@ -46,10 +46,6 @@ public class Request {
|
||||
return target;
|
||||
}
|
||||
|
||||
public boolean isAPIRequest() {
|
||||
return "POST".equals(requestMethod);
|
||||
}
|
||||
|
||||
public InputStream getRequestBody() {
|
||||
return exchange.getRequestBody();
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ public class BasicAuthentication implements Authentication {
|
||||
|
||||
private String authenticationString;
|
||||
|
||||
private WebUser user;
|
||||
|
||||
public BasicAuthentication(String authenticationString) {
|
||||
this.authenticationString = authenticationString;
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ServerPreferencePie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.ServerAccordionCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.ActionsTableCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.GeoInfoTableCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.NicknameTableCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.ActionsTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.GeoInfoTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.NicknameTable;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -85,7 +85,7 @@ public class InspectPage extends Page {
|
||||
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
|
||||
|
||||
String online = "Offline";
|
||||
Optional<Session> activeSession = SessionCache.getInstance().getCachedSession(uuid);
|
||||
Optional<Session> activeSession = SessionCache.getCachedSession(uuid);
|
||||
if (activeSession.isPresent()) {
|
||||
Session session = activeSession.get();
|
||||
session.setSessionID(Integer.MAX_VALUE);
|
||||
@ -116,8 +116,8 @@ public class InspectPage extends Page {
|
||||
String favoriteServer = serverNames.get(profile.getFavoriteServer());
|
||||
addValue("favoriteServer", favoriteServer != null ? favoriteServer : "Unknown");
|
||||
|
||||
addValue("tableBodyNicknames", NicknameTableCreator.createTable(profile.getNicknames(), serverNames));
|
||||
addValue("tableBodyIPs", GeoInfoTableCreator.createTable(profile.getGeoInformation()));
|
||||
addValue("tableBodyNicknames", new NicknameTable(profile.getNicknames(), serverNames).parseBody());
|
||||
addValue("tableBodyIPs", new GeoInfoTable(profile.getGeoInformation()).parseBody());
|
||||
|
||||
Map<UUID, List<Session>> sessions = profile.getSessions();
|
||||
Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
|
||||
@ -186,14 +186,13 @@ public class InspectPage extends Page {
|
||||
addValue("sessionAverageWeek", sessionAverageWeek > 0L ? FormatUtils.formatTimeAmount(sessionAverageWeek) : "-");
|
||||
addValue("sessionAverageMonth", sessionAverageMonth > 0L ? FormatUtils.formatTimeAmount(sessionAverageMonth) : "-");
|
||||
|
||||
|
||||
addValue("sessionCount", sessionCount);
|
||||
addValue("sessionCountDay", sessionCountDay);
|
||||
addValue("sessionCountWeek", sessionCountWeek);
|
||||
addValue("sessionCountMonth", sessionCountMonth);
|
||||
|
||||
List<Action> actions = profile.getAllActions();
|
||||
addValue("tableBodyActions", ActionsTableCreator.createTable(actions));
|
||||
addValue("tableBodyActions", new ActionsTable(actions).parseBody());
|
||||
|
||||
String punchCardData = new PunchCardGraph(allSessions).toHighChartsSeries();
|
||||
WorldTimes worldTimes = profile.getWorldTimes();
|
||||
|
@ -13,8 +13,7 @@ public class ForbiddenResponse extends ErrorResponse {
|
||||
}
|
||||
|
||||
public ForbiddenResponse(String msg) {
|
||||
super.setHeader("HTTP/1.1 403 Forbidden");
|
||||
super.setTitle("403 Forbidden - Access Denied");
|
||||
this();
|
||||
super.setParagraph(msg);
|
||||
super.replacePlaceholders();
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ public class NotFoundResponse extends ErrorResponse {
|
||||
}
|
||||
|
||||
public NotFoundResponse(String msg) {
|
||||
super.setHeader("HTTP/1.1 404 Not Found");
|
||||
super.setTitle("404 Not Found");
|
||||
this();
|
||||
super.setParagraph(msg);
|
||||
super.replacePlaceholders();
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
@ -13,7 +12,6 @@ import com.djrapitops.plan.system.webserver.response.api.BadRequestResponse;
|
||||
import com.djrapitops.plan.system.webserver.response.api.SuccessResponse;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -25,11 +23,8 @@ import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -59,33 +54,6 @@ public abstract class WebAPI {
|
||||
this.variables = new HashMap<>();
|
||||
}
|
||||
|
||||
public static Map<String, String> readVariables(String requestBody) {
|
||||
String[] variables = requestBody.split(";&variable;");
|
||||
|
||||
return Arrays.stream(variables)
|
||||
.map(variable -> variable.split("=", 2))
|
||||
.filter(splitVariables -> splitVariables.length == 2)
|
||||
.collect(Collectors.toMap(splitVariables -> splitVariables[0], splitVariables -> splitVariables[1], (a, b) -> b));
|
||||
}
|
||||
|
||||
public Response processRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
String sender = variables.get("sender");
|
||||
if (sender == null) {
|
||||
Log.debug(getClass().getSimpleName() + ": Sender not Found");
|
||||
return badRequest("Sender not present");
|
||||
} else {
|
||||
try {
|
||||
UUID.fromString(sender);
|
||||
} catch (Exception e) {
|
||||
Log.debug(getClass().getSimpleName() + ": Invalid Sender UUID");
|
||||
return badRequest("Faulty Sender value");
|
||||
}
|
||||
}
|
||||
return onRequest(plugin, variables);
|
||||
}
|
||||
|
||||
public abstract Response onRequest(PlanPlugin plugin, Map<String, String> variables);
|
||||
|
||||
public void sendRequest(String address) throws WebException {
|
||||
Verify.nullCheck(address);
|
||||
|
||||
@ -165,10 +133,6 @@ public abstract class WebAPI {
|
||||
variables.put(key, value);
|
||||
}
|
||||
|
||||
public Map<String, String> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
private SSLSocketFactory getRelaxedSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
@ -179,14 +143,6 @@ public abstract class WebAPI {
|
||||
return ResponseCache.loadResponse(PageId.TRUE.id(), SuccessResponse::new);
|
||||
}
|
||||
|
||||
protected Response fail(String reason) {
|
||||
return ResponseCache.loadResponse(PageId.FALSE.id(), () -> {
|
||||
NotFoundResponse notFoundResponse = new NotFoundResponse("");
|
||||
notFoundResponse.setContent(reason);
|
||||
return notFoundResponse;
|
||||
});
|
||||
}
|
||||
|
||||
protected Response badRequest(String error) {
|
||||
return ResponseCache.loadResponse(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.pages.TreePageHandler;
|
||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann and Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class WebAPIManager extends TreePageHandler {
|
||||
|
||||
private static final Set<String> accessKeys = new HashSet<>();
|
||||
private final Map<String, WebAPI> registry;
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
public WebAPIManager() {
|
||||
registry = new HashMap<>();
|
||||
}
|
||||
|
||||
public void registerNewAPI(WebAPI... api) {
|
||||
for (WebAPI webAPI : api) {
|
||||
registerNewAPI(webAPI);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuthorized(String key) {
|
||||
return accessKeys.contains(key);
|
||||
}
|
||||
|
||||
public void authorize(String key) {
|
||||
accessKeys.remove(key);
|
||||
}
|
||||
|
||||
public String generateNewAccessKey() throws Exception {
|
||||
String key = PassEncryptUtil.createHash(UUID.randomUUID().toString().substring(0, 5)).split(":")[4];
|
||||
accessKeys.add(key);
|
||||
return key;
|
||||
}
|
||||
|
||||
public void registerNewAPI(WebAPI api) {
|
||||
registry.put(api.getClass().getSimpleName().toLowerCase(), api);
|
||||
}
|
||||
|
||||
public <T extends WebAPI> T getAPI(Class<T> api) {
|
||||
WebAPI webAPI = getAPI(api.getSimpleName());
|
||||
return (T) webAPI;
|
||||
}
|
||||
|
||||
public WebAPI getAPI(String apiName) {
|
||||
return registry.get(apiName.toLowerCase());
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bukkit;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class AnalysisReadyWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendRequest(String address, UUID serverUUID) throws WebException {
|
||||
addVariable("serverUUID", serverUUID.toString());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bukkit;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class AnalyzeWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendRequest(String address, UUID serverUUID) throws WebException {
|
||||
addVariable("serverUUID", serverUUID.toString());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -24,9 +24,9 @@ import java.util.UUID;
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
@Deprecated
|
||||
public class ConfigurationWebAPI extends WebAPI {
|
||||
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
if (!Check.isBukkitAvailable()) {
|
||||
Log.debug("Called a wrong server type");
|
||||
@ -42,7 +42,7 @@ public class ConfigurationWebAPI extends WebAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
public void sendRequest(String address) {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bukkit;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class InspectWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
String uuidS = variables.get("uuid");
|
||||
if (uuidS == null) {
|
||||
return badRequest("UUID not included");
|
||||
}
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
|
||||
return fail("WebAPI deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendRequest(String address, UUID uuid) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bukkit;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class IsOnlineWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
String uuidS = variables.get("uuid");
|
||||
if (uuidS == null) {
|
||||
return badRequest("UUID not included");
|
||||
}
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
|
||||
Player player = Plan.getInstance().getServer().getPlayer(uuid);
|
||||
|
||||
if (player != null && player.isOnline()) {
|
||||
return success();
|
||||
} else {
|
||||
return fail("Not Online");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendRequest(String address, UUID uuid) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bukkit;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* WebAPI for requesting Inspect plugins tab contents from a Bukkit Server.
|
||||
* <p>
|
||||
* Call: Bungee to Bukkit
|
||||
* <p>
|
||||
* Bad Requests:
|
||||
* - Called a Bungee Server
|
||||
* - Did not include uuid variable
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class RequestInspectPluginsTabBukkitWebAPI extends WebAPI {
|
||||
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
if (!Check.isBukkitAvailable()) {
|
||||
return badRequest("Called a Bungee Server");
|
||||
}
|
||||
|
||||
String uuidS = variables.get("uuid");
|
||||
if (uuidS == null) {
|
||||
return badRequest("UUID not included");
|
||||
}
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendRequest(String address, UUID uuid) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bungee;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* WebAPI for checking if a page is in webserver cache.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class IsCachedWebAPI extends WebAPI {
|
||||
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
try {
|
||||
return fail("Deprecated");
|
||||
} catch (NullPointerException e) {
|
||||
return badRequest(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public boolean isInspectCached(String address, UUID uuid) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
addVariable("target", "inspectPage");
|
||||
try {
|
||||
super.sendRequest(address);
|
||||
return true;
|
||||
} catch (NotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAnalysisCached(String address, UUID serverUUID) throws WebException {
|
||||
addVariable("serverUUID", serverUUID.toString());
|
||||
addVariable("target", "analysisPage");
|
||||
try {
|
||||
super.sendRequest(address);
|
||||
return true;
|
||||
} catch (NotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bungee;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* WebAPI for posting Html pages such as Inspect or server pages.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class PostHtmlWebAPI extends WebAPI {
|
||||
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendInspectHtml(String address, UUID uuid, String html) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
addVariable("target", "inspectPage");
|
||||
addVariable("html", html);
|
||||
super.sendRequest(address);
|
||||
}
|
||||
|
||||
public void sendAnalysisHtml(String address, String html) throws WebException {
|
||||
addVariable("html", html);
|
||||
addVariable("target", "analysisPage");
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bungee;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* WebAPI for posting Inspect page Plugins tab contents to the Bungee server.
|
||||
* <p>
|
||||
* Call: Bukkit to Bungee
|
||||
* <p>
|
||||
* Bad Requests:
|
||||
* - Did not include uuid
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class PostInspectPluginsTabWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
String uuidS = variables.get("uuid");
|
||||
if (uuidS == null) {
|
||||
return badRequest("uuid not included");
|
||||
}
|
||||
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
UUID serverUUID = UUID.fromString(variables.get("sender"));
|
||||
String nav = variables.get("nav");
|
||||
if (nav == null) {
|
||||
return badRequest("nav not included");
|
||||
}
|
||||
String html = variables.get("html");
|
||||
if (html == null) {
|
||||
return badRequest("html not included");
|
||||
}
|
||||
String[] content = new String[]{nav, html};
|
||||
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendPluginsTab(String address, UUID uuid, String[] html) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
addVariable("nav", html[0]);
|
||||
addVariable("html", html[1]);
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bungee;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class PostNetworkPageContentWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
if (Check.isBukkitAvailable()) {
|
||||
return badRequest("Called a Bukkit server.");
|
||||
}
|
||||
|
||||
UUID serverUUID = UUID.fromString(variables.get("sender"));
|
||||
String html = variables.get("html");
|
||||
if (html == null) {
|
||||
return badRequest("html not present");
|
||||
}
|
||||
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendNetworkContent(String address, String html) throws WebException {
|
||||
addVariable("html", html);
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class PostOriginalBukkitSettingsWebAPI extends WebAPI {
|
||||
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
if (Check.isBukkitAvailable()) {
|
||||
return badRequest("Called a Bukkit Server");
|
||||
@ -45,7 +45,6 @@ public class PostOriginalBukkitSettingsWebAPI extends WebAPI {
|
||||
return success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
addVariable("WebServerPort", Integer.toString(Settings.WEBSERVER_PORT.getNumber()));
|
||||
addVariable("ServerName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bungee;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* WebAPI for requesting Bungee Server to request Plugins tab contents from every server.
|
||||
* <p>
|
||||
* Call: Bukkit to Bungee
|
||||
* <p>
|
||||
* Bad Requests:
|
||||
* - Called a Bukkit Server
|
||||
* - Did not include uuid variable
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RequestPluginsTabWebAPI extends WebAPI {
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
if (!Check.isBungeeAvailable()) {
|
||||
return badRequest("Called a Bukkit Server");
|
||||
}
|
||||
|
||||
String uuidS = variables.get("uuid");
|
||||
if (uuidS == null) {
|
||||
return badRequest("UUID not included");
|
||||
}
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
|
||||
sendRequestsToBukkitServers(plugin, uuid);
|
||||
return success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||
}
|
||||
|
||||
public void sendRequest(String address, UUID uuid) throws WebException {
|
||||
addVariable("uuid", uuid.toString());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
|
||||
public void sendRequestsToBukkitServers(PlanPlugin plugin, UUID uuid) {
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.system.webserver.webapi.bungee;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class RequestSetupWebAPI extends WebAPI {
|
||||
|
||||
@Override
|
||||
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||
return fail("Deprecated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(String address) throws WebException {
|
||||
if (!Check.isBukkitAvailable()) {
|
||||
throw new IllegalStateException("Not supposed to be called on Bungee");
|
||||
}
|
||||
|
||||
Plan plugin = Plan.getInstance();
|
||||
addVariable("webAddress", plugin.getWebServer().getAccessAddress());
|
||||
super.sendRequest(address);
|
||||
}
|
||||
}
|
@ -233,8 +233,8 @@ public class FormatUtils {
|
||||
/**
|
||||
* Gets lines for stack trace recursively.
|
||||
*
|
||||
* @param throwable
|
||||
* @return
|
||||
* @param throwable Throwable element
|
||||
* @return lines of stack trace.
|
||||
*/
|
||||
public static List<String> getStackTrace(Throwable throwable) {
|
||||
List<String> stackTrace = new ArrayList<>();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
@ -32,7 +31,6 @@ public class ManageUtils {
|
||||
* @param copyFromDB Database you want to backup.
|
||||
*/
|
||||
public static void backup(String dbName, Database copyFromDB) throws DBInitException, SQLException {
|
||||
Plan plugin = Plan.getInstance();
|
||||
String timeStamp = new Date().toString().substring(4, 10).replace(" ", "-");
|
||||
String fileName = dbName + "-backup-" + timeStamp;
|
||||
SQLiteDB backupDB = new SQLiteDB(fileName);
|
||||
|
@ -107,7 +107,7 @@ public class MiscUtils {
|
||||
return matches;
|
||||
}
|
||||
|
||||
public static <T> List<T> flatMap(Collection<List<T>> coll) {
|
||||
public static <T> List<T> flatMap(Collection<? extends Collection<T>> coll) {
|
||||
return coll.stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.data.PlayerProfile;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
@ -142,7 +141,6 @@ public class AnalysisUtils {
|
||||
try {
|
||||
// Add 0 time for worlds not present.
|
||||
Set<String> nonZeroWorlds = worldTimes.getWorldTimes().keySet();
|
||||
PlanPlugin plugin = PlanPlugin.getInstance();
|
||||
for (String world : Database.getActive().fetch().getWorldNames(ServerInfo.getServerUUID())) {
|
||||
if (nonZeroWorlds.contains(world)) {
|
||||
continue;
|
||||
|
@ -5,8 +5,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Ramer-Douglas-Peucker Point Reduction Algorithm for reducing points from
|
||||
* graphs.
|
||||
* Ramer-Douglas-Peucker Point Reduction Algorithm Implementation for reducing points from graphs.
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
|
@ -6,7 +6,11 @@
|
||||
package com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
/**
|
||||
* @author ristolah
|
||||
* This math object is used in Ramer–Douglas–Peucker algorithm.
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Line {
|
||||
|
||||
|
@ -3,7 +3,9 @@ package com.djrapitops.plan.utilities.analysis;
|
||||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -153,34 +155,6 @@ public class MathUtils {
|
||||
.sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the biggest Integer in a Collection with Integer as Entry
|
||||
* If the Collection is empty, it will return 1.
|
||||
*
|
||||
* @param values The Collection with Integer as the Entry
|
||||
* @return The biggest Integer
|
||||
* @see #getBiggestLong(Collection)
|
||||
*/
|
||||
public static int getBiggest(Collection<Integer> values) {
|
||||
OptionalInt biggest = values.stream().mapToInt(i -> i).max();
|
||||
|
||||
return biggest.isPresent() ? biggest.getAsInt() : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the biggest Long in a Collection with Long as Entry
|
||||
* If the Collection is empty, it will return 1.
|
||||
*
|
||||
* @param values The Collection with Long as the Entry
|
||||
* @return The biggest Integer
|
||||
* @see #getBiggest(Collection)
|
||||
*/
|
||||
public static long getBiggestLong(Collection<Long> values) {
|
||||
OptionalLong biggest = values.stream().mapToLong(i -> i).max();
|
||||
|
||||
return biggest.isPresent() ? biggest.getAsLong() : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds the double to a double with two digits at the end.
|
||||
* Output: #.##
|
||||
|
@ -31,18 +31,4 @@ public class MapComparator {
|
||||
return sortedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts a Map of String, Long by the Values of the Map.
|
||||
*
|
||||
* @param map Map to sort
|
||||
* @return List with String Array, where first value is the value and second
|
||||
* is the key.
|
||||
*/
|
||||
public static List<String[]> sortByValueLong(Map<String, Long> map) {
|
||||
List<String[]> sortedList = new ArrayList<>();
|
||||
map.keySet().forEach(key -> sortedList.add(new String[]{String.valueOf(map.get(key)), key}));
|
||||
sortedList.sort(Comparator.comparing(strings -> Long.valueOf(strings[0])));
|
||||
return sortedList;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,9 @@ import com.djrapitops.plan.utilities.html.graphs.pie.PieSlice;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Compares PieSlices to descending Percentage order.
|
||||
* Comparator for PieSlices to descending Percentage order.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PieSliceComparator implements Comparator<PieSlice> {
|
||||
|
||||
|
@ -7,7 +7,7 @@ import java.util.Comparator;
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class KillDataComparator implements Comparator<PlayerKill> {
|
||||
public class PlayerKillComparator implements Comparator<PlayerKill> {
|
||||
|
||||
@Override
|
||||
public int compare(PlayerKill o1, PlayerKill o2) {
|
@ -10,7 +10,7 @@ import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparator for UserInfo for Alphabetical Name order.
|
||||
* Comparator for PluginData for Alphabetical Name order.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
@ -10,6 +10,8 @@ import com.djrapitops.plan.utilities.analysis.Point;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparator for Points for ascending x value order.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
|
@ -5,6 +5,8 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparator for Sessions in descending length order.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SessionLengthComparator implements Comparator<Session> {
|
||||
|
@ -5,6 +5,8 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparator for Sessions in descending start order (Latest first).
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SessionStartComparator implements Comparator<Session> {
|
||||
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.file.export;
|
||||
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -29,6 +31,10 @@ public class AnalysisExport extends SpecificExport {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (Check.isBukkitAvailable() && ConnectionSystem.getInstance().isServerAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
exportAvailableServerPage(serverUUID, serverName);
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.PlayersPageResponse;
|
||||
import com.djrapitops.plan.system.webserver.webapi.bungee.PostHtmlWebAPI;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -41,7 +40,7 @@ public class HtmlExport extends SpecificExport {
|
||||
Optional<String> serverName = Database.getActive().fetch().getServerName(serverUUID);
|
||||
serverName.ifPresent(s -> RunnableFactory.createNew(new AnalysisExport(serverUUID, s)).runTaskAsynchronously());
|
||||
} catch (DBException e) {
|
||||
Log.toLog(PostHtmlWebAPI.class.getClass().getName(), e);
|
||||
Log.toLog(HtmlExport.class.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ public class HtmlExport extends SpecificExport {
|
||||
RunnableFactory.createNew(new PlayerExport(playerUUID, playerName)).runTaskAsynchronously();
|
||||
}
|
||||
} catch (DBException e) {
|
||||
Log.toLog(PostHtmlWebAPI.class.getClass().getName(), e);
|
||||
Log.toLog(HtmlExport.class.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.file.export;
|
||||
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -29,6 +31,10 @@ public class PlayerExport extends SpecificExport {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (Check.isBukkitAvailable() && ConnectionSystem.getInstance().isServerAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
exportAvailablePlayerPage(uuid, name);
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
|
@ -103,7 +103,7 @@ public abstract class SpecificExport extends AbsRunnable {
|
||||
.replace("src=\"plugins/", "src=\"../plugins/")
|
||||
.replace("src=\"js/", "src=\"../js/");
|
||||
|
||||
File htmlLocation = null;
|
||||
File htmlLocation;
|
||||
if (usingBungee) {
|
||||
if (serverUUID.equals(ServerInfo.getServerUUID())) {
|
||||
htmlLocation = new File(outputFolder, "network");
|
||||
|
@ -178,15 +178,6 @@ public class HtmlStructure {
|
||||
"})</script>";
|
||||
}
|
||||
|
||||
public static String parseOfflineServerContainer(String oldContent) {
|
||||
if (oldContent == null) {
|
||||
return "";
|
||||
}
|
||||
String[] split = oldContent.split("<p>", 2);
|
||||
String[] split2 = split[1].split("box-footer", 2);
|
||||
return split[0] + "<p>Offline</p></div><div class=\"box-footer" + split2[1];
|
||||
}
|
||||
|
||||
public static String playerStatus(String online, Set<UUID> banned, boolean op) {
|
||||
boolean offline = "offline".equalsIgnoreCase(online);
|
||||
|
||||
|
@ -16,7 +16,7 @@ import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.tables.KillsTableCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.KillsTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -89,7 +89,7 @@ public class SessionTabStructureCreator {
|
||||
|
||||
WorldPie worldPie = new WorldPie(worldTimes);
|
||||
|
||||
String killTable = KillsTableCreator.createTable(session.getPlayerKills());
|
||||
String killTable = new KillsTable(session.getPlayerKills()).parseHtml();
|
||||
|
||||
// Accordion panel header
|
||||
html.append("<div title=\"Session ID: ").append(sessionID)
|
||||
|
@ -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 com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility Class for creating Actions Table for inspect page.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ActionsTable extends TableContainer {
|
||||
|
||||
public ActionsTable(List<Action> actions) {
|
||||
super("Date", "Action", "Info");
|
||||
|
||||
if (actions.isEmpty()) {
|
||||
addRow("No Actions");
|
||||
} else {
|
||||
addValues(actions);
|
||||
}
|
||||
}
|
||||
|
||||
private void addValues(List<Action> actions) {
|
||||
int i = 0;
|
||||
for (Action action : actions) {
|
||||
if (i > 50) {
|
||||
break;
|
||||
}
|
||||
addRow(
|
||||
FormatUtils.formatTimeStampYear(action.getDate()),
|
||||
action.getDoneAction().toString(),
|
||||
HtmlUtils.swapColorsToSpan(action.getAdditionalInfo())
|
||||
);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility Class for creating Actions Table for inspect page.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ActionsTableCreator {
|
||||
|
||||
|
||||
public ActionsTableCreator() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static String createTable(List<Action> actions) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
if (actions.isEmpty()) {
|
||||
html.append(Html.TABLELINE_3.parse("No Actions", "-", "-"));
|
||||
} else {
|
||||
int i = 0;
|
||||
for (Action action : actions) {
|
||||
if (i >= 100) {
|
||||
break;
|
||||
}
|
||||
|
||||
long date = action.getDate();
|
||||
|
||||
html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse(
|
||||
String.valueOf(date), FormatUtils.formatTimeStampYear(date),
|
||||
action.getDoneAction().toString(),
|
||||
HtmlUtils.swapColorsToSpan(action.getAdditionalInfo())
|
||||
));
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return html.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.utilities.comparators.MapComparator;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CommandUseTable extends TableContainer {
|
||||
|
||||
public CommandUseTable(Map<String, Integer> commandUse) {
|
||||
super("Command", "Times Used");
|
||||
|
||||
if (commandUse.isEmpty()) {
|
||||
addRow("No Commands");
|
||||
} else {
|
||||
addValues(commandUse);
|
||||
}
|
||||
}
|
||||
|
||||
private void addValues(Map<String, Integer> commandUse) {
|
||||
List<String[]> sorted = MapComparator.sortByValue(commandUse);
|
||||
Collections.reverse(sorted);
|
||||
|
||||
int i = 0;
|
||||
for (String[] values : sorted) {
|
||||
if (i >= 500) {
|
||||
break;
|
||||
}
|
||||
String command = HtmlUtils.removeXSS(values[1]);
|
||||
addRow(command, values[0]);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.utilities.comparators.MapComparator;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CommandUseTableCreator {
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
private CommandUseTableCreator() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commandUse The commands and the amount of times casted
|
||||
* @return The created command use table
|
||||
*/
|
||||
public static String createTable(Map<String, Integer> commandUse) {
|
||||
List<String[]> sorted = MapComparator.sortByValue(commandUse);
|
||||
|
||||
StringBuilder html = new StringBuilder();
|
||||
if (sorted.isEmpty()) {
|
||||
html.append(Html.TABLELINE_2.parse("No Commands", ""));
|
||||
} else {
|
||||
Collections.reverse(sorted);
|
||||
int i = 0;
|
||||
for (String[] values : sorted) {
|
||||
if (i >= 500) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
html.append(Html.TABLELINE_2.parse(values[1], values[0]));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.toLog("CommandUseTable - Cause: " + values[0] + " " + values[1], e);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility Class for creating IP Table for inspect page.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GeoInfoTable extends TableContainer {
|
||||
|
||||
public GeoInfoTable(List<GeoInfo> geoInfo) {
|
||||
super("IP", "Geolocation", "Last Used");
|
||||
|
||||
if (geoInfo.isEmpty()) {
|
||||
addRow("No Connections");
|
||||
} else {
|
||||
addValues(geoInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void addValues(List<GeoInfo> geoInfo) {
|
||||
for (GeoInfo info : geoInfo) {
|
||||
long date = info.getLastUsed();
|
||||
addRow(
|
||||
FormatUtils.formatIP(info.getIp()),
|
||||
info.getGeolocation(),
|
||||
date != 0 ? FormatUtils.formatTimeStampYear(date) : "-"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user