Skip to content

Commit

Permalink
修复了在迁移领地数据到新服务器后无法索引到世界的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Oct 11, 2024
1 parent 5732fe0 commit 8e25150
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
12 changes: 9 additions & 3 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "cn.lunadeer"
artifactId = "DominionAPI"
version = "2.0-SNAPSHOT"
// 添加组件
from(components["java"])
version = "2.1-SNAPSHOT"
// Add only the necessary artifacts manually to avoid conflicts
artifact(tasks.jar.get()) // The main JAR file without classifier
artifact(tasks.named<Jar>("sourcesJar").get()) {
classifier = "sources"
}
artifact(tasks.named<Jar>("javadocJar").get()) {
classifier = "javadoc"
}
}
}
repositories {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var libraries = listOf<String>()
libraries = libraries + "cn.lunadeer:MinecraftPluginUtils:2.0.2"

group = "cn.lunadeer"
version = "2.13.5-beta"
version = "2.13.6-beta"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.XLogger;
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 org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DatabaseTables {
public static void migrate() {
Expand Down Expand Up @@ -279,7 +285,19 @@ public static void Export(CommandSender sender) {
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"));
Map<String, String> world_uid_map = Dominion.instance.getServer().getWorlds().stream().collect(HashMap::new, (m, w) -> m.put(w.getName(), w.getUID().toString()), HashMap::putAll);
YamlConfiguration world_uid = new YamlConfiguration();
for (Map.Entry<String, String> entry : world_uid_map.entrySet()) {
world_uid.set(entry.getKey(), entry.getValue());
}
try {
world_uid.save(new File(export_path, "world_uid_mapping.yml"));
} catch (Exception e) {
XLogger.err("Save world_uid_mapping.yml failed: %s", e.getMessage());
return;
}
Notification.info(sender, Translation.Commands_Operator_ExportDBSuccess);
Notification.info(sender, "Path: %s", export_path.getAbsolutePath());
});
}

Expand All @@ -290,11 +308,40 @@ public static void Import(CommandSender sender) {
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"));
Map<String, String> world_uid_map = Dominion.instance.getServer().getWorlds().stream().collect(HashMap::new, (m, w) -> m.put(w.getName(), w.getUID().toString()), HashMap::putAll);
File player_name_csv = new File(export_path, "player_name.csv");
File privilege_template_csv = new File(export_path, "privilege_template.csv");
File dominion_csv = new File(export_path, "dominion.csv");
File world_uid_mapping = new File(export_path, "world_uid_mapping.yml");
File dominion_group_csv = new File(export_path, "dominion_group.csv");
File dominion_member_csv = new File(export_path, "dominion_member.csv");
if (!player_name_csv.exists() || !privilege_template_csv.exists() || !dominion_csv.exists() || !world_uid_mapping.exists() || !dominion_group_csv.exists() || !dominion_member_csv.exists()) {
Notification.error(sender, Translation.Commands_Operator_ImportDBIncompleteFail);
return;
}
try {
String dominion_file_str = Files.readString(dominion_csv.toPath());
YamlConfiguration world_uid = YamlConfiguration.loadConfiguration(world_uid_mapping);
for (String key : world_uid.getKeys(false)) {
if (world_uid_map.containsKey(key)) {
String old_uid = world_uid.getString(key);
String new_uid = world_uid_map.get(key);
if (old_uid == null || new_uid == null) {
continue;
}
dominion_file_str = dominion_file_str.replace(old_uid, world_uid_map.get(key));
}
}
Files.writeString(dominion_csv.toPath(), dominion_file_str);
} catch (IOException e) {
XLogger.err("Import world_uid_mapping.yml failed: %s", e.getMessage());
return;
}
Common.ImportCSV("player_name", "id", player_name_csv);
Common.ImportCSV("privilege_template", "id", privilege_template_csv);
Common.ImportCSV("dominion", "id", dominion_csv);
Common.ImportCSV("dominion_group", "id", dominion_group_csv);
Common.ImportCSV("dominion_member", "id", dominion_member_csv);
Notification.info(sender, Translation.Commands_Operator_ImportDBSuccess);
Operator.reloadCache(sender, new String[0]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public class Translation extends Localization {
public static i18n Commands_Operator_ImportDBSuccess;
@i18nField(defaultValue = "没有可导入的数据")
public static i18n Commands_Operator_ImportDBFail;
@i18nField(defaultValue = "导入失败,数据不完整,请重新导出文件")
public static i18n Commands_Operator_ImportDBIncompleteFail;

@i18nField(defaultValue = "用法: /dominion template create <模板名称>")
public static i18n Commands_Template_CreateTemplateUsage;
Expand Down
6 changes: 3 additions & 3 deletions docs/zh-cn/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
}
dependencies {
compileOnly("cn.lunadeer:DominionAPI:2.0-SNAPSHOT")
compileOnly("cn.lunadeer:DominionAPI:2.1-SNAPSHOT")
}
```

Expand All @@ -28,7 +28,7 @@ repositories {
}

dependencies {
compileOnly("cn.lunadeer:DominionAPI:2.0-SNAPSHOT")
compileOnly("cn.lunadeer:DominionAPI:2.1-SNAPSHOT")
}
```

Expand All @@ -47,7 +47,7 @@ dependencies {
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>DominionAPI</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit 8e25150

Please sign in to comment.