From 2078287bec0865efb0e2d21d2bedcb82f92c6749 Mon Sep 17 00:00:00 2001 From: Weihao Date: Sat, 8 May 2021 02:36:40 -0400 Subject: [PATCH] Assign and save random server id --- .../imaginarycode/minecraft/redisbungee/RedisBungee.java | 6 ++---- .../minecraft/redisbungee/RedisBungeeConfiguration.java | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index 0d9485e..a4cb965 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -415,9 +415,6 @@ public final class RedisBungee extends Plugin { final boolean useSSL = configuration.getBoolean("useSSL"); String redisPassword = configuration.getString("redis-password"); String serverId = configuration.getString("server-id"); - if (serverId == null || serverId.isEmpty()) { - serverId = UUID.randomUUID().toString(); - } if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) { redisPassword = null; @@ -425,7 +422,8 @@ public final class RedisBungee extends Plugin { // Configuration sanity checks. if (serverId == null || serverId.isEmpty()) { - throw new RuntimeException("server-id is not specified in the configuration or is empty"); + configuration.set("server-id", UUID.randomUUID().toString()); + ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml")); } if (redisServer != null && !redisServer.isEmpty()) { diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeConfiguration.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeConfiguration.java index 474e4ab..09ac800 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeConfiguration.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeConfiguration.java @@ -22,11 +22,7 @@ public class RedisBungeeConfiguration { public RedisBungeeConfiguration(JedisPool pool, Configuration configuration) { this.pool = pool; - String serverId = configuration.getString("server-id"); - if (serverId == null || serverId.isEmpty()) { - serverId = UUID.randomUUID().toString(); - } - this.serverId = serverId; + this.serverId = configuration.getString("server-id"); this.registerBungeeCommands = configuration.getBoolean("register-bungee-commands", true);