From aa7e878d536cdba529e7d046a4b3099f7ab512f9 Mon Sep 17 00:00:00 2001 From: Akram Louze Date: Thu, 2 Nov 2023 11:15:50 +0100 Subject: [PATCH] Fixed configuration handling --- .../serversync/bungee/BungeeServerSyncPlugin.java | 10 ++++++---- serversync-common/src/main/resources/config.yml | 6 +++--- .../serversync/spigot/SpigotServerSyncPlugin.java | 4 ++-- .../velocity/VelocityServerSyncPlugin.java | 12 +++++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/serversync-bungee/src/main/java/me/akraml/serversync/bungee/BungeeServerSyncPlugin.java b/serversync-bungee/src/main/java/me/akraml/serversync/bungee/BungeeServerSyncPlugin.java index 470f6c2..4c77c50 100644 --- a/serversync-bungee/src/main/java/me/akraml/serversync/bungee/BungeeServerSyncPlugin.java +++ b/serversync-bungee/src/main/java/me/akraml/serversync/bungee/BungeeServerSyncPlugin.java @@ -93,8 +93,8 @@ public void onEnable() { .addKey(RedisCredentialsKeys.MAX_TOTAL, redisSection.getInt("max-total")) .addKey(RedisCredentialsKeys.MAX_IDLE, redisSection.getInt("max-idle")) .addKey(RedisCredentialsKeys.MIN_IDLE, redisSection.getInt("min-idle")) - .addKey(RedisCredentialsKeys.MIN_EVICTABLE_IDLE_TIME, redisSection.getInt("min-evictable-idle-time")) - .addKey(RedisCredentialsKeys.TIME_BETWEEN_EVICTION_RUNS, redisSection.getInt("time-between-eviction-runs")) + .addKey(RedisCredentialsKeys.MIN_EVICTABLE_IDLE_TIME, redisSection.getLong("min-evictable-idle-time")) + .addKey(RedisCredentialsKeys.TIME_BETWEEN_EVICTION_RUNS, redisSection.getLong("time-between-eviction-runs")) .addKey(RedisCredentialsKeys.BLOCK_WHEN_EXHAUSTED, redisSection.getBoolean("block-when-exhausted")) .build(); final RedisMessageBrokerService messageBrokerService = new RedisMessageBrokerService( @@ -121,12 +121,14 @@ public void onEnable() { @Override public void onDisable() { - ServerSync.getInstance().getMessageBrokerService().stop(); + if (ServerSync.getInstance() != null) + ServerSync.getInstance().getMessageBrokerService().stop(); } private void loadConfig() throws IOException { - final File configFile = new File("config.toml"); + final File configFile = new File(getDataFolder(), "config.yml"); if (!configFile.exists()) { + configFile.createNewFile(); try (final InputStream inputStream = getClass().getResourceAsStream("/config.yml")) { assert inputStream != null; Files.copy(inputStream, configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); diff --git a/serversync-common/src/main/resources/config.yml b/serversync-common/src/main/resources/config.yml index 6f72186..40dbd97 100644 --- a/serversync-common/src/main/resources/config.yml +++ b/serversync-common/src/main/resources/config.yml @@ -25,9 +25,9 @@ redis: password: "password-here" timeout: 5000 # In milliseconds. # Pool configuration values. - max-total: 1 - max-idle: 1 - min-idle: 1 + max-total: 16 + max-idle: 8 + min-idle: 8 block-when-exhausted: false min-evictable-idle-time: 60000 time-between-eviction-runs: 30000 \ No newline at end of file diff --git a/serversync-spigot/src/main/java/me/akraml/serversync/spigot/SpigotServerSyncPlugin.java b/serversync-spigot/src/main/java/me/akraml/serversync/spigot/SpigotServerSyncPlugin.java index 0d7d081..757d57c 100644 --- a/serversync-spigot/src/main/java/me/akraml/serversync/spigot/SpigotServerSyncPlugin.java +++ b/serversync-spigot/src/main/java/me/akraml/serversync/spigot/SpigotServerSyncPlugin.java @@ -75,8 +75,8 @@ public void onEnable() { .addKey(RedisCredentialsKeys.MAX_TOTAL, redisSection.getInt("max-total")) .addKey(RedisCredentialsKeys.MAX_IDLE, redisSection.getInt("max-idle")) .addKey(RedisCredentialsKeys.MIN_IDLE, redisSection.getInt("min-idle")) - .addKey(RedisCredentialsKeys.MIN_EVICTABLE_IDLE_TIME, redisSection.getInt("min-evictable-idle-time")) - .addKey(RedisCredentialsKeys.TIME_BETWEEN_EVICTION_RUNS, redisSection.getInt("time-between-eviction-runs")) + .addKey(RedisCredentialsKeys.MIN_EVICTABLE_IDLE_TIME, redisSection.getLong("min-evictable-idle-time")) + .addKey(RedisCredentialsKeys.TIME_BETWEEN_EVICTION_RUNS, redisSection.getLong("time-between-eviction-runs")) .addKey(RedisCredentialsKeys.BLOCK_WHEN_EXHAUSTED, redisSection.getBoolean("block-when-exhausted")) .build(); final RedisMessageBrokerService messageBrokerService = new RedisMessageBrokerService( diff --git a/serversync-velocity/src/main/java/me/akraml/serversync/velocity/VelocityServerSyncPlugin.java b/serversync-velocity/src/main/java/me/akraml/serversync/velocity/VelocityServerSyncPlugin.java index c142ba4..d07c28f 100644 --- a/serversync-velocity/src/main/java/me/akraml/serversync/velocity/VelocityServerSyncPlugin.java +++ b/serversync-velocity/src/main/java/me/akraml/serversync/velocity/VelocityServerSyncPlugin.java @@ -106,8 +106,8 @@ public void onInitialize(final ProxyInitializeEvent event) { .addKey(RedisCredentialsKeys.MAX_TOTAL, redisTable.getLong("max-total").intValue()) .addKey(RedisCredentialsKeys.MAX_IDLE, redisTable.getLong("max-idle").intValue()) .addKey(RedisCredentialsKeys.MIN_IDLE, redisTable.getLong("min-idle").intValue()) - .addKey(RedisCredentialsKeys.MIN_EVICTABLE_IDLE_TIME, redisTable.getLong("min-evictable-idle-time").intValue()) - .addKey(RedisCredentialsKeys.TIME_BETWEEN_EVICTION_RUNS, redisTable.getLong("time-between-eviction-runs").intValue()) + .addKey(RedisCredentialsKeys.MIN_EVICTABLE_IDLE_TIME, redisTable.getLong("min-evictable-idle-time")) + .addKey(RedisCredentialsKeys.TIME_BETWEEN_EVICTION_RUNS, redisTable.getLong("time-between-eviction-runs")) .addKey(RedisCredentialsKeys.BLOCK_WHEN_EXHAUSTED, redisTable.getBoolean("block-when-exhausted")) .build(); final RedisMessageBrokerService messageBrokerService = new RedisMessageBrokerService( @@ -133,9 +133,10 @@ public void onInitialize(final ProxyInitializeEvent event) { private void loadConfig() throws IOException { final File dataFolder = new File("plugins/serversync"); - if (!dataFolder.exists()) dataFolder.createNewFile(); - final File configFile = new File("config.toml"); + if (!dataFolder.exists()) dataFolder.mkdirs(); + final File configFile = new File(dataFolder, "config.toml"); if (!configFile.exists()) { + configFile.createNewFile(); try (final InputStream inputStream = VelocityServerSyncPlugin.class.getResourceAsStream("/config.toml")) { assert inputStream != null; Files.copy(inputStream, configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -145,7 +146,8 @@ private void loadConfig() throws IOException { @Subscribe public void onShutdown(final ProxyShutdownEvent event) { - ServerSync.getInstance().getMessageBrokerService().stop(); + if (ServerSync.getInstance() != null) + ServerSync.getInstance().getMessageBrokerService().stop(); } }