Skip to content

Commit

Permalink
Fixed configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AkramLZ committed Nov 2, 2023
1 parent 9a25d06 commit aa7e878
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions serversync-common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -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();
}

}

0 comments on commit aa7e878

Please sign in to comment.