use of com.ichorpowered.guardian.content.assignment.ConfigurationAssignment in project guardian by ichorpowered.
the class AbstractDetectionContentLoader method save.
@Override
public void save() {
if (this.contentContainer == null)
return;
this.contentContainer.getMap().forEach((key, value) -> {
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();
this.configurationFile.getNode(configurationAssignment.lookup().toArray()).setValue(key.getElementToken());
});
try {
this.configurationFile.save();
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.ichorpowered.guardian.content.assignment.ConfigurationAssignment 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.guardian.content.assignment.ConfigurationAssignment 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();
}
}
}
use of com.ichorpowered.guardian.content.assignment.ConfigurationAssignment in project guardian by ichorpowered.
the class AbstractDetectionContentLoader method acquireAll.
@Override
public void acquireAll() {
if (this.contentContainer == null || this.contentContainer.getPossibleKeys() == null)
return;
this.contentContainer.getPossibleKeys().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();
}
}
});
}
Aggregations