Search in sources :

Example 16 with Node

use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.

the class EnchantmentStorageMetaParser method parse.

@Override
public EnchantmentStorageMeta parse(Node root, ItemStack itemStack, EnchantmentStorageMeta itemMeta) throws ParserException {
    Node node = root.firstChild("enchanted-book");
    if (node != null) {
        for (Node enchantment : node.children("enchantment")) {
            ItemEnchantment value = this.enchantmentParser.parse(enchantment).orFail();
            itemMeta.addStoredEnchant(value.getType(), value.getLevel(), true);
        }
    }
    return itemMeta;
}
Also used : ItemEnchantment(pl.themolka.arcade.item.ItemEnchantment) Node(pl.themolka.arcade.dom.Node)

Example 17 with Node

use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.

the class MapMetaParser method parse.

@Override
public MapMeta parse(Node root, ItemStack itemStack, MapMeta itemMeta) throws ParserException {
    Node node = root.firstChild("map");
    if (node != null) {
        Property scaling = node.property("scaling");
        if (scaling != null) {
            itemMeta.setScaling(this.scalingParser.parse(scaling).orFail());
        }
        Property locationName = node.property("location-name");
        if (locationName != null) {
            itemMeta.setLocationName(this.locationNameParser.parse(locationName).orFail());
        }
        Property color = node.property("color");
        if (color != null) {
            itemMeta.setColor(this.colorParser.parse(color).orFail());
        }
    }
    return itemMeta;
}
Also used : Node(pl.themolka.arcade.dom.Node) Property(pl.themolka.arcade.dom.Property)

Example 18 with Node

use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.

the class KitParser method parseTree.

@Override
protected ParserResult<Kit.Config> parseTree(Node node, String name) throws ParserException {
    String id = this.parseRequiredId(node);
    List<KitContent.Config<?, ?>> contents = new ArrayList<>();
    for (Node contentNode : node.children()) {
        contents.add(this.contentParser.parse(contentNode).orFail());
    }
    if (ParserUtils.ensureNotEmpty(contents)) {
        throw this.fail(node, name, null, "No kit contents defined");
    }
    Set<String> inherit = new LinkedHashSet<>();
    String inheritValue = node.propertyValue("inherit", "parent", "parents");
    if (inheritValue != null) {
        inherit.addAll(ParserUtils.array(inheritValue));
    }
    return ParserResult.fine(node, name, new Kit.Config() {

        public String id() {
            return id;
        }

        public List<KitContent.Config<?, ?>> contents() {
            return contents;
        }

        public Set<String> inherit() {
            return inherit;
        }
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Node(pl.themolka.arcade.dom.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) KitContent(pl.themolka.arcade.kit.content.KitContent)

Example 19 with Node

use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.

the class ImportStage method invokeNode.

@Override
public void invokeNode(Node node) throws PreprocessException {
    if (!node.hasParent()) {
        throw new PreprocessException(node, "Node must have its parent");
    }
    Node parent = node.getParent();
    String targetPath = node.getValue();
    if (targetPath == null) {
        throw new PreprocessException(node, "Target document path not specified");
    }
    Document target;
    try {
        Path directory = this.document.getPath().getParent();
        target = readDocument(this.engines, node, directory.resolve(targetPath).toUri());
    } catch (InvalidPathException ex) {
        throw new PreprocessException(node, "Invalid document path: " + ex.getReason(), ex);
    }
    if (!target.hasPath()) {
        throw new PreprocessException(target, "Cannot resolve target document path");
    } else if (!target.hasRoot()) {
        throw new PreprocessException(target, "Target document is empty");
    }
    Path path = target.getPath();
    if (stack.search(path) != -1) {
        throw new PreprocessException(target, "Import loop detected");
    }
    stack.push(path);
    // Preprocess the target document.
    this.preprocessor.preprocess(target);
    // Remove the old <import> node.
    Node.detach(node);
    // We don't support root node properties.
    parent.add(target.getRoot().children());
}
Also used : Path(java.nio.file.Path) Node(pl.themolka.arcade.dom.Node) Document(pl.themolka.arcade.dom.Document) InvalidPathException(java.nio.file.InvalidPathException)

Example 20 with Node

use of pl.themolka.arcade.dom.Node in project Arcade2 by ShootGame.

the class Include method invokeNode.

@Override
public void invokeNode(Node node) throws PreprocessException {
    if (!node.hasParent()) {
        throw new PreprocessException(node, "Node must have its parent");
    }
    Node parent = node.getParent();
    String targetPath = node.getValue();
    if (targetPath == null) {
        throw new PreprocessException(node, "Target document path not specified");
    }
    Document target;
    try {
        target = ImportStage.readDocument(this.engines, node, this.repository.resolve(targetPath).toUri());
    } catch (InvalidPathException ex) {
        throw new PreprocessException(node, "Invalid document path: " + ex.getReason(), ex);
    }
    if (!target.hasPath()) {
        throw new PreprocessException(target, "Cannot resolve target document path");
    } else if (!target.hasRoot()) {
        throw new PreprocessException(target, "Target document is empty");
    }
    // Preprocess the target document.
    this.preprocessor.preprocess(target);
    // Remove the old <include> node.
    Node.detach(node);
    // We don't support root node properties.
    parent.add(target.getRoot().children());
}
Also used : Node(pl.themolka.arcade.dom.Node) Document(pl.themolka.arcade.dom.Document) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

Node (pl.themolka.arcade.dom.Node)25 ArrayList (java.util.ArrayList)7 Property (pl.themolka.arcade.dom.Property)7 File (java.io.File)2 InvalidPathException (java.nio.file.InvalidPathException)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Ref (pl.themolka.arcade.config.Ref)2 Document (pl.themolka.arcade.dom.Document)2 ParserException (pl.themolka.arcade.parser.ParserException)2 ParserNotSupportedException (pl.themolka.arcade.parser.ParserNotSupportedException)2 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 FireworkEffect (org.bukkit.FireworkEffect)1 Material (org.bukkit.Material)1