Added Node Checking for Smarter Configs
Implemented node checks during config loading to stop the config api from providing null and causing other unrelated initialization errors and stopping auto config reset.
This commit is contained in:
1 parent
40138413bb
commit
188d541c4d
4 files changed
+38
No files matched your search
@@ -35,6 +35,14 @@ public class BukkitConfig extends ConfigProvider {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void checkNodes(String... nodes) {
|
||||
for (String node : nodes) {
|
||||
if (!loadedConfiguration.contains(node))
|
||||
throw new ConfigException("The node \"" + node + "\" does not exist in the config.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() throws ConfigResetException {
|
||||
try {
|
||||
@@ -59,6 +67,8 @@ public class BukkitConfig extends ConfigProvider {
|
||||
try {
|
||||
loadedConfiguration = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode");
|
||||
|
||||
this.onlyProxy = loadedConfiguration.getBoolean("only-allow-proxy-connections");
|
||||
this.timestampValidationMode = loadedConfiguration.getString("timestamp-validation");
|
||||
this.doDebug = loadedConfiguration.getBoolean("debug-mode");
|
||||
|
||||
@@ -38,6 +38,14 @@ public class BungeeConfig extends ConfigProvider {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void checkNodes(String... nodes) {
|
||||
for (String node : nodes) {
|
||||
if (!loadedConfiguration.contains(node))
|
||||
throw new ConfigException("The node \"" + node + "\" does not exist in the config.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() throws ConfigResetException {
|
||||
try {
|
||||
@@ -63,6 +71,8 @@ public class BungeeConfig extends ConfigProvider {
|
||||
ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||
loadedConfiguration = configProvider.load(configFile);
|
||||
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode");
|
||||
|
||||
this.onlyProxy = loadedConfiguration.getBoolean("only-allow-proxy-connections");
|
||||
this.timestampValidationMode = loadedConfiguration.getString("timestamp-validation");
|
||||
this.doDebug = loadedConfiguration.getBoolean("debug-mode");
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.tcpshield.tcpshield.provider;
|
||||
import net.tcpshield.tcpshield.util.exception.config.ConfigLoadException;
|
||||
import net.tcpshield.tcpshield.util.exception.config.ConfigReloadException;
|
||||
import net.tcpshield.tcpshield.util.exception.config.ConfigResetException;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.ConfigException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -75,4 +76,11 @@ public abstract class ConfigProvider {
|
||||
*/
|
||||
public abstract void reload() throws ConfigReloadException;
|
||||
|
||||
/**
|
||||
* Checks the provided nodes to see if they exist in the config
|
||||
* @param nodes The nodes to check
|
||||
* @throws ConfigException Thrown when a node isnt found
|
||||
*/
|
||||
protected abstract void checkNodes(String... nodes) throws ConfigException;
|
||||
|
||||
}
|
||||
@@ -34,6 +34,14 @@ public class VelocityConfig extends ConfigProvider {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void checkNodes(String... nodes) {
|
||||
for (String node : nodes) {
|
||||
if (!loadedToml.contains(node))
|
||||
throw new ConfigException("The node \"" + node + "\" does not exist in the config.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() throws ConfigResetException {
|
||||
try {
|
||||
@@ -58,6 +66,8 @@ public class VelocityConfig extends ConfigProvider {
|
||||
try {
|
||||
loadedToml = new Toml().read(configFile);
|
||||
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode");
|
||||
|
||||
this.onlyProxy = loadedToml.getBoolean("only-allow-proxy-connections");
|
||||
this.timestampValidationMode = loadedToml.getString("timestamp-validation");
|
||||
this.doDebug = loadedToml.getBoolean("debug-mode");
|
||||
|
||||
Reference in new issue
Block a user