Registered plan export command

- Fixed dagger compile error
- Fixed checkstyle errors
This commit is contained in:
Risto Lahtela 2020-06-20 21:51:12 +03:00
parent 42669b7367
commit 01fb4c7d84
12 changed files with 154 additions and 65 deletions

View File

@ -165,6 +165,7 @@ subprojects {
} }
checkstyle { checkstyle {
toolVersion "8.33"
getConfigDirectory().set file("$rootProject.projectDir/config/checkstyle") getConfigDirectory().set file("$rootProject.projectDir/config/checkstyle")
} }

View File

@ -21,6 +21,7 @@ import com.djrapitops.plan.commands.PlanCommand;
import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.PlaceholderModule; import com.djrapitops.plan.modules.PlaceholderModule;
import com.djrapitops.plan.modules.ServerCommandModule;
import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule;
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule; import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule; import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
@ -42,6 +43,7 @@ import javax.inject.Singleton;
APFModule.class, APFModule.class,
PlaceholderModule.class, PlaceholderModule.class,
ServerCommandModule.class,
BukkitServerPropertiesModule.class, BukkitServerPropertiesModule.class,
BukkitSuperClassBindingModule.class BukkitSuperClassBindingModule.class
}) })

View File

@ -23,7 +23,6 @@ package com.djrapitops.plan;
*/ */
public class DebugChannels { public class DebugChannels {
private DebugChannels() { private DebugChannels() {
/* Static variable class */ /* Static variable class */
} }

View File

@ -44,6 +44,7 @@ public class PlanCommand {
private final RegistrationCommands registrationCommands; private final RegistrationCommands registrationCommands;
private final PluginStatusCommands statusCommands; private final PluginStatusCommands statusCommands;
private final DatabaseCommands databaseCommands; private final DatabaseCommands databaseCommands;
private final DataUtilityCommands dataUtilityCommands;
private final ErrorLogger errorLogger; private final ErrorLogger errorLogger;
@Inject @Inject
@ -56,6 +57,7 @@ public class PlanCommand {
RegistrationCommands registrationCommands, RegistrationCommands registrationCommands,
PluginStatusCommands statusCommands, PluginStatusCommands statusCommands,
DatabaseCommands databaseCommands, DatabaseCommands databaseCommands,
DataUtilityCommands dataUtilityCommands,
ErrorLogger errorLogger ErrorLogger errorLogger
) { ) {
this.commandName = commandName; this.commandName = commandName;
@ -66,6 +68,7 @@ public class PlanCommand {
this.registrationCommands = registrationCommands; this.registrationCommands = registrationCommands;
this.statusCommands = statusCommands; this.statusCommands = statusCommands;
this.databaseCommands = databaseCommands; this.databaseCommands = databaseCommands;
this.dataUtilityCommands = dataUtilityCommands;
this.errorLogger = errorLogger; this.errorLogger = errorLogger;
} }
@ -98,6 +101,8 @@ public class PlanCommand {
.subcommand(reloadCommand()) .subcommand(reloadCommand())
.subcommand(disableCommand()) .subcommand(disableCommand())
.subcommand(databaseCommand()) .subcommand(databaseCommand())
.subcommand(export())
.exceptionHandler(this::handleException) .exceptionHandler(this::handleException)
.build(); .build();
} }
@ -183,7 +188,7 @@ public class PlanCommand {
.optionalArgument("username", "Username of another user. If not specified linked user is used.") .optionalArgument("username", "Username of another user. If not specified linked user is used.")
.description("Unregister user of Plan website") .description("Unregister user of Plan website")
.inDepthDescription("Use without arguments to unregister linked user, or with username argument to unregister another user.") .inDepthDescription("Use without arguments to unregister linked user, or with username argument to unregister another user.")
.onCommand(((sender, arguments) -> registrationCommands.onUnregister(commandName, sender, arguments))) .onCommand((sender, arguments) -> registrationCommands.onUnregister(commandName, sender, arguments))
.build(); .build();
} }
@ -326,4 +331,15 @@ public class PlanCommand {
.onCommand(databaseCommands::onUninstalled) .onCommand(databaseCommands::onUninstalled)
.build(); .build();
} }
private Subcommand export() {
return Subcommand.builder()
.aliases("export")
.requirePermission("plan.data.export")
.optionalArgument("export kind", "players/server_json")
.description("Export html or json files manually.")
.inDepthDescription("Performs an export to export location defined in the config.")
.onCommand(dataUtilityCommands::onExport)
.build();
}
} }

View File

