Fix freeze on startup (#2368)

* DON'T load resources in static init!!!

* Update src/main/java/emu/grasscutter/Grasscutter.java

Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>

* Update src/main/java/emu/grasscutter/tools/Tools.java

Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>

---------

Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
This commit is contained in:
jie65535 2023-09-17 10:55:46 +08:00 committed by GitHub
parent 5f5e6c38b1
commit fdad4218e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View File

@ -158,6 +158,8 @@ public final class Grasscutter {
// Generate handbooks.
Tools.createGmHandbooks(false);
// Generate gacha mappings.
Tools.generateGachaMappings();
}
// Start servers.

View File

@ -114,8 +114,6 @@ public class DataLoader {
} catch (Exception e) {
Grasscutter.getLogger().error("An error occurred while trying to check the data folder.", e);
}
generateGachaMappings();
}
private static void checkAndCopyData(String name) {
@ -131,16 +129,4 @@ public class DataLoader {
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);
}
}
}
}

View File

@ -10,6 +10,7 @@ import emu.grasscutter.data.common.ItemUseData;
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;
@ -311,8 +312,19 @@ public final class Tools {
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");