mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-04 22:41:41 +01:00
[#958] Export Command + online status change export
Added /plan manage export that can be used to export all players based on config settings. Arguments: list, players, server_json Permission: plan.manage Added a config setting 'Export.Export_player_on_login_and_logout' for exporting player page and JSON based on config settings on login or logout.
This commit is contained in:
parent
0ed86b532c
commit
3167cc5f6a
@ -51,6 +51,7 @@ public class ManageCommand extends TreeCmdNode {
|
||||
ManageSetupCommand setupCommand,
|
||||
ManageConDebugCommand conDebugCommand,
|
||||
ManageImportCommand importCommand,
|
||||
ManageExportCommand exportCommand,
|
||||
ManageDisableCommand disableCommand,
|
||||
ManageUninstalledCommand uninstalledCommand
|
||||
) {
|
||||
@ -72,6 +73,7 @@ public class ManageCommand extends TreeCmdNode {
|
||||
setupCommand,
|
||||
conDebugCommand,
|
||||
importCommand,
|
||||
exportCommand,
|
||||
disableCommand,
|
||||
uninstalledCommand
|
||||
};
|
||||
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.queries.objects.UserIdentifierQueries;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.export.HtmlExport;
|
||||
import com.djrapitops.plan.system.export.JSONExport;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* This manage SubCommand is used to import data from 3rd party plugins.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageExportCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final ColorScheme colorScheme;
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final HtmlExport htmlExport;
|
||||
private final JSONExport jsonExport;
|
||||
private final Processing processing;
|
||||
|
||||
@Inject
|
||||
public ManageExportCommand(
|
||||
Locale locale,
|
||||
ColorScheme colorScheme,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Processing processing,
|
||||
HtmlExport htmlExport,
|
||||
JSONExport jsonExport
|
||||
) {
|
||||
super("export", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
this.locale = locale;
|
||||
this.colorScheme = colorScheme;
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.htmlExport = htmlExport;
|
||||
this.jsonExport = jsonExport;
|
||||
this.processing = processing;
|
||||
|
||||
setArguments("<export_kind>/list");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_EXPORT));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_EXPORT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, "1+", Arrays.toString(this.getArguments()))));
|
||||
|
||||
String exportArg = args[0];
|
||||
|
||||
if ("list".equals(exportArg)) {
|
||||
sender.sendMessage("> " + colorScheme.getMainColor() + "players, server_json");
|
||||
return;
|
||||
}
|
||||
|
||||
Database.State dbState = dbSystem.getDatabase().getState();
|
||||
if (dbState != Database.State.OPEN) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
|
||||
return;
|
||||
}
|
||||
|
||||
getExportFunction(exportArg).accept(sender);
|
||||
}
|
||||
|
||||
private Consumer<Sender> getExportFunction(String exportArg) {
|
||||
switch (exportArg) {
|
||||
case "players":
|
||||
return this::exportPlayers;
|
||||
case "server_json":
|
||||
return this::exportServerJSON;
|
||||
default:
|
||||
return sender -> sender.sendMessage(locale.getString(ManageLang.FAIL_EXPORTER_NOT_FOUND, exportArg));
|
||||
}
|
||||
}
|
||||
|
||||
private void exportServerJSON(Sender sender) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
processing.submitNonCritical(() -> {
|
||||
jsonExport.exportServerJSON(serverInfo.getServerUUID());
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
});
|
||||
}
|
||||
|
||||
private void exportPlayers(Sender sender) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
if (config.get(ExportSettings.PLAYERS_PAGE)) {
|
||||
processing.submitNonCritical(htmlExport::exportPlayersPage);
|
||||
}
|
||||
Boolean exportPlayerJSON = config.get(ExportSettings.PLAYER_JSON);
|
||||
Boolean exportPlayerHTML = config.get(ExportSettings.PLAYER_PAGES);
|
||||
processing.submitNonCritical(() -> {
|
||||
Map<UUID, String> players = dbSystem.getDatabase().query(UserIdentifierQueries.fetchAllPlayerNames());
|
||||
for (Map.Entry<UUID, String> entry : players.entrySet()) {
|
||||
if (exportPlayerJSON) {
|
||||
jsonExport.exportPlayerJSON(entry.getKey());
|
||||
}
|
||||
if (exportPlayerHTML) {
|
||||
htmlExport.exportPlayerPage(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
});
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plan.utilities.html.pages.InspectPage;
|
||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
@ -107,7 +108,21 @@ public class HtmlExport extends SpecificExport {
|
||||
});
|
||||
}
|
||||
|
||||
public void exportPlayer(UUID playerUUID) {
|
||||
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) {
|
||||
InspectPage playerPage = pageFactory.inspectPage(playerUUID);
|
||||
try {
|
||||
exportPlayerPage(playerName, playerPage.toHtml());
|
||||
} catch (ParseException | IOException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void exportCachedPlayerPage(UUID playerUUID) {
|
||||
if (Check.isBukkitAvailable() && connectionSystem.isServerAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
@ -89,20 +89,24 @@ public abstract class SpecificExport {
|
||||
return player;
|
||||
}
|
||||
|
||||
protected void exportAvailablePlayerPage(UUID uuid, String name) throws IOException {
|
||||
Response response = ResponseCache.loadResponse(PageId.PLAYER.of(uuid));
|
||||
protected void exportPlayerPage(String playerName, String html) throws IOException {
|
||||
List<String> lines = Arrays.asList(html.split("\n"));
|
||||
|
||||
File htmlLocation = new File(getPlayerFolder(), playerName.replace(" ", "%20").replace(".", "%2E"));
|
||||
htmlLocation.mkdirs();
|
||||
File exportFile = new File(htmlLocation, "index.html");
|
||||
|
||||
export(exportFile, lines);
|
||||
}
|
||||
|
||||
protected void exportAvailablePlayerPage(UUID playerUUID, String name) throws IOException {
|
||||
Response response = ResponseCache.loadResponse(PageId.PLAYER.of(playerUUID));
|
||||
if (response == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String html = response.getContent().replace("../", "../../");
|
||||
List<String> lines = Arrays.asList(html.split("\n"));
|
||||
|
||||
File htmlLocation = new File(getPlayerFolder(), name.replace(" ", "%20").replace(".", "%2E"));
|
||||
htmlLocation.mkdirs();
|
||||
File exportFile = new File(htmlLocation, "index.html");
|
||||
|
||||
export(exportFile, lines);
|
||||
exportPlayerPage(name, html);
|
||||
}
|
||||
|
||||
protected void exportAvailableServerPage(UUID serverUUID, String serverName) throws IOException {
|
||||
|
@ -105,13 +105,13 @@ public class CacheInspectPageRequest extends InfoRequestWithVariables implements
|
||||
return DefaultResponses.SUCCESS.get();
|
||||
}
|
||||
|
||||
private void cache(UUID uuid, String html) {
|
||||
ResponseCache.cacheResponse(PageId.PLAYER.of(uuid), () -> new InspectPageResponse(uuid, html));
|
||||
private void cache(UUID playerUUID, String html) {
|
||||
ResponseCache.cacheResponse(PageId.PLAYER.of(playerUUID), () -> new InspectPageResponse(playerUUID, html));
|
||||
if (config.get(ExportSettings.PLAYER_PAGES)) {
|
||||
processing.submitNonCritical(() -> htmlExport.exportPlayer(uuid));
|
||||
processing.submitNonCritical(() -> htmlExport.exportCachedPlayerPage(playerUUID));
|
||||
}
|
||||
if (config.get(ExportSettings.PLAYER_JSON)) {
|
||||
processing.submitNonCritical(() -> jsonExport.exportPlayerJSON(uuid));
|
||||
processing.submitNonCritical(() -> jsonExport.exportPlayerJSON(playerUUID));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ public enum CmdHelpLang implements Lang {
|
||||
MANAGE_CLEAR("Command Help - /plan manage clear", "Clear a Database"),
|
||||
MANAGE_CON("Command Help - /plan manage con", "Debug Server-Bungee connections"),
|
||||
MANAGE_IMPORT("Command Help - /plan manage import", "Import data from elsewhere"),
|
||||
MANAGE_EXPORT("Command Help - /plan manage export", "Trigger export manually"),
|
||||
MANAGE_DISABLE("Command Help - /plan manage disable", "Disable a feature temporarily"),
|
||||
MANAGE_SETUP("Command Help - /plan manage setup", "Set-up Server-Bungee connection"),
|
||||
|
||||
|
@ -41,6 +41,7 @@ public enum DeepHelpLang implements Lang {
|
||||
MANAGE_CON("In Depth Help - /plan manage con ?", "> §2Connection Debug Subcommand\\ Used to debug connections in the network.\\ Sends a request to each server in the database."),
|
||||
MANAGE_DISABLE("In Depth Help - /plan manage disable ?", "> §2Disable Subcommand\\ Can disable parts of the plugin until next reload.\\ Accepted arguments:\\ §2kickcount §fDisables kick counts in case /kickall is used on shutdown macro."),
|
||||
MANAGE_IMPORT("In Depth Help - /plan manage import ?", "> §2Import Subcommand\\ Import data from other sources.\\ Accepted Arguments:\\ §2offline §fBukkit player data, only register date and name."),
|
||||
MANAGE_EXPORT("In Depth Help - /plan manage export ?", "> §2Export Subcommand\\ Trigger export to result folders.\\ Accepted Arguments:\\ §2list §fList possible arguments.\\ §2players §fExport /players, /player pages + /player/raw json depending on config values.\\ §2server_json §fExport /server/raw JSON if enabled in config."),
|
||||
MANAGE_MOVE("In Depth Help - /plan manage move ?", "> §2Move Subcommand\\ Move data from SQLite to MySQL or other way around.\\ Target database is cleared before transfer."),
|
||||
MANAGE_REMOVE("In Depth Help - /plan manage remove ?", "> §2Remove Subcommand\\ Remove player's data from the active database."),
|
||||
MANAGE_RESTORE("In Depth Help - /plan manage restore ?", "> §2Restore Subcommand\\ Restore a previous backup SQLite database (.db file)\\ You can also restore database.db from another server to MySQL.\\ Target database is cleared before transfer."),
|
||||
|
@ -45,6 +45,7 @@ public enum ManageLang implements Lang {
|
||||
FAIL_INCORRECT_DB("Manage - Fail Incorrect Database", "> §c'${0}' is not a supported database."),
|
||||
FAIL_FILE_NOT_FOUND("Manage - Fail File not found", "> §cNo File found at ${0}"),
|
||||
FAIL_IMPORTER_NOT_FOUND("Manage - Fail No Importer", "§eImporter '${0}' doesn't exist"),
|
||||
FAIL_EXPORTER_NOT_FOUND("Manage - Fail No Exporter", "§eExporter '${0}' doesn't exist"),
|
||||
NO_SERVER("Manage - Fail No Server", "No server found with given parameters."),
|
||||
UNINSTALLING_SAME_SERVER("Manage - Fail Same server", "Can not mark this server as uninstalled (You are on it)");
|
||||
|
||||
|
@ -16,8 +16,11 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing.processors.info;
|
||||
|
||||
import com.djrapitops.plan.system.export.HtmlExport;
|
||||
import com.djrapitops.plan.system.export.JSONExport;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import dagger.Lazy;
|
||||
|
||||
@ -34,14 +37,23 @@ import java.util.function.BiConsumer;
|
||||
@Singleton
|
||||
public class InfoProcessors {
|
||||
|
||||
private final Lazy<PlanConfig> config;
|
||||
private final Lazy<HtmlExport> htmlExport;
|
||||
private final Lazy<JSONExport> jsonExport;
|
||||
private final Lazy<InfoSystem> infoSystem;
|
||||
private final Lazy<WebExceptionLogger> webExceptionLogger;
|
||||
|
||||
@Inject
|
||||
public InfoProcessors(
|
||||
Lazy<PlanConfig> config,
|
||||
Lazy<HtmlExport> htmlExport,
|
||||
Lazy<JSONExport> jsonExport,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
Lazy<WebExceptionLogger> webExceptionLogger
|
||||
) {
|
||||
this.config = config;
|
||||
this.htmlExport = htmlExport;
|
||||
this.jsonExport = jsonExport;
|
||||
this.infoSystem = infoSystem;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
}
|
||||
@ -58,6 +70,6 @@ public class InfoProcessors {
|
||||
}
|
||||
|
||||
public PlayerPageUpdateProcessor playerPageUpdateProcessor(UUID uuid) {
|
||||
return new PlayerPageUpdateProcessor(uuid);
|
||||
return new PlayerPageUpdateProcessor(uuid, config.get(), htmlExport.get(), jsonExport.get());
|
||||
}
|
||||
}
|
@ -16,6 +16,10 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.processing.processors.info;
|
||||
|
||||
import com.djrapitops.plan.system.export.HtmlExport;
|
||||
import com.djrapitops.plan.system.export.JSONExport;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
|
||||
@ -23,16 +27,35 @@ import java.util.UUID;
|
||||
|
||||
public class PlayerPageUpdateProcessor implements Runnable {
|
||||
|
||||
private final UUID uuid;
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final PlanConfig config;
|
||||
private final HtmlExport htmlExport;
|
||||
private final JSONExport jsonExport;
|
||||
|
||||
PlayerPageUpdateProcessor(
|
||||
UUID uuid
|
||||
UUID playerUUID,
|
||||
PlanConfig config,
|
||||
HtmlExport htmlExport,
|
||||
JSONExport jsonExport
|
||||
) {
|
||||
this.uuid = uuid;
|
||||
this.playerUUID = playerUUID;
|
||||
this.config = config;
|
||||
this.htmlExport = htmlExport;
|
||||
this.jsonExport = jsonExport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ResponseCache.clearResponse(PageId.PLAYER.of(uuid));
|
||||
ResponseCache.clearResponse(PageId.PLAYER.of(playerUUID));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class ExportSettings {
|
||||
public static final Setting<Boolean> PLAYERS_PAGE = new BooleanSetting("Export.Parts.Players_page");
|
||||
public static final Setting<Boolean> SERVER_PAGE = new BooleanSetting("Export.Parts.Server_page");
|
||||
public static final Setting<Boolean> SERVER_JSON = new BooleanSetting("Export.Parts.Server_JSON");
|
||||
public static final Setting<Boolean> EXPORT_ON_ONLINE_STATUS_CHANGE = new BooleanSetting("Export.Export_player_on_login_and_logout");
|
||||
|
||||
private ExportSettings() {
|
||||
/* static variable class */
|
||||
|
@ -161,6 +161,7 @@ Export:
|
||||
Players_page: false
|
||||
Server_page: false
|
||||
Server_JSON: false
|
||||
Export_player_on_login_and_logout: false
|
||||
# -----------------------------------------------------
|
||||
# These settings affect Plugin data integration.
|
||||
# If a plugin is causing issues the integration can be disabled by setting Plugin_name.Enabled: false
|
||||
|
@ -174,6 +174,8 @@ Export:
|
||||
Players_page: false
|
||||
Server_page: false
|
||||
Server_JSON: false
|
||||
# All player pages/JSON can be exported by using /plan m export players
|
||||
Export_player_on_login_and_logout: false
|
||||
# -----------------------------------------------------
|
||||
# These settings affect Plugin data integration.
|
||||
# If a plugin is causing issues the integration can be disabled by setting Plugin_name.Enabled: false
|
||||
|
Loading…
Reference in New Issue
Block a user