From 5c86bb8380359b694128357aee79b2d6d7437eba Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Fri, 2 Jan 2026 22:13:24 -0800 Subject: [PATCH] Load data versions from a json file --- .gitignore | 5 +- src/main/java/emu/nebula/GameConstants.java | 19 -------- src/main/java/emu/nebula/Nebula.java | 54 +++++++++++++++++++-- src/main/resources/versions.json | 7 +++ 4 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/versions.json diff --git a/.gitignore b/.gitignore index bcd493c..b81233f 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,9 @@ tmp/ /*.jar /*.sh +# Custom external data version json +/versions.json + # Extra Nebula Handbook.txt config.json @@ -78,4 +81,4 @@ patchlist.json *.exe *.p12 BuildConfig.java -Test.java \ No newline at end of file +Test.java diff --git a/src/main/java/emu/nebula/GameConstants.java b/src/main/java/emu/nebula/GameConstants.java index 8a1e97e..3a2b25d 100644 --- a/src/main/java/emu/nebula/GameConstants.java +++ b/src/main/java/emu/nebula/GameConstants.java @@ -9,25 +9,6 @@ public class GameConstants { public static final String VERSION = "1.4.0"; public static int DATA_VERSION = 0; - // Set data versions for each region - // TODO move this to a json file inside the jar to make it easier to auto-update - static { - RegionConfig.getRegion("global") - .setDataVersion(75); - - RegionConfig.getRegion("kr") - .setDataVersion(82); - - RegionConfig.getRegion("jp") - .setDataVersion(79); - - RegionConfig.getRegion("tw") - .setDataVersion(76); - - RegionConfig.getRegion("cn") - .setDataVersion(77); - } - public static final ZoneId UTC_ZONE = ZoneId.of("UTC"); public static final String PROTO_BASE_TYPE_URL = "type.googleapis.com/proto."; diff --git a/src/main/java/emu/nebula/Nebula.java b/src/main/java/emu/nebula/Nebula.java index 127fada..6fc2203 100644 --- a/src/main/java/emu/nebula/Nebula.java +++ b/src/main/java/emu/nebula/Nebula.java @@ -3,6 +3,7 @@ package emu.nebula; import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,16 +43,19 @@ public class Nebula { @Getter private static CommandManager commandManager; @Getter private static PluginManager pluginManager; + private static boolean generateHandbook = true; + public static void main(String[] args) { - // Load config first - Nebula.loadConfig(); - // Start Server Nebula.getLogger().info("Starting Nebula " + getJarVersion()); Nebula.getLogger().info("Git hash: " + getGitHash()); - Nebula.getLogger().info("Game version: " + GameConstants.getGameVersion()); - boolean generateHandbook = true; + // Load config and data versions first + Nebula.loadConfig(); + Nebula.loadDataVersions(); + + // Output game version + Nebula.getLogger().info("Game version: " + GameConstants.getGameVersion()); // Load keys AeadHelper.loadKeys(); @@ -182,6 +186,46 @@ public class Nebula { } } + // Data versions + + public static void loadDataVersions() { + // Data versions + Map versions = null; + + // Get version file + var file = new File("./versions.json"); + + if (file.exists()) { + // Load data versions from an external file first, in case the internal versions.json is out of date + try (FileReader reader = new FileReader(file)) { + versions = JsonUtils.loadToMap(reader, String.class, Integer.class); + } catch (Exception e) { + // Ignored + } + } + + if (versions == null) { + // Loads data versions from the internal versions.json from the jar resources + try (var stream = Nebula.class.getResourceAsStream("/versions.json"); var reader = new InputStreamReader(stream)) { + versions = JsonUtils.loadToMap(reader, String.class, Integer.class); + } catch (Exception e) { + // Ignored + } + } + + // Sanity check + if (versions == null) { + Nebula.getLogger().error("Could not load versions.json!"); + return; + } + + // Load data version for region + for (var entry : versions.entrySet()) { + RegionConfig.getRegion(entry.getKey()) + .setDataVersion(entry.getValue()); + } + } + // Build Config private static String getJarVersion() { diff --git a/src/main/resources/versions.json b/src/main/resources/versions.json new file mode 100644 index 0000000..e8fd942 --- /dev/null +++ b/src/main/resources/versions.json @@ -0,0 +1,7 @@ +{ + "global": 75, + "kr": 82, + "jp": 79, + "tw": 76, + "cn": 77 +} \ No newline at end of file