@ -1,3 +1,19 @@
/*
* 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.commands.subcommands; package com.djrapitops.plan.commands.subcommands;
import com.djrapitops.plan.commands.use.Arguments; import com.djrapitops.plan.commands.use.Arguments;

View File

@ -14,46 +14,33 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>. * along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.djrapitops.plan.commands.subcommands.manage; package com.djrapitops.plan.commands.subcommands;
import com.djrapitops.plan.commands.use.Arguments;
import com.djrapitops.plan.commands.use.CMDSender;
import com.djrapitops.plan.delivery.export.Exporter; import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.exceptions.ExportException; 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.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.locale.Locale; import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.lang.CmdHelpLang;
import com.djrapitops.plan.settings.locale.lang.CommandLang; import com.djrapitops.plan.settings.locale.lang.CommandLang;
import com.djrapitops.plan.settings.locale.lang.DeepHelpLang;
import com.djrapitops.plan.settings.locale.lang.ManageLang; import com.djrapitops.plan.settings.locale.lang.ManageLang;
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.queries.objects.UserIdentifierQueries; import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries;
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.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
/**
* This manage SubCommand is used to import data from 3rd party plugins.
*
* @author Rsl1122
*/
@Singleton @Singleton
public class ManageExportCommand extends CommandNode { public class DataUtilityCommands {
private final Locale locale; private final Locale locale;
private final ColorScheme colorScheme;
private final PlanConfig config; private final PlanConfig config;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -61,88 +48,71 @@ public class ManageExportCommand extends CommandNode {
private final Processing processing; private final Processing processing;
@Inject @Inject
public ManageExportCommand( public DataUtilityCommands(
Locale locale, Locale locale,
ColorScheme colorScheme,
PlanConfig config, PlanConfig config,
DBSystem dbSystem, DBSystem dbSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
Exporter exporter, Exporter exporter,
Processing processing Processing processing
) { ) {
super("export", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
this.locale = locale; this.locale = locale;
this.colorScheme = colorScheme;
this.config = config; this.config = config;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.exporter = exporter; this.exporter = exporter;
this.processing = processing; this.processing = processing;
setArguments("<export_kind>/list");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_EXPORT));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_EXPORT));
} }
@Override private void ensureDatabaseIsOpen() {
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(); Database.State dbState = dbSystem.getDatabase().getState();
if (dbState != Database.State.OPEN) { if (dbState != Database.State.OPEN) {
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
return;
} }
getExportFunction(exportArg).accept(sender);
} }
private Consumer<Sender> getExportFunction(String exportArg) { public void onExport(CMDSender sender, Arguments arguments) {
String exportKind = arguments.get(0)
.orElseThrow(() -> new IllegalArgumentException("Accepts following as export kind: players, server_json"));
ensureDatabaseIsOpen();
getExportFunction(exportKind).accept(sender);
}
private Consumer<CMDSender> getExportFunction(String exportArg) {
if ("players".equals(exportArg)) { if ("players".equals(exportArg)) {
return this::exportPlayers; return this::exportPlayers;
} else if ("server_json".endsWith(exportArg)) { } else if ("server_json".endsWith(exportArg)) {
return this::exportServerJSON; return this::exportServerJSON;
} }
return sender -> sender.sendMessage(locale.getString(ManageLang.FAIL_EXPORTER_NOT_FOUND, exportArg)); throw new IllegalArgumentException(locale.getString(ManageLang.FAIL_EXPORTER_NOT_FOUND, exportArg));
} }
private void exportServerJSON(Sender sender) { private void exportServerJSON(CMDSender sender) {
if (config.isFalse(ExportSettings.SERVER_JSON)) { if (config.isFalse(ExportSettings.SERVER_JSON)) {
sender.sendMessage("§c'" + ExportSettings.SERVER_JSON.getPath() + "': false"); throw new IllegalArgumentException("'" + ExportSettings.SERVER_JSON.getPath() + "': false");
return;
} }
processing.submitNonCritical(() -> { processing.submitNonCritical(() -> {
try { try {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); sender.send(locale.getString(ManageLang.PROGRESS_START));
if (exporter.exportServerJSON(serverInfo.getServer())) { if (exporter.exportServerJSON(serverInfo.getServer())) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.send(locale.getString(ManageLang.PROGRESS_SUCCESS));
} else { } else {
sender.sendMessage(locale.get(ManageLang.PROGRESS_FAIL).toString("see '" + ExportSettings.SERVER_JSON.getPath() + "' in config.yml")); sender.send(locale.get(ManageLang.PROGRESS_FAIL).toString("see '" + ExportSettings.SERVER_JSON.getPath() + "' in config.yml"));
} }
} catch (ExportException e) { } catch (ExportException e) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL)); sender.send(locale.get(ManageLang.PROGRESS_FAIL).toString(e.getMessage()));
sender.sendMessage("§c" + e.toString());
} }
}); });
} }
private void exportPlayers(Sender sender) { private void exportPlayers(CMDSender sender) {
boolean exportPlayerJSON = config.isTrue(ExportSettings.PLAYER_JSON); boolean exportPlayerJSON = config.isTrue(ExportSettings.PLAYER_JSON);
boolean exportPlayerHTML = config.isTrue(ExportSettings.PLAYER_PAGES); boolean exportPlayerHTML = config.isTrue(ExportSettings.PLAYER_PAGES);
boolean exportPlayersHtml = config.isTrue(ExportSettings.PLAYERS_PAGE); boolean exportPlayersHtml = config.isTrue(ExportSettings.PLAYERS_PAGE);
if (!exportPlayerJSON && !exportPlayerHTML) { if (!exportPlayerJSON && !exportPlayerHTML) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL)); throw new IllegalArgumentException("'" + ExportSettings.PLAYER_JSON.getPath() + "' & '" + ExportSettings.PLAYER_PAGES.getPath() + "': false (config.yml)");
sender.sendMessage("§c'" + ExportSettings.PLAYER_JSON.getPath() + "' & '" + ExportSettings.PLAYER_PAGES.getPath() + "': false");
return;
} }
if (exportPlayersHtml) { if (exportPlayersHtml) {
@ -151,8 +121,8 @@ public class ManageExportCommand extends CommandNode {
processing.submitNonCritical(() -> performExport(sender, exportPlayerJSON, exportPlayerHTML)); processing.submitNonCritical(() -> performExport(sender, exportPlayerJSON, exportPlayerHTML));
} }
private void performExport(Sender sender, boolean exportPlayerJSON, boolean exportPlayerHTML) { private void performExport(CMDSender sender, boolean exportPlayerJSON, boolean exportPlayerHTML) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); sender.send(locale.getString(ManageLang.PROGRESS_START));
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();
@ -168,14 +138,14 @@ public class ManageExportCommand extends CommandNode {
} }
i++; i++;
if (i % 1000 == 0) { if (i % 1000 == 0) {
sender.sendMessage(i + " / " + size + " processed.."); sender.send(i + " / " + size + " processed..");
} }
} }
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.send(locale.getString(ManageLang.PROGRESS_SUCCESS));
if (failed != 0) { if (failed != 0) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL)); sender.send(locale.getString(ManageLang.PROGRESS_FAIL));
sender.sendMessage(" §2✔: §f" + (i - failed)); sender.send(" §2✔: §f" + (i - failed));
sender.sendMessage(" §c✕: §f" + failed); sender.send(" §c✕: §f" + failed);
} }
} }
} }

