Load data versions from a json file

This commit is contained in:
Melledy
2026-01-02 22:13:24 -08:00
parent 088c2df58a
commit 5c86bb8380
4 changed files with 60 additions and 25 deletions
@@ -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.";
+49 -5
View File
@@ -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<String, Integer> 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() {
+7
View File
@@ -0,0 +1,7 @@
{
"global": 75,
"kr": 82,
"jp": 79,
"tw": 76,
"cn": 77
}