Skip to content

Commit

Permalink
检测到BotName变动时提示重置数据文件
Browse files Browse the repository at this point in the history
  • Loading branch information
SerendipityR-2022 authored Aug 20, 2022
1 parent d6b5bb2 commit d594732
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cn.serendipityr.EndMinecraftPlusV2.VersionControl.ProtocolLibs;

public class EndMinecraftPlusV2 {
public static String ver = "1.2.2";
public static String ver = "1.2.3";

public static void main(String[] args) {
System.out.println("========================-Forked by SerendipityR-========================");
Expand Down
26 changes: 26 additions & 0 deletions src/cn/serendipityr/EndMinecraftPlusV2/Tools/DataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,39 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class DataUtil {
public static boolean notModify = false;
public static List<String> botRegPasswords;
public static HashMap<String,String> botRegPasswordsMap = new HashMap<>();

public static void loadData() {
File dataFile = new File("data.yml");

if (dataFile.exists()) {
YamlConfiguration data = YamlConfiguration.loadConfiguration(dataFile);
botRegPasswords = data.getStringList("Data");
botRegPasswords.remove("");

String lastBotName = data.getString("LastBotName");
if (lastBotName != null && !ConfigUtil.BotName.equals(lastBotName)) {
LogUtil.doLog(-1, "检测到BotName已被修改,是否重置数据文件以使更改生效? [y/n]:", "DataUtil");
Scanner scanner = new Scanner(System.in);
if (scanner.nextLine().contains("y")) {
if (dataFile.delete()) {
LogUtil.doLog(0, "数据文件已成功重置。", "DataUtil");
} else {
LogUtil.doLog(0, "修改数据文件时出错,操作成功未完成。", "DataUtil");
}
LogUtil.emptyLog();
loadData();
return;
}

notModify = true;
LogUtil.emptyLog();
}
} else {
botRegPasswords = new ArrayList<>();
}
Expand Down Expand Up @@ -48,6 +70,10 @@ public static void updateData(List<String> dataList) {

data.set("Data", dataList);

if (!notModify) {
data.set("LastBotName", ConfigUtil.BotName);
}

try {
data.save(dataFile);
} catch (IOException e) {
Expand Down
3 changes: 1 addition & 2 deletions src/data.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Data:
- ""
Data: []

0 comments on commit d594732

Please sign in to comment.