View File

@ -1,3 +1,19 @@
/*
* 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.commands.use; package com.djrapitops.plan.commands.use;
import com.djrapitops.plan.utilities.analysis.Maximum; import com.djrapitops.plan.utilities.analysis.Maximum;

View File

@ -1,3 +1,19 @@
/*
* 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.commands.use; package com.djrapitops.plan.commands.use;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -1,3 +1,19 @@
/*
* 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.commands.use; package com.djrapitops.plan.commands.use;
public class PlayerChatFormatter extends ChatFormatter { public class PlayerChatFormatter extends ChatFormatter {

View File

@ -0,0 +1,33 @@
/*
* 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.modules;
import dagger.Module;
import dagger.Provides;
import javax.inject.Named;
@Module
public class ServerCommandModule {
@Provides
@Named("mainCommandName")
String provideMainCommandName() {
return "plan";
}
}

View File

@ -21,6 +21,7 @@ import com.djrapitops.plan.commands.OldPlanCommand;
import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.PlaceholderModule; import com.djrapitops.plan.modules.PlaceholderModule;
import com.djrapitops.plan.modules.ServerCommandModule;
import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule;
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule; import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule; import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
@ -42,6 +43,7 @@ import javax.inject.Singleton;
APFModule.class, APFModule.class,
PlaceholderModule.class, PlaceholderModule.class,
ServerCommandModule.class,
NukkitServerPropertiesModule.class, NukkitServerPropertiesModule.class,
NukkitSuperClassBindingModule.class NukkitSuperClassBindingModule.class
}) })

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.commands.OldPlanCommand;
import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.PlaceholderModule; import com.djrapitops.plan.modules.PlaceholderModule;
import com.djrapitops.plan.modules.ServerCommandModule;
import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule;
import com.djrapitops.plan.modules.sponge.SpongePlanModule; import com.djrapitops.plan.modules.sponge.SpongePlanModule;
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule; import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
@ -41,6 +42,7 @@ import javax.inject.Singleton;
APFModule.class, APFModule.class,
PlaceholderModule.class, PlaceholderModule.class,
ServerCommandModule.class,
SpongeSuperClassBindingModule.class, SpongeSuperClassBindingModule.class,
SpongeServerPropertiesModule.class SpongeServerPropertiesModule.class
}) })