This commit is contained in:
tyuXX 2026-07-06 22:46:13 +03:00
parent 66f612268e
commit e8cd47a8d7
178 changed files with 5432 additions and 5187 deletions

View file

@ -1,31 +1,33 @@
package org.gsdistance.grimmsServer.Config;
import org.gsdistance.grimmsServer.GrimmsServer;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.gsdistance.grimmsServer.GrimmsServer;
public class ActiveConfig {
public static final Map<ConfigKey, Object> configValues = new HashMap<>();
public static final Map<ConfigKey, Object> configValues = new HashMap();
public static void setConfigValue(ConfigKey key, Object value) {
configValues.put(key, value);
}
public ActiveConfig() {
}
@SuppressWarnings("unchecked")
public static <T> T getConfigValue(ConfigKey key, Class<T> ignoredType) {
try {
return (T) configValues.getOrDefault(key, key.getDefaultValue());
} catch (ClassCastException e) {
GrimmsServer.logger.warning("Config value for " + key.getKey() + " is not of type " + ignoredType.getSimpleName() + ". Message: " + e.getMessage());
try {
return ignoredType.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException |
InstantiationException ex) {
GrimmsServer.logger.warning("Failed to instantiate default value for " + key.getKey() + ". Message: " + ex.getMessage());
return null;
}
}
}
}
public static void setConfigValue(ConfigKey key, Object value) {
configValues.put(key, value);
}
public static <T> T getConfigValue(ConfigKey key, Class<T> ignoredType) {
try {
return (T)configValues.getOrDefault(key, key.getDefaultValue());
} catch (ClassCastException e) {
GrimmsServer.logger.warning("Config value for " + key.getKey() + " is not of type " + ignoredType.getSimpleName() + ". Message: " + e.getMessage());
try {
return (T)ignoredType.getDeclaredConstructor().newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException ex) {
GrimmsServer.logger.warning("Failed to instantiate default value for " + key.getKey() + ". Message: " + ((ReflectiveOperationException)ex).getMessage());
return null;
}
}
}
}