use of org.cubeengine.converter.node.MapNode in project modules-extra by CubeEngine.
the class QuestionConverter method toNode.
@Override
public Node toNode(Question object, ConverterManager manager) throws ConversionException {
MapNode node = MapNode.emptyMap();
node.set("question", new StringNode(object.getQuestion()));
node.set("answer", new StringNode(object.getAnswer()));
node.set("keywords", manager.convertToNode(object.getKeywords()));
return node;
}
use of org.cubeengine.converter.node.MapNode in project modules-extra by CubeEngine.
the class ItemStackConverter method toNode.
@Override
public Node toNode(ItemStack itemStack) throws ConversionException {
if (itemStack == null || itemStack.getItem() == Material.AIR) {
return NullNode.emptyNode();
}
MapNode item = MapNode.emptyMap();
item.set("Count", new IntNode(itemStack.getAmount()));
item.set("Damage", new IntNode(itemStack.getDurability()));
item.set("Item", StringNode.of(itemStack.getType().name()));
net.minecraft.server.v1_8_R2.ItemStack nmsCopy = CraftItemStack.asNMSCopy(itemStack);
if (nmsCopy == null) {
CubeEngine.getLog().error("NMSCopy is unexpectedly null! " + itemStack);
return null;
}
NBTTagCompound tag = nmsCopy.getTag();
item.set("tag", tag == null ? MapNode.emptyMap() : NBTUtils.convertNBTToNode(tag));
return item;
}
use of org.cubeengine.converter.node.MapNode in project core by CubeEngine.
the class Vector3iConverter method toNode.
@Override
public Node toNode(Vector3i blockVector3, ConverterManager converterManager) throws ConversionException {
MapNode mapNode = MapNode.emptyMap();
mapNode.set("x", new IntNode(blockVector3.getX()));
mapNode.set("y", new IntNode(blockVector3.getY()));
mapNode.set("z", new IntNode(blockVector3.getZ()));
return mapNode;
}
use of org.cubeengine.converter.node.MapNode in project core by CubeEngine.
the class Vector3iConverter method fromNode.
@Override
public Vector3i fromNode(Node node, ConverterManager converterManager) throws ConversionException {
if (node instanceof MapNode) {
Node x = ((MapNode) node).get("x");
Node y = ((MapNode) node).get("y");
Node z = ((MapNode) node).get("z");
return new Vector3i(converterManager.convertFromNode(x, Integer.class), converterManager.convertFromNode(y, Integer.class), converterManager.convertFromNode(z, Integer.class));
}
throw ConversionException.of(this, node, "Node is not a MapNode!");
}
use of org.cubeengine.converter.node.MapNode in project core by CubeEngine.
the class DataContainerConverter method toMap.
private Map toMap(MapNode node, ConverterManager manager) throws ConversionException {
Map<DataQuery, Object> map = new HashMap<>();
for (Entry<String, Node> entry : node.getMappedNodes().entrySet()) {
DataQuery key = DataQuery.of('_', node.getOriginalKey(entry.getKey()));
map.put(key, toObject(entry.getValue(), manager));
}
return map;
}
Aggregations