Search in sources :

Example 1 with MapNode

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;
}
Also used : StringNode(org.cubeengine.converter.node.StringNode) MapNode(org.cubeengine.converter.node.MapNode)

Example 2 with MapNode

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;
}
Also used : IntNode(org.cubeengine.converter.node.IntNode) MapNode(org.cubeengine.converter.node.MapNode)

Example 3 with MapNode

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;
}
Also used : IntNode(org.cubeengine.converter.node.IntNode) MapNode(org.cubeengine.converter.node.MapNode)

Example 4 with 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!");
}
Also used : MapNode(org.cubeengine.converter.node.MapNode) IntNode(org.cubeengine.converter.node.IntNode) Node(org.cubeengine.converter.node.Node) Vector3i(com.flowpowered.math.vector.Vector3i) MapNode(org.cubeengine.converter.node.MapNode)

Example 5 with 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;
}
Also used : HashMap(java.util.HashMap) MapNode(org.cubeengine.converter.node.MapNode) ListNode(org.cubeengine.converter.node.ListNode) Node(org.cubeengine.converter.node.Node) DataQuery(org.spongepowered.api.data.DataQuery)

Aggregations

MapNode (org.cubeengine.converter.node.MapNode)8 Node (org.cubeengine.converter.node.Node)5 IntNode (org.cubeengine.converter.node.IntNode)4 StringNode (org.cubeengine.converter.node.StringNode)3 ListNode (org.cubeengine.converter.node.ListNode)2 DataQuery (org.spongepowered.api.data.DataQuery)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 HashMap (java.util.HashMap)1 NullNode (org.cubeengine.converter.node.NullNode)1 DataContainer (org.spongepowered.api.data.DataContainer)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1