From dc293cd7ea1f7cbb48311fd39e664f60ff0e18be Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:22:06 -0800 Subject: [PATCH] Improve how the data version is handled --- src/main/java/emu/nebula/Config.java | 2 +- src/main/java/emu/nebula/GameConstants.java | 14 ++++++++++++-- src/main/java/emu/nebula/Nebula.java | 8 ++++---- src/main/java/emu/nebula/net/NetMsgIdUtils.java | 2 +- src/main/java/emu/nebula/server/HttpServer.java | 4 ++-- src/main/java/emu/nebula/util/Handbook.java | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/emu/nebula/Config.java b/src/main/java/emu/nebula/Config.java index 9e14a5c..c42c5ac 100644 --- a/src/main/java/emu/nebula/Config.java +++ b/src/main/java/emu/nebula/Config.java @@ -22,8 +22,8 @@ public class Config { public ServerRates serverRates = new ServerRates(); public LogOptions logOptions = new LogOptions(); + public int customDataVersion = 0; public String resourceDir = "./resources"; - public String dataDir = "./data"; public String patchListPath = "./patchlist.json"; @Getter diff --git a/src/main/java/emu/nebula/GameConstants.java b/src/main/java/emu/nebula/GameConstants.java index 6fb36ba..66a52de 100644 --- a/src/main/java/emu/nebula/GameConstants.java +++ b/src/main/java/emu/nebula/GameConstants.java @@ -3,8 +3,8 @@ package emu.nebula; import java.time.ZoneId; public class GameConstants { - public static final int DATA_VERSION = 46; - public static final String VERSION = "1.0.0." + DATA_VERSION; + private static final int DATA_VERSION = 46; + private static final String VERSION = "1.0.0"; public static final ZoneId UTC_ZONE = ZoneId.of("UTC"); @@ -33,4 +33,14 @@ public class GameConstants { public static final int MAX_FRIENDSHIPS = 50; public static final int MAX_PENDING_FRIENDSHIPS = 30; + + // Helper functions + + public static String getGameVersion() { + return VERSION + "." + getDataVersion(); + } + + public static int getDataVersion() { + return Nebula.getConfig().getCustomDataVersion() > 0 ? Nebula.getConfig().getCustomDataVersion() : DATA_VERSION ; + } } diff --git a/src/main/java/emu/nebula/Nebula.java b/src/main/java/emu/nebula/Nebula.java index a31dab0..f43a933 100644 --- a/src/main/java/emu/nebula/Nebula.java +++ b/src/main/java/emu/nebula/Nebula.java @@ -42,16 +42,16 @@ public class Nebula { @Getter private static PluginManager pluginManager; 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.VERSION); + Nebula.getLogger().info("Game version: " + GameConstants.getGameVersion()); boolean generateHandbook = true; - // Load config + commands - Nebula.loadConfig(); - // Load plugin manager Nebula.pluginManager = new PluginManager(); diff --git a/src/main/java/emu/nebula/net/NetMsgIdUtils.java b/src/main/java/emu/nebula/net/NetMsgIdUtils.java index 2634351..10f216a 100644 --- a/src/main/java/emu/nebula/net/NetMsgIdUtils.java +++ b/src/main/java/emu/nebula/net/NetMsgIdUtils.java @@ -39,7 +39,7 @@ public class NetMsgIdUtils { } public static void dumpPacketIds() { - try (FileWriter writer = new FileWriter("./MsgIds_" + GameConstants.VERSION + ".json")) { + try (FileWriter writer = new FileWriter("./MsgIds_" + GameConstants.getGameVersion() + ".json")) { // Create sorted tree map Map packetIds = msgIdMap.int2ObjectEntrySet().stream() .filter(e -> e.getIntKey() > 0) diff --git a/src/main/java/emu/nebula/server/HttpServer.java b/src/main/java/emu/nebula/server/HttpServer.java index dc51345..dc32dc0 100644 --- a/src/main/java/emu/nebula/server/HttpServer.java +++ b/src/main/java/emu/nebula/server/HttpServer.java @@ -63,7 +63,7 @@ public class HttpServer { // Patch list public long getDataVersion() { - return getPatchlist() != null ? getPatchlist().getVersion() : GameConstants.DATA_VERSION; + return getPatchlist() != null ? getPatchlist().getVersion() : GameConstants.getDataVersion(); } public synchronized void loadPatchList() { @@ -89,7 +89,7 @@ public class HttpServer { } if (this.patchlist != null) { - Nebula.getLogger().info("Loaded patchlist version " + patchlist.getVersion()); + Nebula.getLogger().info("Loaded patchlist (Data version: " + patchlist.getVersion() + ")"); } } diff --git a/src/main/java/emu/nebula/util/Handbook.java b/src/main/java/emu/nebula/util/Handbook.java index fa3c459..85d835e 100644 --- a/src/main/java/emu/nebula/util/Handbook.java +++ b/src/main/java/emu/nebula/util/Handbook.java @@ -34,7 +34,7 @@ public class Handbook { var time = Instant.ofEpochMilli(System.currentTimeMillis()).atZone(ZoneId.systemDefault()).format(dtf); // Header - writer.println("# Nebula " + GameConstants.VERSION + " Handbook"); + writer.println("# Nebula " + GameConstants.getGameVersion() + " Handbook"); writer.println("# Created " + time); // Dump characters