Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix freeze on startup #2368

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/emu/grasscutter/Grasscutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public static void main(String[] args) throws Exception {

// Generate handbooks.
Tools.createGmHandbooks(false);
// Generate gacha mappings.
Tools.generateGachaMappings();
}

// Start servers.
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/emu/grasscutter/data/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ public static void checkAllFiles() {
} catch (Exception e) {
Grasscutter.getLogger().error("An error occurred while trying to check the data folder.", e);
}

generateGachaMappings();
}

private static void checkAndCopyData(String name) {
Expand All @@ -131,16 +129,4 @@ private static void checkAndCopyData(String name) {
FileUtils.copyResource("/defaults/data/" + name, filePath.toString());
}
}

private static void generateGachaMappings() {
var path = GachaHandler.getGachaMappingsPath();
if (!Files.exists(path)) {
try {
Grasscutter.getLogger().debug("Creating default '" + path + "' data");
Tools.createGachaMappings(path);
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to create gacha mappings. \n" + exception);
}
}
}
}
14 changes: 13 additions & 1 deletion src/main/java/emu/grasscutter/tools/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import emu.grasscutter.data.excels.*;
import emu.grasscutter.data.excels.achievement.AchievementData;
import emu.grasscutter.data.excels.avatar.AvatarData;
import emu.grasscutter.server.http.handlers.GachaHandler;
import emu.grasscutter.utils.*;
import emu.grasscutter.utils.lang.Language;
import emu.grasscutter.utils.lang.Language.TextStrings;
Expand Down Expand Up @@ -311,8 +312,19 @@ public static List<String> createGachaMappingJsons() {
return sbs.stream().map(StringBuilder::toString).toList();
}

public static void generateGachaMappings() {
var path = GachaHandler.getGachaMappingsPath();
if (!Files.exists(path)) {
try {
Grasscutter.getLogger().debug("Creating default '" + path + "' data");
Tools.createGachaMappings(path);
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to create gacha mappings. \n" + exception);
}
}
}

public static void createGachaMappings(Path location) throws IOException {
ResourceLoader.loadResources();
List<String> jsons = createGachaMappingJsons();
var usedLocales = new HashSet<String>();
StringBuilder sb = new StringBuilder("mappings = {\n");
Expand Down