Search in sources :

Example 1 with StringNode

use of org.cubeengine.converter.node.StringNode 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 StringNode

use of org.cubeengine.converter.node.StringNode in project core by CubeEngine.

the class WorldConverter method fromNode.

@Override
public World fromNode(Node node) throws ConversionException {
    if (node instanceof StringNode) {
        String string = ((StringNode) node).getValue();
        Optional<World> world = Optional.empty();
        if (string.contains("(") && string.contains(")")) {
            UUID uid = UUID.fromString(string.substring(string.indexOf('(') + 1, string.indexOf(')')));
            world = Sponge.getServer().getWorld(uid);
            string = string.substring(0, string.indexOf('('));
        }
        if (!world.isPresent()) {
            world = Sponge.getServer().getWorld(string);
        }
        if (world.isPresent()) {
            return world.get();
        }
        throw ConversionException.of(this, node, "World not found! ");
    }
    throw ConversionException.of(this, node, "Node is not a StringNode!");
}
Also used : StringNode(org.cubeengine.converter.node.StringNode) World(org.spongepowered.api.world.World) UUID(java.util.UUID)

Example 3 with StringNode

use of org.cubeengine.converter.node.StringNode 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!");
    }
}
Also used : IntNode(org.cubeengine.converter.node.IntNode) MapNode(org.cubeengine.converter.node.MapNode) NullNode(org.cubeengine.converter.node.NullNode) StringNode(org.cubeengine.converter.node.StringNode) IntNode(org.cubeengine.converter.node.IntNode) Node(org.cubeengine.converter.node.Node) StringNode(org.cubeengine.converter.node.StringNode) MapNode(org.cubeengine.converter.node.MapNode) ItemStack(org.spongepowered.api.item.inventory.ItemStack) NullNode(org.cubeengine.converter.node.NullNode)

Example 4 with StringNode

use of org.cubeengine.converter.node.StringNode in project core by CubeEngine.

the class LocationConverter method fromNode.

@Override
@SuppressWarnings("unchecked")
public Location<World> fromNode(Node node, ConverterManager manager) throws ConversionException {
    if (node instanceof MapNode) {
        Map<String, Node> input = ((MapNode) node).getValue();
        World world = Sponge.getServer().getWorld(((StringNode) input.get("world")).getValue()).get();
        double x = manager.convertFromNode(input.get("x"), double.class);
        double y = manager.convertFromNode(input.get("y"), double.class);
        double z = manager.convertFromNode(input.get("z"), double.class);
        // TODO Location + Direction
        return new Location(world, x, y, z);
    }
    throw ConversionException.of(this, node, "Node is not a MapNode!");
}
Also used : MapNode(org.cubeengine.converter.node.MapNode) StringNode(org.cubeengine.converter.node.StringNode) Node(org.cubeengine.converter.node.Node) StringNode(org.cubeengine.converter.node.StringNode) MapNode(org.cubeengine.converter.node.MapNode) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Aggregations

StringNode (org.cubeengine.converter.node.StringNode)4 MapNode (org.cubeengine.converter.node.MapNode)3 Node (org.cubeengine.converter.node.Node)2 World (org.spongepowered.api.world.World)2 UUID (java.util.UUID)1 IntNode (org.cubeengine.converter.node.IntNode)1 NullNode (org.cubeengine.converter.node.NullNode)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Location (org.spongepowered.api.world.Location)1