use of com.ichorpowered.guardianapi.content.key.ContentKey in project guardian by ichorpowered.
the class AbstractDetectionContentLoader method acquireAll.
@Override
public void acquireAll(Set<ContentKey<?>> contentKeys) {
if (this.contentContainer == null)
return;
contentKeys.forEach(key -> {
final Optional<ConfigurationAssignment> assignment = key.getAssignments().stream().filter(contentAssignment -> contentAssignment.getClass().equals(ConfigurationAssignment.class)).map(contentAssignment -> (ConfigurationAssignment) contentAssignment).findFirst();
if (!assignment.isPresent())
return;
final ConfigurationAssignment configurationAssignment = assignment.get();
final CommentedConfigurationNode node = this.configurationFile.getNode(configurationAssignment.lookup().toArray());
if (MapValue.class.isAssignableFrom(key.getDefaultValue().getClass())) {
final Map<Object, Object> collect = Maps.newHashMap();
if (node.hasMapChildren()) {
for (final Map.Entry<Object, ? extends ConfigurationNode> entry : node.getChildrenMap().entrySet()) {
collect.put(entry.getKey(), entry.getValue().getValue());
this.contentContainer.attempt(key, GuardianMapValue.builder((Key) key).defaultElement(collect).element(collect).create());
}
return;
}
}
if (Value.class.isAssignableFrom(key.getDefaultValue().getClass())) {
try {
Object value = node.getValue(key.getElementToken());
this.contentContainer.attempt(key, GuardianValue.builder((Key) key).defaultElement(value).element(value).create());
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
});
}
use of com.ichorpowered.guardianapi.content.key.ContentKey in project guardian by ichorpowered.
the class AbstractDetectionContentLoader method acquireSingle.
@Override
public void acquireSingle(ContentKey<?> key) {
if (this.contentContainer == null)
return;
final Optional<ConfigurationAssignment> assignment = key.getAssignments().stream().filter(contentAssignment -> contentAssignment.getClass().equals(ConfigurationAssignment.class)).map(contentAssignment -> (ConfigurationAssignment) contentAssignment).findFirst();
if (!assignment.isPresent())
return;
final ConfigurationAssignment configurationAssignment = assignment.get();
final CommentedConfigurationNode node = this.configurationFile.getNode(configurationAssignment.lookup().toArray());
if (MapValue.class.isAssignableFrom(key.getDefaultValue().getClass())) {
final Map<Object, Object> collect = Maps.newHashMap();
if (node.hasMapChildren()) {
for (final Map.Entry<Object, ? extends ConfigurationNode> entry : node.getChildrenMap().entrySet()) {
collect.put(entry.getKey(), entry.getValue().getValue());
this.contentContainer.attempt(key, GuardianMapValue.builder((Key) key).defaultElement(collect).element(collect).create());
}
return;
}
}
if (Value.class.isAssignableFrom(key.getDefaultValue().getClass())) {
try {
Object value = node.getValue(key.getElementToken());
this.contentContainer.attempt(key, GuardianValue.builder((Key) key).defaultElement(value).element(value).create());
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
}
Aggregations