From a487f23bf3ffa24e81a2296473bfb8e78fd52e93 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Mon, 2 Mar 2020 13:36:26 +0800 Subject: [PATCH] SAAAAAAAND! Former-commit-id: 3fbc15d28e0de1d61682248bcea42fdb066e263d --- .../quickshop/Command/CommandManager.java | 7 ++ .../SubCommands/SubCommand_Export.java | 79 +++++++++++++++++++ src/main/resources/plugin.yml | 4 +- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Export.java diff --git a/src/main/java/org/maxgamer/quickshop/Command/CommandManager.java b/src/main/java/org/maxgamer/quickshop/Command/CommandManager.java index 046ee9fed..191a9a5ae 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/CommandManager.java +++ b/src/main/java/org/maxgamer/quickshop/Command/CommandManager.java @@ -260,6 +260,13 @@ public class CommandManager implements TabCompleter, CommandExecutor { .permission("quickshop.recovery") .executor(new SubCommand_Recovery()) .build()); + registerCmd( + CommandContainer.builder() + .prefix("export") + .hidden(true) + .permission("quickshop.export") + .executor(new SubCommand_Export()) + .build()); } private void registerCmd(CommandContainer container) { diff --git a/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Export.java b/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Export.java new file mode 100644 index 000000000..70f084ad7 --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Export.java @@ -0,0 +1,79 @@ +/* + * This file is a part of project QuickShop, the name is SubCommand_Amount.java + * Copyright (C) Ghost_chu + * Copyright (C) Bukkit Commons Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +package org.maxgamer.quickshop.Command.SubCommands; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.List; +import lombok.SneakyThrows; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.Command.CommandProcesser; +import org.maxgamer.quickshop.QuickShop; + +public class SubCommand_Export implements CommandProcesser { + + private final QuickShop plugin = QuickShop.instance; + + @Override + @SneakyThrows + public synchronized void onCommand( + @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) { + if (!(sender instanceof ConsoleCommandSender)) { + return; + } + File file = new File(plugin.getDataFolder(), "export.txt"); + if (file.exists()) { + file.delete(); + file.createNewFile(); + } else { + file.createNewFile(); + } + + new BukkitRunnable() { + @SneakyThrows + @Override + public void run() { + StringBuilder finalReport = new StringBuilder(); + plugin + .getShopLoader() + .getShopsInDatabase() + .forEach((shop -> finalReport.append("\t").append(shop).append("\n"))); + BufferedWriter outputStream = new BufferedWriter(new FileWriter(file, false)); + outputStream.write(finalReport.toString()); + outputStream.close(); + sender.sendMessage("Done."); + } + }.runTaskAsynchronously(plugin); + + + } + + @NotNull + @Override + public List onTabComplete( + @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) { + return null; + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6898c2da4..acae8a903 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -89,7 +89,7 @@ permissions: description: Switch to or from developer mode default: op quickshop.export: - description: Allows exporting the database to mysql or sqlite + description: Allows exporting the database to a plain file default: op quickshop.alerts: description: Alert the player when someone tries to cheat with the display item @@ -123,4 +123,4 @@ permissions: default: op quickshop.recovery: description: Permission to use /qs recovery, WARNING DO NOT EXECUTE THIS COMMAND IF YOU DID NOT KNOW WHAT WILL HAPPEND - default: false \ No newline at end of file + default: false