mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-19 09:09:54 +02:00
Load data versions from a json file
This commit is contained in:
@@ -70,6 +70,9 @@ tmp/
|
||||
/*.jar
|
||||
/*.sh
|
||||
|
||||
# Custom external data version json
|
||||
/versions.json
|
||||
|
||||
# Extra
|
||||
Nebula Handbook.txt
|
||||
config.json
|
||||
|
||||
@@ -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.";
|
||||
|
||||
@@ -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;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Load config first
|
||||
Nebula.loadConfig();
|
||||
private static boolean generateHandbook = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 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() {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"global": 75,
|
||||
"kr": 82,
|
||||
"jp": 79,
|
||||
"tw": 76,
|
||||
"cn": 77
|
||||
}
|
||||
Reference in New Issue
Block a user