Skip to content

Commit

Permalink
Fix null config values throwing exception - closes #147
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jan 24, 2017
1 parent 02ea3af commit 599072e
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@

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

0 comments on commit 599072e

Please sign in to comment.