use of org.cubeengine.converter.node.NullNode in project modules-extra by CubeEngine.
the class ItemStackConverter method fromNode.
@Override
public ItemStack fromNode(Node node) throws ConversionException {
if (node instanceof MapNode) {
Node count = ((MapNode) node).get("Count");
Node damage = ((MapNode) node).get("Damage");
Node item = ((MapNode) node).get("Item");
Node tag = ((MapNode) node).get("tag");
if (count instanceof IntNode && damage instanceof IntNode && item instanceof StringNode && (tag instanceof MapNode)) {
try {
ItemStack itemStack = new ItemStack(Material.valueOf(item.asText()));
itemStack.setDurability(((IntNode) damage).getValue().shortValue());
itemStack.setAmount(((IntNode) count).getValue());
net.minecraft.server.v1_8_R2.ItemStack nms = CraftItemStack.asNMSCopy(itemStack);
nms.setTag(((MapNode) tag).isEmpty() ? null : (NBTTagCompound) NBTUtils.convertNodeToNBT(tag));
return CraftItemStack.asBukkitCopy(nms);
} catch (IllegalArgumentException e) {
throw ConversionException.of(this, item, "Unknown Material!");
}
} else {
throw ConversionException.of(this, node, "Invalid SubNodes!");
}
} else if (node instanceof NullNode) {
return null;
} else {
throw ConversionException.of(this, node, "Node is not a MapNode!");
}
}
Aggregations