mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2025-01-12 05:54:26 +08:00
新增数据库导入导出功能,便于迁移、备份数据库
This commit is contained in:
parent
ab838c5596
commit
897c6f17fd
@ -38,7 +38,7 @@ allprojects {
|
||||
compileOnly("us.dynmap:DynmapCoreAPI:3.4")
|
||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||
|
||||
implementation("cn.lunadeer:MinecraftPluginUtils:1.3.9-SNAPSHOT")
|
||||
implementation("cn.lunadeer:MinecraftPluginUtils:1.3.10-SNAPSHOT")
|
||||
implementation("org.yaml:snakeyaml:2.0")
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,12 @@ public class Commands implements TabExecutor {
|
||||
case "export_mca":
|
||||
Operator.exportMca(sender, args);
|
||||
break;
|
||||
case "export_db":
|
||||
Operator.exportDatabase(sender, args);
|
||||
break;
|
||||
case "import_db":
|
||||
Operator.importDatabase(sender, args);
|
||||
break;
|
||||
// case "set_config":
|
||||
// SetConfig.handler(sender, args);
|
||||
// break;
|
||||
@ -216,6 +222,8 @@ public class Commands implements TabExecutor {
|
||||
"reload_cache",
|
||||
"reload_config",
|
||||
"export_mca",
|
||||
"export_db",
|
||||
"import_db",
|
||||
"sys_config",
|
||||
"all_dominion",
|
||||
"set_map_color",
|
||||
|
@ -3,6 +3,7 @@ package cn.lunadeer.dominion.commands;
|
||||
import cn.lunadeer.dominion.Cache;
|
||||
import cn.lunadeer.dominion.Dominion;
|
||||
import cn.lunadeer.dominion.api.dtos.DominionDTO;
|
||||
import cn.lunadeer.dominion.managers.DatabaseTables;
|
||||
import cn.lunadeer.dominion.managers.Translation;
|
||||
import cn.lunadeer.dominion.utils.map.MapRender;
|
||||
import cn.lunadeer.minecraftpluginutils.GiteaReleaseCheck;
|
||||
@ -140,6 +141,42 @@ public class Operator {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据库
|
||||
* /dominion export_db [confirm]
|
||||
*
|
||||
* @param sender 发送者
|
||||
* @param args 参数
|
||||
*/
|
||||
public static void exportDatabase(CommandSender sender, String[] args) {
|
||||
if (!hasPermission(sender, "dominion.admin")) {
|
||||
return;
|
||||
}
|
||||
if (args.length != 2 || !args[1].equals("confirm")) {
|
||||
Notification.warn(sender, Translation.Commands_Operator_ExportDBConfirm);
|
||||
return;
|
||||
}
|
||||
DatabaseTables.Export(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据库
|
||||
* /dominion import_db [confirm]
|
||||
*
|
||||
* @param sender 发送者
|
||||
* @param args 参数
|
||||
*/
|
||||
public static void importDatabase(CommandSender sender, String[] args) {
|
||||
if (!hasPermission(sender, "dominion.admin")) {
|
||||
return;
|
||||
}
|
||||
if (args.length != 2 || !args[1].equals("confirm")) {
|
||||
Notification.warn(sender, Translation.Commands_Operator_ImportDBConfirm);
|
||||
return;
|
||||
}
|
||||
DatabaseTables.Import(sender);
|
||||
}
|
||||
|
||||
public static void version(CommandSender sender, String[] args) {
|
||||
if (!hasPermission(sender, "dominion.admin")) {
|
||||
return;
|
||||
|
@ -1,14 +1,19 @@
|
||||
package cn.lunadeer.dominion.managers;
|
||||
|
||||
import cn.lunadeer.dominion.Dominion;
|
||||
import cn.lunadeer.dominion.commands.Operator;
|
||||
import cn.lunadeer.dominion.dtos.Flag;
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.minecraftpluginutils.Scheduler;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.*;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.AddColumn;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.RemoveColumn;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
|
||||
@ -260,4 +265,38 @@ public class DatabaseTables {
|
||||
new RemoveColumn("world").table("dominion").IfExists().execute();
|
||||
}
|
||||
}
|
||||
|
||||
private static final File export_path = new File(Dominion.instance.getDataFolder(), "ExportedDatabaseTables");
|
||||
|
||||
public static void Export(CommandSender sender) {
|
||||
Scheduler.runTaskAsync(() -> {
|
||||
Notification.info(sender, Translation.Commands_Operator_ExportDBBegin);
|
||||
if (!export_path.exists()) {
|
||||
export_path.mkdirs();
|
||||
}
|
||||
Common.ExportCSV("player_name", new File(export_path, "player_name.csv"));
|
||||
Common.ExportCSV("privilege_template", new File(export_path, "privilege_template.csv"));
|
||||
Common.ExportCSV("dominion", new File(export_path, "dominion.csv"));
|
||||
Common.ExportCSV("dominion_group", new File(export_path, "dominion_group.csv"));
|
||||
Common.ExportCSV("dominion_member", new File(export_path, "dominion_member.csv"));
|
||||
Notification.info(sender, Translation.Commands_Operator_ExportDBSuccess);
|
||||
});
|
||||
}
|
||||
|
||||
public static void Import(CommandSender sender) {
|
||||
Scheduler.runTaskAsync(() -> {
|
||||
if (!export_path.exists()) {
|
||||
Notification.error(sender, Translation.Commands_Operator_ImportDBFail);
|
||||
return;
|
||||
}
|
||||
Notification.info(sender, Translation.Commands_Operator_ImportDBBegin);
|
||||
Common.ImportCSV("player_name", "id", new File(export_path, "player_name.csv"));
|
||||
Common.ImportCSV("privilege_template", "id", new File(export_path, "privilege_template.csv"));
|
||||
Common.ImportCSV("dominion", "id", new File(export_path, "dominion.csv"));
|
||||
Common.ImportCSV("dominion_group", "id", new File(export_path, "dominion_group.csv"));
|
||||
Common.ImportCSV("dominion_member", "id", new File(export_path, "dominion_member.csv"));
|
||||
Notification.info(sender, Translation.Commands_Operator_ImportDBSuccess);
|
||||
Operator.reloadCache(sender, new String[0]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +148,20 @@ public class Translation extends Localization {
|
||||
public static i18n Commands_Operator_ReloadingConfig;
|
||||
@i18nField(defaultValue = "配置文件已重新加载")
|
||||
public static i18n Commands_Operator_ReloadedConfig;
|
||||
@i18nField(defaultValue = "你正在尝试导出数据库表,此行为会踢出所有玩家并关闭服务器,如确认继续请输入 /dominion export_db confirm")
|
||||
public static i18n Commands_Operator_ExportDBConfirm;
|
||||
@i18nField(defaultValue = "正在导出数据库表...")
|
||||
public static i18n Commands_Operator_ExportDBBegin;
|
||||
@i18nField(defaultValue = "数据库表导出完成")
|
||||
public static i18n Commands_Operator_ExportDBSuccess;
|
||||
@i18nField(defaultValue = "你正在尝试导入数据库表,此行为会踢出所有玩家并关闭服务器,如确认继续请输入 /dominion import_db confirm")
|
||||
public static i18n Commands_Operator_ImportDBConfirm;
|
||||
@i18nField(defaultValue = "正在导入数据库表...")
|
||||
public static i18n Commands_Operator_ImportDBBegin;
|
||||
@i18nField(defaultValue = "数据库表导入完成")
|
||||
public static i18n Commands_Operator_ImportDBSuccess;
|
||||
@i18nField(defaultValue = "没有可导入的数据")
|
||||
public static i18n Commands_Operator_ImportDBFail;
|
||||
|
||||
@i18nField(defaultValue = "用法: /dominion template create <模板名称>")
|
||||
public static i18n Commands_Template_CreateTemplateUsage;
|
||||
|
Loading…
Reference in New Issue
Block a user