Fix null config values throwing exception - closes #147
This commit is contained in:
parent
02ea3afbe9
commit
599072eef6
@ -28,22 +28,23 @@ import com.google.common.cache.LoadingCache;
|
|||||||
|
|
||||||
import me.lucko.luckperms.common.config.keys.EnduringKey;
|
import me.lucko.luckperms.common.config.keys.EnduringKey;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public abstract class AbstractConfiguration implements LPConfiguration {
|
public abstract class AbstractConfiguration implements LPConfiguration {
|
||||||
private final LoadingCache<ConfigKey<?>, Object> cache = CacheBuilder.newBuilder()
|
private final LoadingCache<ConfigKey<?>, Optional<Object>> cache = CacheBuilder.newBuilder()
|
||||||
.build(new CacheLoader<ConfigKey<?>, Object>() {
|
.build(new CacheLoader<ConfigKey<?>, Optional<Object>>() {
|
||||||
@Override
|
@Override
|
||||||
public Object load(ConfigKey<?> key) {
|
public Optional<Object> load(ConfigKey<?> key) {
|
||||||
return key.get(AbstractConfiguration.this);
|
return Optional.ofNullable(key.get(AbstractConfiguration.this));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T get(ConfigKey<T> key) {
|
public <T> T get(ConfigKey<T> key) {
|
||||||
return (T) cache.getUnchecked(key);
|
return (T) cache.getUnchecked(key).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user