Skip to content

Commit 8e30c32

Browse files
committed
Improve ConfigAdapter
1 parent 00590da commit 8e30c32

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.example</groupId>
88
<artifactId>ForestRedisAPI</artifactId>
9-
<version>1.0.0</version>
9+
<version>1.0.1</version>
1010

1111
<properties>
1212
<maven.compiler.source>11</maven.compiler.source>
@@ -89,11 +89,6 @@
8989

9090

9191
<dependencies>
92-
<dependency>
93-
<groupId>com.github.ForestTechMC</groupId>
94-
<artifactId>ForestRedisAPI</artifactId>
95-
<version>v${project.version}</version>
96-
</dependency>
9792
<dependency>
9893
<groupId>org.spigotmc</groupId>
9994
<artifactId>spigot-api</artifactId>

src/main/java/cz/foresttech/forestredis/bungee/config/BungeeConfigAdapter.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class BungeeConfigAdapter implements IConfigurationAdapter {
1616

1717
private String fileName;
18+
private Configuration configuration;
1819

1920
@Override
2021
public void setup(String fileName) {
@@ -33,45 +34,46 @@ public void setup(String fileName) {
3334
ForestRedisBungee.getInstance().logger().warning("Cannot create config.yml! This proxy won't process any Redis communication!");
3435
return;
3536
}
36-
loadYamlFile();
37+
loadConfiguration();
3738
}
38-
loadYamlFile();
39+
loadConfiguration();
3940
}
4041

4142
@Override
4243
public boolean isSetup() {
43-
return loadYamlFile() != null;
44+
return configuration != null;
4445
}
4546

46-
public Configuration loadYamlFile() {
47+
@Override
48+
public void loadConfiguration() {
4749
try {
48-
return ConfigurationProvider
50+
configuration = ConfigurationProvider
4951
.getProvider(YamlConfiguration.class)
5052
.load(new File(ForestRedisBungee.getInstance().getDataFolder(), fileName + ".yml"));
5153
} catch (IOException e) {
5254
ForestRedisBungee.getInstance().logger().warning("Cannot load config.yml! This proxy won't process any Redis communication!");
53-
return null;
55+
configuration = null;
5456
}
5557
}
5658

5759
@Override
5860
public String getString(String path, String def) {
59-
return this.loadYamlFile().getString(path, def);
61+
return this.configuration.getString(path, def);
6062
}
6163

6264
@Override
6365
public int getInt(String path, int def) {
64-
return this.loadYamlFile().getInt(path, def);
66+
return this.configuration.getInt(path, def);
6567
}
6668

6769
@Override
6870
public boolean getBoolean(String path, boolean def) {
69-
return this.loadYamlFile().getBoolean(path, def);
71+
return this.configuration.getBoolean(path, def);
7072
}
7173

7274
@Override
7375
public List<String> getStringList(String path) {
74-
return this.loadYamlFile().getStringList(path);
76+
return this.configuration.getStringList(path);
7577
}
7678

7779
}

src/main/java/cz/foresttech/forestredis/shared/config/IConfigurationAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public interface IConfigurationAdapter {
88

99
boolean isSetup();
1010

11+
void loadConfiguration();
12+
1113
String getString(String path, String def);
1214

1315
int getInt(String path, int def);

src/main/java/cz/foresttech/forestredis/spigot/config/SpigotConfigAdapter.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cz.foresttech.forestredis.spigot.config;
22

33
import com.google.common.base.Charsets;
4+
import cz.foresttech.forestredis.bungee.ForestRedisBungee;
45
import cz.foresttech.forestredis.shared.config.IConfigurationAdapter;
56
import cz.foresttech.forestredis.spigot.ForestRedisSpigot;
67
import org.bukkit.configuration.file.FileConfiguration;
@@ -32,19 +33,25 @@ public void setup(String fileName) {
3233
}
3334

3435
configuration = YamlConfiguration.loadConfiguration(file);
35-
reloadConfig();
36+
loadConfiguration();
3637
}
3738

3839
@Override
3940
public boolean isSetup() {
4041
return configuration != null;
4142
}
4243

43-
public void reloadConfig() {
44-
configuration = YamlConfiguration.loadConfiguration(file);
45-
InputStream defConfigStream = ForestRedisSpigot.getInstance().getResource(fileName + ".yml");
46-
if (defConfigStream != null) {
47-
configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
44+
@Override
45+
public void loadConfiguration() {
46+
try {
47+
configuration = YamlConfiguration.loadConfiguration(file);
48+
InputStream defConfigStream = ForestRedisSpigot.getInstance().getResource(fileName + ".yml");
49+
if (defConfigStream != null) {
50+
configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
51+
}
52+
} catch (Exception ex) {
53+
ForestRedisBungee.getInstance().logger().warning("Cannot load config.yml! This server won't process any Redis communication!");
54+
configuration = null;
4855
}
4956
}
5057

0 commit comments

Comments
 (0)