mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 16:37:58 +01:00
Export of /player pages
This commit is contained in:
parent
3a3ba7e801
commit
8a5656e9dc
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.gathering.listeners.bukkit;
|
||||
|
||||
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.JSONCache;
|
||||
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.identification.ServerInfo;
|
||||
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.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.*;
|
||||
@ -57,11 +58,11 @@ import java.util.UUID;
|
||||
public class PlayerOnlineListener implements Listener {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Processors processors;
|
||||
private final Processing processing;
|
||||
private final ServerInfo serverInfo;
|
||||
private final DBSystem dbSystem;
|
||||
private final ExtensionServiceImplementation extensionService;
|
||||
private final Exporter exporter;
|
||||
private final GeolocationCache geolocationCache;
|
||||
private final NicknameCache nicknameCache;
|
||||
private final SessionCache sessionCache;
|
||||
@ -71,11 +72,11 @@ public class PlayerOnlineListener implements Listener {
|
||||
@Inject
|
||||
public PlayerOnlineListener(
|
||||
PlanConfig config,
|
||||
Processors processors,
|
||||
Processing processing,
|
||||
ServerInfo serverInfo,
|
||||
DBSystem dbSystem,
|
||||
ExtensionServiceImplementation extensionService,
|
||||
Exporter exporter,
|
||||
GeolocationCache geolocationCache,
|
||||
NicknameCache nicknameCache,
|
||||
SessionCache sessionCache,
|
||||
@ -83,11 +84,11 @@ public class PlayerOnlineListener implements Listener {
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.processors = processors;
|
||||
this.processing = processing;
|
||||
this.serverInfo = serverInfo;
|
||||
this.dbSystem = dbSystem;
|
||||
this.extensionService = extensionService;
|
||||
this.exporter = exporter;
|
||||
this.geolocationCache = geolocationCache;
|
||||
this.nicknameCache = nicknameCache;
|
||||
this.sessionCache = sessionCache;
|
||||
@ -151,7 +152,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
long time = System.currentTimeMillis();
|
||||
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
|
||||
JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);
|
||||
|
||||
|
||||
BukkitAFKListener.AFK_TRACKER.performedAction(playerUUID, time);
|
||||
|
||||
String world = player.getWorld().getName();
|
||||
@ -181,8 +182,10 @@ public class PlayerOnlineListener implements Listener {
|
||||
(uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid))
|
||||
));
|
||||
|
||||
processing.submitNonCritical(processors.info().playerPageExportProcessor(playerUUID));
|
||||
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)
|
||||
@ -205,6 +208,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
private void actOnQuitEvent(PlayerQuitEvent event) {
|
||||
long time = System.currentTimeMillis();
|
||||
Player player = event.getPlayer();
|
||||
String playerName = player.getName();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
|
||||
@ -219,6 +223,8 @@ public class PlayerOnlineListener implements Listener {
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.gathering.listeners.bungee;
|
||||
|
||||
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.JSONCache;
|
||||
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.identification.ServerInfo;
|
||||
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.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction;
|
||||
@ -55,10 +56,10 @@ import java.util.UUID;
|
||||
public class PlayerOnlineListener implements Listener {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Processors processors;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final ExtensionServiceImplementation extensionService;
|
||||
private final Exporter exporter;
|
||||
private final GeolocationCache geolocationCache;
|
||||
private final SessionCache sessionCache;
|
||||
private final ServerInfo serverInfo;
|
||||
@ -67,20 +68,19 @@ public class PlayerOnlineListener implements Listener {
|
||||
@Inject
|
||||
public PlayerOnlineListener(
|
||||
PlanConfig config,
|
||||
Processors processors,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
ExtensionServiceImplementation extensionService,
|
||||
GeolocationCache geolocationCache,
|
||||
Exporter exporter, GeolocationCache geolocationCache,
|
||||
SessionCache sessionCache,
|
||||
ServerInfo serverInfo,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.processors = processors;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.extensionService = extensionService;
|
||||
this.exporter = exporter;
|
||||
this.geolocationCache = geolocationCache;
|
||||
this.sessionCache = sessionCache;
|
||||
this.serverInfo = serverInfo;
|
||||
@ -116,8 +116,10 @@ public class PlayerOnlineListener implements Listener {
|
||||
}
|
||||
|
||||
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
|
||||
processing.submit(processors.info().playerPageExportProcessor(playerUUID));
|
||||
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();
|
||||
JSONCache.invalidateMatching(DataID.SERVER_OVERVIEW);
|
||||
@ -144,11 +146,13 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
private void actOnLogout(PlayerDisconnectEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
String playerName = player.getName();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
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(() -> {
|
||||
JSONCache.invalidateMatching(
|
||||
DataID.SERVER_OVERVIEW,
|
||||
@ -179,6 +183,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
private void actOnServerSwitch(ServerSwitchEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
String playerName = player.getName();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
@ -186,7 +191,9 @@ public class PlayerOnlineListener implements Listener {
|
||||
Session session = new Session(playerUUID, serverInfo.getServerUUID(), time, null, null);
|
||||
session.putRawData(SessionKeys.SERVER_NAME, "Proxy Server");
|
||||
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);
|
||||
}
|
||||
|
@ -17,8 +17,9 @@
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
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.exceptions.ExportException;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
@ -53,7 +54,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final HtmlExport export;
|
||||
private final Exporter exporter;
|
||||
private final ServerInfo serverInfo;
|
||||
private final WebServer webServer;
|
||||
private final DBSystem dbSystem;
|
||||
@ -63,7 +64,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
public AnalyzeCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
HtmlExport export,
|
||||
Exporter exporter,
|
||||
ServerInfo serverInfo,
|
||||
WebServer webServer,
|
||||
DBSystem dbSystem,
|
||||
@ -73,7 +74,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.export = export;
|
||||
this.exporter = exporter;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
this.dbSystem = dbSystem;
|
||||
@ -97,9 +98,9 @@ public class AnalyzeCommand extends CommandNode {
|
||||
try {
|
||||
Server server = getServer(args);
|
||||
sendWebUserNotificationIfNecessary(sender);
|
||||
export.exportServer(server); // TODO
|
||||
exporter.exportServerPage(server);
|
||||
sendLink(server, sender);
|
||||
} catch (DBOpException e) {
|
||||
} catch (DBOpException | ExportException e) {
|
||||
sender.sendMessage("§cError occurred: " + e.toString());
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
|
@ -16,8 +16,10 @@
|
||||
*/
|
||||
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.JSONExport;
|
||||
import com.djrapitops.plan.exceptions.ExportException;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
@ -57,6 +59,7 @@ public class ManageExportCommand extends CommandNode {
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Exporter exporter;
|
||||
private final HtmlExport htmlExport;
|
||||
private final JSONExport jsonExport;
|
||||
private final Processing processing;
|
||||
@ -68,6 +71,7 @@ public class ManageExportCommand extends CommandNode {
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Exporter exporter,
|
||||
Processing processing,
|
||||
HtmlExport htmlExport,
|
||||
JSONExport jsonExport
|
||||
@ -79,6 +83,7 @@ public class ManageExportCommand extends CommandNode {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.exporter = exporter;
|
||||
this.htmlExport = htmlExport;
|
||||
this.jsonExport = jsonExport;
|
||||
this.processing = processing;
|
||||
@ -138,13 +143,15 @@ public class ManageExportCommand extends CommandNode {
|
||||
processing.submitNonCritical(() -> {
|
||||
Map<UUID, String> players = dbSystem.getDatabase().query(UserIdentifierQueries.fetchAllPlayerNames());
|
||||
int size = players.size();
|
||||
int failed = 0;
|
||||
|
||||
int i = 1;
|
||||
for (Map.Entry<UUID, String> entry : players.entrySet()) {
|
||||
if (exportPlayerJSON) {
|
||||
jsonExport.exportPlayerJSON(entry.getKey());
|
||||
}
|
||||
if (exportPlayerHTML) {
|
||||
htmlExport.exportPlayerPage(entry.getKey(), entry.getValue());
|
||||
try {
|
||||
if (exportPlayerJSON) jsonExport.exportPlayerJSON(entry.getKey());
|
||||
if (exportPlayerHTML) exporter.exportPlayerPage(entry.getKey(), entry.getValue());
|
||||
} catch (ExportException e) {
|
||||
failed++;
|
||||
}
|
||||
i++;
|
||||
if (i % 1000 == 0) {
|
||||
@ -152,6 +159,11 @@ public class ManageExportCommand extends CommandNode {
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ public class Exporter {
|
||||
|
||||
private final PlanFiles files;
|
||||
private final PlanConfig config;
|
||||
private final PlayerPageExporter playerPageExporter;
|
||||
private final ServerPageExporter serverPageExporter;
|
||||
private final NetworkPageExporter networkPageExporter;
|
||||
|
||||
@ -52,11 +53,13 @@ public class Exporter {
|
||||
public Exporter(
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
PlayerPageExporter playerPageExporter,
|
||||
ServerPageExporter serverPageExporter,
|
||||
NetworkPageExporter networkPageExporter
|
||||
) {
|
||||
this.files = files;
|
||||
this.config = config;
|
||||
this.playerPageExporter = playerPageExporter;
|
||||
this.serverPageExporter = serverPageExporter;
|
||||
this.networkPageExporter = networkPageExporter;
|
||||
|
||||
@ -74,12 +77,12 @@ public class Exporter {
|
||||
* Export a page of a server.
|
||||
*
|
||||
* @param server Server which page is going to be exported
|
||||
* @return false if the page was not exported due to previous failure.
|
||||
* @throws ExportException If the export failed
|
||||
* @return false if the page was not exported due to previous failure or is disabled in config.
|
||||
* @throws ExportException If the export failed due to IO, NotFound or ParseException.
|
||||
*/
|
||||
public boolean exportServerPage(Server server) throws ExportException {
|
||||
UUID serverUUID = server.getUuid();
|
||||
if (failedServers.contains(serverUUID)) return false;
|
||||
if (failedServers.contains(serverUUID) || !config.get(ExportSettings.SERVER_PAGE)) return false;
|
||||
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,23 +17,14 @@
|
||||
package com.djrapitops.plan.delivery.export;
|
||||
|
||||
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.PlayerPage;
|
||||
import com.djrapitops.plan.exceptions.ExportException;
|
||||
import com.djrapitops.plan.exceptions.ParseException;
|
||||
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.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
||||
import com.djrapitops.plan.settings.theme.Theme;
|
||||
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.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
@ -45,8 +36,8 @@ import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class responsible for Html Export task.
|
||||
@ -92,50 +83,6 @@ public class HtmlExport extends SpecificExport {
|
||||
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() {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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, "../");
|
||||
}
|
||||
|
||||
}
|
@ -85,7 +85,7 @@ public class ServerPageExporter extends FileExporter {
|
||||
private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException, ParseException {
|
||||
UUID serverUUID = server.getUuid();
|
||||
Path to = toDirectory
|
||||
.resolve(serverInfo.getServer().isProxy() ? "server/" + server.getName() : "server")
|
||||
.resolve(serverInfo.getServer().isProxy() ? "server/" + toFileName(server.getName()) : "server")
|
||||
.resolve("index.html");
|
||||
|
||||
Page page = pageFactory.serverPage(serverUUID);
|
||||
|
@ -17,20 +17,16 @@
|
||||
package com.djrapitops.plan.delivery.export;
|
||||
|
||||
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.storage.file.PlanFiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Abstract Html Export Task.
|
||||
@ -79,35 +75,10 @@ public abstract class SpecificExport {
|
||||
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 player = new File(getFolder(), "player");
|
||||
player.mkdirs();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,6 @@ package com.djrapitops.plan.exceptions;
|
||||
*/
|
||||
public class ExportException extends Exception {
|
||||
|
||||
public ExportException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExportException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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_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> 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> 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");
|
||||
|
@ -115,7 +115,6 @@ public class ConfigSettingKeyTest {
|
||||
settings.remove(PluginSettings.BUNGEE_COPY_CONFIG);
|
||||
settings.remove(DatabaseSettings.TYPE);
|
||||
settings.remove(DisplaySettings.WORLD_ALIASES);
|
||||
settings.remove(TimeSettings.ANALYSIS_REFRESH_PERIOD);
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.gathering.listeners.sponge;
|
||||
|
||||
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.JSONCache;
|
||||
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.identification.ServerInfo;
|
||||
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.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.*;
|
||||
@ -61,11 +62,11 @@ import java.util.UUID;
|
||||
public class PlayerOnlineListener {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Processors processors;
|
||||
private final Processing processing;
|
||||
private final ServerInfo serverInfo;
|
||||
private final DBSystem dbSystem;
|
||||
private final ExtensionServiceImplementation extensionService;
|
||||
private final Exporter exporter;
|
||||
private final GeolocationCache geolocationCache;
|
||||
private final NicknameCache nicknameCache;
|
||||
private final SessionCache sessionCache;
|
||||
@ -75,23 +76,22 @@ public class PlayerOnlineListener {
|
||||
@Inject
|
||||
public PlayerOnlineListener(
|
||||
PlanConfig config,
|
||||
Processors processors,
|
||||
Processing processing,
|
||||
ServerInfo serverInfo,
|
||||
DBSystem dbSystem,
|
||||
ExtensionServiceImplementation extensionService,
|
||||
GeolocationCache geolocationCache,
|
||||
Exporter exporter, GeolocationCache geolocationCache,
|
||||
NicknameCache nicknameCache,
|
||||
SessionCache sessionCache,
|
||||
Status status,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.processors = processors;
|
||||
this.processing = processing;
|
||||
this.serverInfo = serverInfo;
|
||||
this.dbSystem = dbSystem;
|
||||
this.extensionService = extensionService;
|
||||
this.exporter = exporter;
|
||||
this.geolocationCache = geolocationCache;
|
||||
this.nicknameCache = nicknameCache;
|
||||
this.sessionCache = sessionCache;
|
||||
@ -154,7 +154,7 @@ public class PlayerOnlineListener {
|
||||
long time = System.currentTimeMillis();
|
||||
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
|
||||
JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);
|
||||
|
||||
|
||||
SpongeAFKListener.AFK_TRACKER.performedAction(playerUUID, time);
|
||||
|
||||
String world = player.getWorld().getName();
|
||||
@ -185,8 +185,10 @@ public class PlayerOnlineListener {
|
||||
(uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid))
|
||||
));
|
||||
|
||||
processing.submitNonCritical(processors.info().playerPageExportProcessor(playerUUID));
|
||||
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)
|
||||
@ -209,11 +211,12 @@ public class PlayerOnlineListener {
|
||||
private void actOnQuitEvent(ClientConnectionEvent.Disconnect event) {
|
||||
long time = System.currentTimeMillis();
|
||||
Player player = event.getTargetEntity();
|
||||
String playerName = player.getName();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
|
||||
JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);
|
||||
|
||||
|
||||
SpongeAFKListener.AFK_TRACKER.loggedOut(playerUUID, time);
|
||||
|
||||
nicknameCache.removeDisplayName(playerUUID);
|
||||
@ -224,6 +227,8 @@ public class PlayerOnlineListener {
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.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));
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
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.JSONCache;
|
||||
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.identification.ServerInfo;
|
||||
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.paths.DataGatheringSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction;
|
||||
@ -57,10 +58,10 @@ import java.util.UUID;
|
||||
public class PlayerOnlineListener {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Processors processors;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final ExtensionServiceImplementation extensionService;
|
||||
private final Exporter exporter;
|
||||
private final GeolocationCache geolocationCache;
|
||||
private final SessionCache sessionCache;
|
||||
private final ServerInfo serverInfo;
|
||||
@ -70,19 +71,18 @@ public class PlayerOnlineListener {
|
||||
public PlayerOnlineListener(
|
||||
PlanConfig config,
|
||||
Processing processing,
|
||||
Processors processors,
|
||||
DBSystem dbSystem,
|
||||
ExtensionServiceImplementation extensionService,
|
||||
GeolocationCache geolocationCache,
|
||||
Exporter exporter, GeolocationCache geolocationCache,
|
||||
SessionCache sessionCache,
|
||||
ServerInfo serverInfo,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.processing = processing;
|
||||
this.processors = processors;
|
||||
this.dbSystem = dbSystem;
|
||||
this.extensionService = extensionService;
|
||||
this.exporter = exporter;
|
||||
this.geolocationCache = geolocationCache;
|
||||
this.sessionCache = sessionCache;
|
||||
this.serverInfo = serverInfo;
|
||||
@ -117,8 +117,10 @@ public class PlayerOnlineListener {
|
||||
}
|
||||
|
||||
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
|
||||
processing.submit(processors.info().playerPageExportProcessor(playerUUID));
|
||||
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();
|
||||
JSONCache.invalidateMatching(DataID.SERVER_OVERVIEW);
|
||||
@ -145,10 +147,13 @@ public class PlayerOnlineListener {
|
||||
|
||||
public void actOnLogout(DisconnectEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String playerName = player.getUsername();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
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(() -> {
|
||||
JSONCache.invalidateMatching(
|
||||
@ -180,13 +185,16 @@ public class PlayerOnlineListener {
|
||||
|
||||
public void actOnServerSwitch(ServerConnectedEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String playerName = player.getUsername();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
// Replaces the current session in the cache.
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user