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 {
toolVersion "8.33"
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.modules.APFModule;
import com.djrapitops.plan.modules.PlaceholderModule;
import com.djrapitops.plan.modules.ServerCommandModule;
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
@ -42,6 +43,7 @@ import javax.inject.Singleton;
APFModule.class,
PlaceholderModule.class,
ServerCommandModule.class,
BukkitServerPropertiesModule.class,
BukkitSuperClassBindingModule.class
})

View File

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

View File

@ -44,6 +44,7 @@ public class PlanCommand {
private final RegistrationCommands registrationCommands;
private final PluginStatusCommands statusCommands;
private final DatabaseCommands databaseCommands;
private final DataUtilityCommands dataUtilityCommands;
private final ErrorLogger errorLogger;
@Inject
@ -56,6 +57,7 @@ public class PlanCommand {
RegistrationCommands registrationCommands,
PluginStatusCommands statusCommands,
DatabaseCommands databaseCommands,
DataUtilityCommands dataUtilityCommands,
ErrorLogger errorLogger
) {
this.commandName = commandName;
@ -66,6 +68,7 @@ public class PlanCommand {
this.registrationCommands = registrationCommands;
this.statusCommands = statusCommands;
this.databaseCommands = databaseCommands;
this.dataUtilityCommands = dataUtilityCommands;
this.errorLogger = errorLogger;
}
@ -98,6 +101,8 @@ public class PlanCommand {
.subcommand(reloadCommand())
.subcommand(disableCommand())
.subcommand(databaseCommand())
.subcommand(export())
.exceptionHandler(this::handleException)
.build();
}
@ -183,7 +188,7 @@ public class PlanCommand {
.optionalArgument("username", "Username of another user. If not specified linked user is used.")
.description("Unregister user of Plan website")
.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();
}
@ -326,4 +331,15 @@ public class PlanCommand {
.onCommand(databaseCommands::onUninstalled)
.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;
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
* 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.exceptions.ExportException;
import com.djrapitops.plan.identification.ServerInfo;
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.paths.ExportSettings;
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.DeepHelpLang;
import com.djrapitops.plan.settings.locale.lang.ManageLang;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
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.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 {
public class DataUtilityCommands {
private final Locale locale;
private final ColorScheme colorScheme;
private final PlanConfig config;
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
@ -61,88 +48,71 @@ public class ManageExportCommand extends CommandNode {
private final Processing processing;
@Inject
public ManageExportCommand(
public DataUtilityCommands(
Locale locale,
ColorScheme colorScheme,
PlanConfig config,
DBSystem dbSystem,
ServerInfo serverInfo,
Exporter exporter,
Processing processing
) {
super("export", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
this.locale = locale;
this.colorScheme = colorScheme;
this.config = config;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.exporter = exporter;
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;
}
private void ensureDatabaseIsOpen() {
Database.State dbState = dbSystem.getDatabase().getState();
if (dbState != Database.State.OPEN) {
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
return;
throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
}
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)) {
return this::exportPlayers;
} else if ("server_json".endsWith(exportArg)) {
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)) {
sender.sendMessage("§c'" + ExportSettings.SERVER_JSON.getPath() + "': false");
return;
throw new IllegalArgumentException("'" + ExportSettings.SERVER_JSON.getPath() + "': false");
}
processing.submitNonCritical(() -> {
try {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
sender.send(locale.getString(ManageLang.PROGRESS_START));
if (exporter.exportServerJSON(serverInfo.getServer())) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
sender.send(locale.getString(ManageLang.PROGRESS_SUCCESS));
} 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) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL));
sender.sendMessage("§c" + e.toString());
sender.send(locale.get(ManageLang.PROGRESS_FAIL).toString(e.getMessage()));
}
});
}
private void exportPlayers(Sender sender) {
private void exportPlayers(CMDSender sender) {
boolean exportPlayerJSON = config.isTrue(ExportSettings.PLAYER_JSON);
boolean exportPlayerHTML = config.isTrue(ExportSettings.PLAYER_PAGES);
boolean exportPlayersHtml = config.isTrue(ExportSettings.PLAYERS_PAGE);
if (!exportPlayerJSON && !exportPlayerHTML) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL));
sender.sendMessage("§c'" + ExportSettings.PLAYER_JSON.getPath() + "' & '" + ExportSettings.PLAYER_PAGES.getPath() + "': false");
return;
throw new IllegalArgumentException("'" + ExportSettings.PLAYER_JSON.getPath() + "' & '" + ExportSettings.PLAYER_PAGES.getPath() + "': false (config.yml)");
}
if (exportPlayersHtml) {
@ -151,8 +121,8 @@ public class ManageExportCommand extends CommandNode {
processing.submitNonCritical(() -> performExport(sender, exportPlayerJSON, exportPlayerHTML));
}
private void performExport(Sender sender, boolean exportPlayerJSON, boolean exportPlayerHTML) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
private void performExport(CMDSender sender, boolean exportPlayerJSON, boolean exportPlayerHTML) {
sender.send(locale.getString(ManageLang.PROGRESS_START));
Map<UUID, String> players = dbSystem.getDatabase().query(UserIdentifierQueries.fetchAllPlayerNames());
int size = players.size();
@ -168,14 +138,14 @@ public class ManageExportCommand extends CommandNode {
}
i++;
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) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL));
sender.sendMessage(" §2✔: §f" + (i - failed));
sender.sendMessage(" §c✕: §f" + failed);
sender.send(locale.getString(ManageLang.PROGRESS_FAIL));
sender.send(" §2✔: §f" + (i - 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;
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;
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;
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.modules.APFModule;
import com.djrapitops.plan.modules.PlaceholderModule;
import com.djrapitops.plan.modules.ServerCommandModule;
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
@ -42,6 +43,7 @@ import javax.inject.Singleton;
APFModule.class,
PlaceholderModule.class,
ServerCommandModule.class,
NukkitServerPropertiesModule.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.modules.APFModule;
import com.djrapitops.plan.modules.PlaceholderModule;
import com.djrapitops.plan.modules.ServerCommandModule;
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
@ -41,6 +42,7 @@ import javax.inject.Singleton;
APFModule.class,
PlaceholderModule.class,
ServerCommandModule.class,
SpongeSuperClassBindingModule.class,
SpongeServerPropertiesModule.class
})