Export of /player pages

This commit is contained in:
Rsl1122 2019-09-01 17:57:39 +03:00
parent 3a3ba7e801
commit 8a5656e9dc
17 changed files with 300 additions and 348 deletions

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.gathering.listeners.bukkit; package com.djrapitops.plan.gathering.listeners.bukkit;
import com.djrapitops.plan.delivery.domain.Nickname; import com.djrapitops.plan.delivery.domain.Nickname;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.extension.CallEvents; import com.djrapitops.plan.extension.CallEvents;
@ -28,9 +29,9 @@ import com.djrapitops.plan.gathering.domain.Session;
import com.djrapitops.plan.gathering.listeners.Status; import com.djrapitops.plan.gathering.listeners.Status;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.processing.Processing;
import com.djrapitops.plan.processing.processors.Processors;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.transactions.events.*; import com.djrapitops.plan.storage.database.transactions.events.*;
@ -57,11 +58,11 @@ import java.util.UUID;
public class PlayerOnlineListener implements Listener { public class PlayerOnlineListener implements Listener {
private final PlanConfig config; private final PlanConfig config;
private final Processors processors;
private final Processing processing; private final Processing processing;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService; private final ExtensionServiceImplementation extensionService;
private final Exporter exporter;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final NicknameCache nicknameCache; private final NicknameCache nicknameCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
@ -71,11 +72,11 @@ public class PlayerOnlineListener implements Listener {
@Inject @Inject
public PlayerOnlineListener( public PlayerOnlineListener(
PlanConfig config, PlanConfig config,
Processors processors,
Processing processing, Processing processing,
ServerInfo serverInfo, ServerInfo serverInfo,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService, ExtensionServiceImplementation extensionService,
Exporter exporter,
GeolocationCache geolocationCache, GeolocationCache geolocationCache,
NicknameCache nicknameCache, NicknameCache nicknameCache,
SessionCache sessionCache, SessionCache sessionCache,
@ -83,11 +84,11 @@ public class PlayerOnlineListener implements Listener {
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
this.config = config; this.config = config;
this.processors = processors;
this.processing = processing; this.processing = processing;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService; this.extensionService = extensionService;
this.exporter = exporter;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.nicknameCache = nicknameCache; this.nicknameCache = nicknameCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
@ -181,8 +182,10 @@ public class PlayerOnlineListener implements Listener {
(uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid)) (uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid))
)); ));
processing.submitNonCritical(processors.info().playerPageExportProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN)); processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
@ -205,6 +208,7 @@ public class PlayerOnlineListener implements Listener {
private void actOnQuitEvent(PlayerQuitEvent event) { private void actOnQuitEvent(PlayerQuitEvent event) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Player player = event.getPlayer(); Player player = event.getPlayer();
String playerName = player.getName();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
UUID serverUUID = serverInfo.getServerUUID(); UUID serverUUID = serverInfo.getServerUUID();
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID); JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
@ -219,6 +223,8 @@ public class PlayerOnlineListener implements Listener {
sessionCache.endSession(playerUUID, time) sessionCache.endSession(playerUUID, time)
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession))); .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
processing.submit(processors.info().playerPageExportProcessor(playerUUID)); if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
} }
} }

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.gathering.listeners.bungee; package com.djrapitops.plan.gathering.listeners.bungee;
import com.djrapitops.plan.delivery.domain.keys.SessionKeys; import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.extension.CallEvents; import com.djrapitops.plan.extension.CallEvents;
@ -26,9 +27,9 @@ import com.djrapitops.plan.gathering.cache.SessionCache;
import com.djrapitops.plan.gathering.domain.Session; import com.djrapitops.plan.gathering.domain.Session;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.processing.Processing;
import com.djrapitops.plan.processing.processors.Processors;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction;
@ -55,10 +56,10 @@ import java.util.UUID;
public class PlayerOnlineListener implements Listener { public class PlayerOnlineListener implements Listener {
private final PlanConfig config; private final PlanConfig config;
private final Processors processors;
private final Processing processing; private final Processing processing;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService; private final ExtensionServiceImplementation extensionService;
private final Exporter exporter;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -67,20 +68,19 @@ public class PlayerOnlineListener implements Listener {
@Inject @Inject
public PlayerOnlineListener( public PlayerOnlineListener(
PlanConfig config, PlanConfig config,
Processors processors,
Processing processing, Processing processing,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService, ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, Exporter exporter, GeolocationCache geolocationCache,
SessionCache sessionCache, SessionCache sessionCache,
ServerInfo serverInfo, ServerInfo serverInfo,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
this.config = config; this.config = config;
this.processors = processors;
this.processing = processing; this.processing = processing;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService; this.extensionService = extensionService;
this.exporter = exporter;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -116,8 +116,10 @@ public class PlayerOnlineListener implements Listener {
} }
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName)); database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
processing.submit(processors.info().playerPageExportProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN)); processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
UUID serverUUID = serverInfo.getServerUUID(); UUID serverUUID = serverInfo.getServerUUID();
JSONCache.invalidateMatching(DataID.SERVER_OVERVIEW); JSONCache.invalidateMatching(DataID.SERVER_OVERVIEW);
@ -144,11 +146,13 @@ public class PlayerOnlineListener implements Listener {
private void actOnLogout(PlayerDisconnectEvent event) { private void actOnLogout(PlayerDisconnectEvent event) {
ProxiedPlayer player = event.getPlayer(); ProxiedPlayer player = event.getPlayer();
String playerName = player.getName();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
sessionCache.endSession(playerUUID, System.currentTimeMillis()); sessionCache.endSession(playerUUID, System.currentTimeMillis());
processing.submit(processors.info().playerPageExportProcessor(playerUUID)); if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
processing.submit(() -> { processing.submit(() -> {
JSONCache.invalidateMatching( JSONCache.invalidateMatching(
DataID.SERVER_OVERVIEW, DataID.SERVER_OVERVIEW,
@ -179,6 +183,7 @@ public class PlayerOnlineListener implements Listener {
private void actOnServerSwitch(ServerSwitchEvent event) { private void actOnServerSwitch(ServerSwitchEvent event) {
ProxiedPlayer player = event.getPlayer(); ProxiedPlayer player = event.getPlayer();
String playerName = player.getName();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
@ -186,7 +191,9 @@ public class PlayerOnlineListener implements Listener {
Session session = new Session(playerUUID, serverInfo.getServerUUID(), time, null, null); Session session = new Session(playerUUID, serverInfo.getServerUUID(), time, null, null);
session.putRawData(SessionKeys.SERVER_NAME, "Proxy Server"); session.putRawData(SessionKeys.SERVER_NAME, "Proxy Server");
sessionCache.cacheSession(playerUUID, session); sessionCache.cacheSession(playerUUID, session);
processing.submit(processors.info().playerPageExportProcessor(playerUUID)); if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
JSONCache.invalidate(DataID.SERVERS); JSONCache.invalidate(DataID.SERVERS);
} }

View File

@ -17,8 +17,9 @@
package com.djrapitops.plan.commands.subcommands; package com.djrapitops.plan.commands.subcommands;
import com.djrapitops.plan.PlanSystem; import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.delivery.export.HtmlExport; import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.delivery.webserver.WebServer;
import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.exceptions.database.DBOpException;
import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
@ -53,7 +54,7 @@ public class AnalyzeCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Processing processing; private final Processing processing;
private final HtmlExport export; private final Exporter exporter;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final WebServer webServer; private final WebServer webServer;
private final DBSystem dbSystem; private final DBSystem dbSystem;
@ -63,7 +64,7 @@ public class AnalyzeCommand extends CommandNode {
public AnalyzeCommand( public AnalyzeCommand(
Locale locale, Locale locale,
Processing processing, Processing processing,
HtmlExport export, Exporter exporter,
ServerInfo serverInfo, ServerInfo serverInfo,
WebServer webServer, WebServer webServer,
DBSystem dbSystem, DBSystem dbSystem,
@ -73,7 +74,7 @@ public class AnalyzeCommand extends CommandNode {
this.locale = locale; this.locale = locale;
this.processing = processing; this.processing = processing;
this.export = export; this.exporter = exporter;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.webServer = webServer; this.webServer = webServer;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
@ -97,9 +98,9 @@ public class AnalyzeCommand extends CommandNode {
try { try {
Server server = getServer(args); Server server = getServer(args);
sendWebUserNotificationIfNecessary(sender); sendWebUserNotificationIfNecessary(sender);
export.exportServer(server); // TODO exporter.exportServerPage(server);
sendLink(server, sender); sendLink(server, sender);
} catch (DBOpException e) { } catch (DBOpException | ExportException e) {
sender.sendMessage("§cError occurred: " + e.toString()); sender.sendMessage("§cError occurred: " + e.toString());
errorHandler.log(L.ERROR, this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} }

View File

@ -16,8 +16,10 @@
*/ */
package com.djrapitops.plan.commands.subcommands.manage; package com.djrapitops.plan.commands.subcommands.manage;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.export.HtmlExport; import com.djrapitops.plan.delivery.export.HtmlExport;
import com.djrapitops.plan.delivery.export.JSONExport; import com.djrapitops.plan.delivery.export.JSONExport;
import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.processing.Processing;
import com.djrapitops.plan.settings.Permissions; import com.djrapitops.plan.settings.Permissions;
@ -57,6 +59,7 @@ public class ManageExportCommand extends CommandNode {
private final PlanConfig config; private final PlanConfig config;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final Exporter exporter;
private final HtmlExport htmlExport; private final HtmlExport htmlExport;
private final JSONExport jsonExport; private final JSONExport jsonExport;
private final Processing processing; private final Processing processing;
@ -68,6 +71,7 @@ public class ManageExportCommand extends CommandNode {
PlanConfig config, PlanConfig config,
DBSystem dbSystem, DBSystem dbSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
Exporter exporter,
Processing processing, Processing processing,
HtmlExport htmlExport, HtmlExport htmlExport,
JSONExport jsonExport JSONExport jsonExport
@ -79,6 +83,7 @@ public class ManageExportCommand extends CommandNode {
this.config = config; this.config = config;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.exporter = exporter;
this.htmlExport = htmlExport; this.htmlExport = htmlExport;
this.jsonExport = jsonExport; this.jsonExport = jsonExport;
this.processing = processing; this.processing = processing;
@ -138,13 +143,15 @@ public class ManageExportCommand extends CommandNode {
processing.submitNonCritical(() -> { processing.submitNonCritical(() -> {
Map<UUID, String> players = dbSystem.getDatabase().query(UserIdentifierQueries.fetchAllPlayerNames()); Map<UUID, String> players = dbSystem.getDatabase().query(UserIdentifierQueries.fetchAllPlayerNames());
int size = players.size(); int size = players.size();
int failed = 0;
int i = 1; int i = 1;
for (Map.Entry<UUID, String> entry : players.entrySet()) { for (Map.Entry<UUID, String> entry : players.entrySet()) {
if (exportPlayerJSON) { try {
jsonExport.exportPlayerJSON(entry.getKey()); if (exportPlayerJSON) jsonExport.exportPlayerJSON(entry.getKey());
} if (exportPlayerHTML) exporter.exportPlayerPage(entry.getKey(), entry.getValue());
if (exportPlayerHTML) { } catch (ExportException e) {
htmlExport.exportPlayerPage(entry.getKey(), entry.getValue()); failed++;
} }
i++; i++;
if (i % 1000 == 0) { if (i % 1000 == 0) {
@ -152,6 +159,11 @@ public class ManageExportCommand extends CommandNode {
} }
} }
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
if (failed != 0) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL));
sender.sendMessage(" §2✔: §f" + (i - failed));
sender.sendMessage(" §c✕: §f" + failed);
}
}); });
} }
} }

View File

@ -43,6 +43,7 @@ public class Exporter {
private final PlanFiles files; private final PlanFiles files;
private final PlanConfig config; private final PlanConfig config;
private final PlayerPageExporter playerPageExporter;
private final ServerPageExporter serverPageExporter; private final ServerPageExporter serverPageExporter;
private final NetworkPageExporter networkPageExporter; private final NetworkPageExporter networkPageExporter;
@ -52,11 +53,13 @@ public class Exporter {
public Exporter( public Exporter(
PlanFiles files, PlanFiles files,
PlanConfig config, PlanConfig config,
PlayerPageExporter playerPageExporter,
ServerPageExporter serverPageExporter, ServerPageExporter serverPageExporter,
NetworkPageExporter networkPageExporter NetworkPageExporter networkPageExporter
) { ) {
this.files = files; this.files = files;
this.config = config; this.config = config;
this.playerPageExporter = playerPageExporter;
this.serverPageExporter = serverPageExporter; this.serverPageExporter = serverPageExporter;
this.networkPageExporter = networkPageExporter; this.networkPageExporter = networkPageExporter;
@ -74,12 +77,12 @@ public class Exporter {
* Export a page of a server. * Export a page of a server.
* *
* @param server Server which page is going to be exported * @param server Server which page is going to be exported
* @return false if the page was not exported due to previous failure. * @return false if the page was not exported due to previous failure or is disabled in config.
* @throws ExportException If the export failed * @throws ExportException If the export failed due to IO, NotFound or ParseException.
*/ */
public boolean exportServerPage(Server server) throws ExportException { public boolean exportServerPage(Server server) throws ExportException {
UUID serverUUID = server.getUuid(); UUID serverUUID = server.getUuid();
if (failedServers.contains(serverUUID)) return false; if (failedServers.contains(serverUUID) || !config.get(ExportSettings.SERVER_PAGE)) return false;
try { try {
Path toDirectory = getPageExportDirectory(); Path toDirectory = getPageExportDirectory();
@ -94,4 +97,24 @@ public class Exporter {
throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.getMessage(), e); throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.getMessage(), e);
} }
} }
/**
* Export page of a player.
*
* @param playerUUID UUID of the player.
* @param playerName Name of the player.
* @return false if the page was not exported due to config settings.
* @throws ExportException If the export failed due to IO, NotFound or ParseException.
*/
public boolean exportPlayerPage(UUID playerUUID, String playerName) throws ExportException {
Path toDirectory = getPageExportDirectory();
if (!config.get(ExportSettings.PLAYER_PAGES)) return false;
try {
playerPageExporter.export(toDirectory, playerUUID, playerName);
return true;
} catch (IOException | NotFoundException | ParseException e) {
throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e);
}
}
} }

View File

@ -17,23 +17,14 @@
package com.djrapitops.plan.delivery.export; package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.delivery.rendering.json.JSONFactory; import com.djrapitops.plan.delivery.rendering.json.JSONFactory;
import com.djrapitops.plan.delivery.rendering.pages.NetworkPage;
import com.djrapitops.plan.delivery.rendering.pages.PageFactory; import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
import com.djrapitops.plan.delivery.rendering.pages.PlayerPage;
import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.exceptions.ParseException; import com.djrapitops.plan.exceptions.ParseException;
import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.exceptions.database.DBOpException;
import com.djrapitops.plan.gathering.domain.BaseUser;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ExportSettings; import com.djrapitops.plan.settings.config.paths.ExportSettings;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.objects.BaseUserQueries;
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries;
import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -45,8 +36,8 @@ import javax.inject.Singleton;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.util.Arrays;
import java.util.*; import java.util.List;
/** /**
* Class responsible for Html Export task. * Class responsible for Html Export task.
@ -92,50 +83,6 @@ public class HtmlExport extends SpecificExport {
return config.get(ExportSettings.HTML_EXPORT_PATH); return config.get(ExportSettings.HTML_EXPORT_PATH);
} }
public void exportServer(Server server) {
Database database = dbSystem.getDatabase();
// boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
// if (serverInfo.getServer().isNotProxy() && hasProxy) {
// return;
// }
try {
exporter.exportServerPage(server);
} catch (ExportException e) {
errorHandler.log(L.WARN, this.getClass(), e);
}
}
public void exportPlayerPage(UUID playerUUID) {
Optional<String> name = dbSystem.getDatabase().query(UserIdentifierQueries.fetchPlayerNameOf(playerUUID));
exportPlayerPage(playerUUID, name.orElse("Unknown"));
}
public void exportPlayerPage(UUID playerUUID, String playerName) {
PlayerPage playerPage = pageFactory.playerPage(playerUUID);
try {
exportPlayerPage(playerName, playerPage.toHtml());
} catch (ParseException | IOException e) {
errorHandler.log(L.ERROR, this.getClass(), e);
}
}
public void exportCachedPlayerPage(UUID playerUUID) {
Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return;
}
database.query(UserIdentifierQueries.fetchPlayerNameOf(playerUUID))
.ifPresent(playerName -> {
try {
exportAvailablePlayerPage(playerUUID, playerName);
} catch (IOException e) {
errorHandler.log(L.WARN, this.getClass(), e);
}
});
}
public void exportPlayersPage() { public void exportPlayersPage() {
try { try {
String html = pageFactory.playersPage().toHtml() String html = pageFactory.playersPage().toHtml()
@ -155,58 +102,4 @@ public class HtmlExport extends SpecificExport {
} }
} }
public void exportAvailablePlayers() {
try {
Collection<BaseUser> users = dbSystem.getDatabase().query(BaseUserQueries.fetchAllBaseUsers());
for (BaseUser user : users) {
exportAvailablePlayerPage(user.getUuid(), user.getName());
}
} catch (IOException | DBOpException e) {
errorHandler.log(L.WARN, this.getClass(), e);
}
}
public void exportNetworkPage() {
if (serverInfo.getServer().isNotProxy()) {
return;
}
NetworkPage networkPage = pageFactory.networkPage();
// TODO
}
private void copyFromJar(String[] resources) {
for (String resource : resources) {
try {
copyFromJar(resource);
} catch (IOException e) {
errorHandler.log(L.WARN, this.getClass(), e);
}
}
}
private void copyFromJar(String resource) throws IOException {
List<String> lines = files.getCustomizableResourceOrDefault(resource).asLines();
File to = new File(getFolder(), resource.replace("web/", "").replace("/", File.separator));
File locationFolder = to.getParentFile();
Verify.isTrue(locationFolder.exists() && locationFolder.isDirectory() || locationFolder.mkdirs(),
() -> new FileNotFoundException("Output folder could not be created at" + locationFolder.getAbsolutePath()));
if (to.exists()) {
Files.delete(to.toPath());
if (!to.createNewFile()) {
return;
}
}
export(to, lines);
}
public void exportAvailableServerPages() {
for (Server server : dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection())) {
exportServer(server);
}
}
} }

View File

@ -0,0 +1,188 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.delivery.rendering.pages.Page;
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
import com.djrapitops.plan.delivery.webserver.RequestTarget;
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONHandler;
import com.djrapitops.plan.delivery.webserver.response.Response;
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
import com.djrapitops.plan.exceptions.ParseException;
import com.djrapitops.plan.exceptions.connection.NotFoundException;
import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.util.UUID;
/**
* Handles exporting of /player page html, data and resources.
*
* @author Rsl1122
*/
@Singleton
public class PlayerPageExporter extends FileExporter {
private final PlanFiles files;
private final PageFactory pageFactory;
private final RootJSONHandler jsonHandler;
private final Locale locale;
private final Theme theme;
private final ExportPaths exportPaths;
@Inject
public PlayerPageExporter(
PlanFiles files,
PageFactory pageFactory,
RootJSONHandler jsonHandler,
Locale locale,
Theme theme
) {
this.files = files;
this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler;
this.locale = locale;
this.theme = theme;
exportPaths = new ExportPaths();
}
public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException, NotFoundException, ParseException {
exportRequiredResources(toDirectory);
Path playerDirectory = toDirectory.resolve("player/" + toFileName(playerName));
exportJSON(playerDirectory, playerUUID);
exportHtml(playerDirectory, playerUUID);
}
private void exportHtml(Path playerDirectory, UUID playerUUID) throws IOException, ParseException, NotFoundException {
Path to = playerDirectory.resolve("index.html");
try {
Page page = pageFactory.playerPage(playerUUID);
export(to, exportPaths.resolveExportPaths(locale.replaceMatchingLanguage(page.toHtml())));
} catch (IllegalStateException notFound) {
throw new NotFoundException(notFound.getMessage());
}
}
private void exportJSON(Path toDirectory, UUID playerUUID) throws IOException, NotFoundException {
exportJSON(toDirectory, "player?player=" + playerUUID);
}
private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException {
Response found = getJSONResponse(resource);
if (found instanceof ErrorResponse) {
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
}
String jsonResourceName = toFileName(toJSONResourceName(resource)) + ".json";
export(toDirectory.resolve(jsonResourceName), found.getContent());
exportPaths.put("../v1/" + resource, "./" + jsonResourceName);
}
private String toJSONResourceName(String resource) {
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
}
private Response getJSONResponse(String resource) {
try {
return jsonHandler.getResponse(null, new RequestTarget(URI.create(resource)));
} catch (WebException e) {
// The rest of the exceptions should not be thrown
throw new IllegalStateException("Unexpected exception thrown: " + e.toString(), e);
}
}
private void exportRequiredResources(Path toDirectory) throws IOException {
exportImage(toDirectory, "img/Flaticon_circle.png");
// Style
exportResources(toDirectory,
"css/sb-admin-2.css",
"css/style.css",
"vendor/jquery/jquery.min.js",
"vendor/bootstrap/js/bootstrap.bundle.min.js",
"vendor/jquery-easing/jquery.easing.min.js",
"vendor/datatables/jquery.dataTables.min.js",
"vendor/datatables/dataTables.bootstrap4.min.js",
"vendor/highcharts/highstock.js",
"vendor/highcharts/map.js",
"vendor/highcharts/world.js",
"vendor/highcharts/drilldown.js",
"vendor/highcharts/highcharts-more.js",
"vendor/highcharts/no-data-to-display.js",
"vendor/fullcalendar/fullcalendar.min.css",
"vendor/momentjs/moment.js",
"vendor/fullcalendar/fullcalendar.min.js",
"js/sb-admin-2.js",
"js/xmlhttprequests.js",
"js/color-selector.js",
"js/sessionAccordion.js",
"js/graphs.js",
"js/player-values.js"
);
}
private void exportResources(Path toDirectory, String... resourceNames) throws IOException {
for (String resourceName : resourceNames) {
exportResource(toDirectory, resourceName);
}
}
private void exportResource(Path toDirectory, String resourceName) throws IOException {
Resource resource = files.getCustomizableResourceOrDefault("web/" + resourceName);
Path to = toDirectory.resolve(resourceName);
if (resourceName.endsWith(".css")) {
export(to, theme.replaceThemeColors(resource.asString()));
} else {
export(to, resource.asLines());
}
exportPaths.put(resourceName, toRelativePathFromRoot(resourceName));
}
private void exportImage(Path toDirectory, String resourceName) throws IOException {
Resource resource = files.getCustomizableResourceOrDefault("web/" + resourceName);
Path to = toDirectory.resolve(resourceName);
export(to, resource);
exportPaths.put(resourceName, toRelativePathFromRoot(resourceName));
}
private String toRelativePathFromRoot(String resourceName) {
// Player html is exported at /player/<name>/index.html
return "../../" + toNonRelativePath(resourceName);
}
private String toNonRelativePath(String resourceName) {
return StringUtils.remove(resourceName, "../");
}
}

View File

@ -85,7 +85,7 @@ public class ServerPageExporter extends FileExporter {
private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException, ParseException { private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException, ParseException {
UUID serverUUID = server.getUuid(); UUID serverUUID = server.getUuid();
Path to = toDirectory Path to = toDirectory
.resolve(serverInfo.getServer().isProxy() ? "server/" + server.getName() : "server") .resolve(serverInfo.getServer().isProxy() ? "server/" + toFileName(server.getName()) : "server")
.resolve("index.html"); .resolve("index.html");
Page page = pageFactory.serverPage(serverUUID); Page page = pageFactory.serverPage(serverUUID);

View File

@ -17,20 +17,16 @@
package com.djrapitops.plan.delivery.export; package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.delivery.rendering.json.JSONFactory; import com.djrapitops.plan.delivery.rendering.json.JSONFactory;
import com.djrapitops.plan.delivery.webserver.response.Response;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.storage.file.PlanFiles;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* Abstract Html Export Task. * Abstract Html Export Task.
@ -79,35 +75,10 @@ public abstract class SpecificExport {
Files.write(to.toPath(), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE); Files.write(to.toPath(), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE);
} }
File getServerFolder() {
File server = new File(getFolder(), "server");
server.mkdirs();
return server;
}
File getPlayerFolder() { File getPlayerFolder() {
File player = new File(getFolder(), "player"); File player = new File(getFolder(), "player");
player.mkdirs(); player.mkdirs();
return player; return player;
} }
void exportPlayerPage(String playerName, String html) throws IOException {
List<String> lines = Arrays.asList(html.replace("../", "../../").split("\n"));
File htmlLocation = new File(getPlayerFolder(), URLEncoder.encode(playerName, "UTF-8").replace(".", "%2E"));
htmlLocation.mkdirs();
File exportFile = new File(htmlLocation, "index.html");
export(exportFile, lines);
}
void exportAvailablePlayerPage(UUID playerUUID, String name) throws IOException {
Response response = null; // TODO
if (response == null) {
return;
}
String html = response.getContent();
exportPlayerPage(name, html);
}
} }

View File

@ -23,10 +23,6 @@ package com.djrapitops.plan.exceptions;
*/ */
public class ExportException extends Exception { public class ExportException extends Exception {
public ExportException(String message) {
super(message);
}
public ExportException(String message, Throwable cause) { public ExportException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -1,44 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.processing.processors;
import com.djrapitops.plan.processing.processors.info.InfoProcessors;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* Factory for creating Runnables to run with {@link com.djrapitops.plan.processing.Processing}.
*
* @author Rsl1122
*/
@Singleton
public class Processors {
private final InfoProcessors infoProcessors;
@Inject
public Processors(
InfoProcessors infoProcessors
) {
this.infoProcessors = infoProcessors;
}
public InfoProcessors info() {
return infoProcessors;
}
}

View File

@ -1,55 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.processing.processors.info;
import com.djrapitops.plan.delivery.export.HtmlExport;
import com.djrapitops.plan.delivery.export.JSONExport;
import com.djrapitops.plan.settings.config.PlanConfig;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.UUID;
/**
* Factory for creating Runnables related to ... to run with {@link com.djrapitops.plan.processing.Processing}.
*
* @author Rsl1122
*/
@Singleton
public class InfoProcessors {
private final Lazy<PlanConfig> config;
private final Lazy<HtmlExport> htmlExport;
private final Lazy<JSONExport> jsonExport;
@Inject
public InfoProcessors(
Lazy<PlanConfig> config,
Lazy<HtmlExport> htmlExport,
Lazy<JSONExport> jsonExport
) {
this.config = config;
this.htmlExport = htmlExport;
this.jsonExport = jsonExport;
}
// TODO Remove after Export has been rewritten to have update methods
public PlayerPageExportProcessor playerPageExportProcessor(UUID uuid) {
return new PlayerPageExportProcessor(uuid, config.get(), htmlExport.get(), jsonExport.get());
}
}

View File

@ -1,57 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.processing.processors.info;
import com.djrapitops.plan.delivery.export.HtmlExport;
import com.djrapitops.plan.delivery.export.JSONExport;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import java.util.UUID;
public class PlayerPageExportProcessor implements Runnable {
private final UUID playerUUID;
private final PlanConfig config;
private final HtmlExport htmlExport;
private final JSONExport jsonExport;
PlayerPageExportProcessor(
UUID playerUUID,
PlanConfig config,
HtmlExport htmlExport,
JSONExport jsonExport
) {
this.playerUUID = playerUUID;
this.config = config;
this.htmlExport = htmlExport;
this.jsonExport = jsonExport;
}
@Override
public void run() {
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
if (config.get(ExportSettings.PLAYER_JSON)) {
jsonExport.exportPlayerJSON(playerUUID);
}
if (config.get(ExportSettings.PLAYER_PAGES)) {
htmlExport.exportPlayerPage(playerUUID);
}
}
}
}

View File

@ -36,7 +36,6 @@ public class TimeSettings {
public static final Setting<Long> DELETE_INACTIVE_PLAYERS_AFTER = new TimeSetting("Time.Thresholds.Remove_inactive_player_data_after"); public static final Setting<Long> DELETE_INACTIVE_PLAYERS_AFTER = new TimeSetting("Time.Thresholds.Remove_inactive_player_data_after");
public static final Setting<Long> DELETE_TPS_DATA_AFTER = new TimeSetting("Time.Thresholds.Remove_time_series_data_after"); public static final Setting<Long> DELETE_TPS_DATA_AFTER = new TimeSetting("Time.Thresholds.Remove_time_series_data_after");
public static final Setting<Long> DELETE_PING_DATA_AFTER = new TimeSetting("Time.Thresholds.Remove_ping_data_after"); public static final Setting<Long> DELETE_PING_DATA_AFTER = new TimeSetting("Time.Thresholds.Remove_ping_data_after");
public static final Setting<Long> ANALYSIS_REFRESH_PERIOD = new TimeSetting("Time.Periodic_tasks.Analysis_refresh_every");
public static final Setting<Long> EXTENSION_DATA_REFRESH_PERIOD = new TimeSetting("Time.Periodic_tasks.Extension_data_refresh_every"); public static final Setting<Long> EXTENSION_DATA_REFRESH_PERIOD = new TimeSetting("Time.Periodic_tasks.Extension_data_refresh_every");
public static final Setting<Long> CLEAN_DATABASE_PERIOD = new TimeSetting("Time.Periodic_tasks.Clean_Database_every"); public static final Setting<Long> CLEAN_DATABASE_PERIOD = new TimeSetting("Time.Periodic_tasks.Clean_Database_every");
public static final Setting<Long> CONFIG_UPDATE_INTERVAL = new TimeSetting("Time.Periodic_tasks.Check_DB_for_server_config_files_every"); public static final Setting<Long> CONFIG_UPDATE_INTERVAL = new TimeSetting("Time.Periodic_tasks.Check_DB_for_server_config_files_every");

View File

@ -115,7 +115,6 @@ public class ConfigSettingKeyTest {
settings.remove(PluginSettings.BUNGEE_COPY_CONFIG); settings.remove(PluginSettings.BUNGEE_COPY_CONFIG);
settings.remove(DatabaseSettings.TYPE); settings.remove(DatabaseSettings.TYPE);
settings.remove(DisplaySettings.WORLD_ALIASES); settings.remove(DisplaySettings.WORLD_ALIASES);
settings.remove(TimeSettings.ANALYSIS_REFRESH_PERIOD);
return settings; return settings;
} }

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.gathering.listeners.sponge; package com.djrapitops.plan.gathering.listeners.sponge;
import com.djrapitops.plan.delivery.domain.Nickname; import com.djrapitops.plan.delivery.domain.Nickname;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.extension.CallEvents; import com.djrapitops.plan.extension.CallEvents;
@ -28,9 +29,9 @@ import com.djrapitops.plan.gathering.domain.Session;
import com.djrapitops.plan.gathering.listeners.Status; import com.djrapitops.plan.gathering.listeners.Status;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.processing.Processing;
import com.djrapitops.plan.processing.processors.Processors;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.transactions.events.*; import com.djrapitops.plan.storage.database.transactions.events.*;
@ -61,11 +62,11 @@ import java.util.UUID;
public class PlayerOnlineListener { public class PlayerOnlineListener {
private final PlanConfig config; private final PlanConfig config;
private final Processors processors;
private final Processing processing; private final Processing processing;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService; private final ExtensionServiceImplementation extensionService;
private final Exporter exporter;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final NicknameCache nicknameCache; private final NicknameCache nicknameCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
@ -75,23 +76,22 @@ public class PlayerOnlineListener {
@Inject @Inject
public PlayerOnlineListener( public PlayerOnlineListener(
PlanConfig config, PlanConfig config,
Processors processors,
Processing processing, Processing processing,
ServerInfo serverInfo, ServerInfo serverInfo,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService, ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, Exporter exporter, GeolocationCache geolocationCache,
NicknameCache nicknameCache, NicknameCache nicknameCache,
SessionCache sessionCache, SessionCache sessionCache,
Status status, Status status,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
this.config = config; this.config = config;
this.processors = processors;
this.processing = processing; this.processing = processing;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService; this.extensionService = extensionService;
this.exporter = exporter;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.nicknameCache = nicknameCache; this.nicknameCache = nicknameCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
@ -185,8 +185,10 @@ public class PlayerOnlineListener {
(uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid)) (uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid))
)); ));
processing.submitNonCritical(processors.info().playerPageExportProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN)); processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
} }
@Listener(order = Order.DEFAULT) @Listener(order = Order.DEFAULT)
@ -209,6 +211,7 @@ public class PlayerOnlineListener {
private void actOnQuitEvent(ClientConnectionEvent.Disconnect event) { private void actOnQuitEvent(ClientConnectionEvent.Disconnect event) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Player player = event.getTargetEntity(); Player player = event.getTargetEntity();
String playerName = player.getName();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
UUID serverUUID = serverInfo.getServerUUID(); UUID serverUUID = serverInfo.getServerUUID();
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID); JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
@ -224,6 +227,8 @@ public class PlayerOnlineListener {
sessionCache.endSession(playerUUID, time) sessionCache.endSession(playerUUID, time)
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession))); .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
processing.submit(processors.info().playerPageExportProcessor(playerUUID)); if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
} }
} }

View File

@ -16,6 +16,7 @@
*/ */
package com.djrapitops.plan.gathering.listeners.velocity; package com.djrapitops.plan.gathering.listeners.velocity;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.extension.CallEvents; import com.djrapitops.plan.extension.CallEvents;
@ -25,9 +26,9 @@ import com.djrapitops.plan.gathering.cache.SessionCache;
import com.djrapitops.plan.gathering.domain.Session; import com.djrapitops.plan.gathering.domain.Session;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.processing.Processing;
import com.djrapitops.plan.processing.processors.Processors;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction;
@ -57,10 +58,10 @@ import java.util.UUID;
public class PlayerOnlineListener { public class PlayerOnlineListener {
private final PlanConfig config; private final PlanConfig config;
private final Processors processors;
private final Processing processing; private final Processing processing;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService; private final ExtensionServiceImplementation extensionService;
private final Exporter exporter;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -70,19 +71,18 @@ public class PlayerOnlineListener {
public PlayerOnlineListener( public PlayerOnlineListener(
PlanConfig config, PlanConfig config,
Processing processing, Processing processing,
Processors processors,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService, ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, Exporter exporter, GeolocationCache geolocationCache,
SessionCache sessionCache, SessionCache sessionCache,
ServerInfo serverInfo, ServerInfo serverInfo,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
this.config = config; this.config = config;
this.processing = processing; this.processing = processing;
this.processors = processors;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService; this.extensionService = extensionService;
this.exporter = exporter;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -117,8 +117,10 @@ public class PlayerOnlineListener {
} }
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName)); database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
processing.submit(processors.info().playerPageExportProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN)); processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
UUID serverUUID = serverInfo.getServerUUID(); UUID serverUUID = serverInfo.getServerUUID();
JSONCache.invalidateMatching(DataID.SERVER_OVERVIEW); JSONCache.invalidateMatching(DataID.SERVER_OVERVIEW);
@ -145,10 +147,13 @@ public class PlayerOnlineListener {
public void actOnLogout(DisconnectEvent event) { public void actOnLogout(DisconnectEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String playerName = player.getUsername();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
sessionCache.endSession(playerUUID, System.currentTimeMillis()); sessionCache.endSession(playerUUID, System.currentTimeMillis());
processing.submit(processors.info().playerPageExportProcessor(playerUUID)); if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
processing.submit(() -> { processing.submit(() -> {
JSONCache.invalidateMatching( JSONCache.invalidateMatching(
@ -180,13 +185,16 @@ public class PlayerOnlineListener {
public void actOnServerSwitch(ServerConnectedEvent event) { public void actOnServerSwitch(ServerConnectedEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String playerName = player.getUsername();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
// Replaces the current session in the cache. // Replaces the current session in the cache.
sessionCache.cacheSession(playerUUID, new Session(playerUUID, serverInfo.getServerUUID(), time, null, null)); sessionCache.cacheSession(playerUUID, new Session(playerUUID, serverInfo.getServerUUID(), time, null, null));
processing.submit(processors.info().playerPageExportProcessor(playerUUID)); if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
JSONCache.invalidate(DataID.SERVERS); JSONCache.invalidate(DataID.SERVERS);
} }