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 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