Fix null config values throwing exception - closes #147

This commit is contained in:
Luck 2017-01-24 20:13:18 +00:00
parent 02ea3afbe9
commit 599072eef6
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -28,22 +28,23 @@ import com.google.common.cache.LoadingCache;
import me.lucko.luckperms.common.config.keys.EnduringKey;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@SuppressWarnings("unchecked")
public abstract class AbstractConfiguration implements LPConfiguration {
private final LoadingCache<ConfigKey<?>, Object> cache = CacheBuilder.newBuilder()
.build(new CacheLoader<ConfigKey<?>, Object>() {
private final LoadingCache<ConfigKey<?>, Optional<Object>> cache = CacheBuilder.newBuilder()
.build(new CacheLoader<ConfigKey<?>, Optional<Object>>() {
@Override
public Object load(ConfigKey<?> key) {
return key.get(AbstractConfiguration.this);
public Optional<Object> load(ConfigKey<?> key) {
return Optional.ofNullable(key.get(AbstractConfiguration.this));
}
});
@Override
public <T> T get(ConfigKey<T> key) {
return (T) cache.getUnchecked(key);
return (T) cache.getUnchecked(key).orElse(null);
}
@Override