Search in sources :

Example 6 with Node

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

the class SimpleGameManager method fillDefaultQueue.

@Override
public void fillDefaultQueue() {
    Node node = this.plugin.getSettings().getData().child("queue");
    if (node == null) {
        node = Node.empty();
    }
    for (Node mapNode : node.children("map")) {
        String directory = mapNode.propertyValue("directory");
        String mapName = mapNode.getValue();
        OfflineMap map = null;
        if (directory != null) {
            map = this.plugin.getMaps().getContainer().getMapByDirectory(directory);
        } else if (mapName != null) {
            map = this.plugin.getMaps().getContainer().getMap(mapName);
        }
        if (map != null) {
            queue.addMap(map);
        }
    }
    this.postEvent(new MapQueueFillEvent(this.plugin, this.getQueue()));
}
Also used : MapQueueFillEvent(pl.themolka.arcade.map.queue.MapQueueFillEvent) Node(pl.themolka.arcade.dom.Node) OfflineMap(pl.themolka.arcade.map.OfflineMap)

Example 7 with Node

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

the class SimpleGameManager method setDefaultMaxGameId.

@Override
public void setDefaultMaxGameId() {
    Node node = this.plugin.getSettings().getData().child("queue");
    if (node == null) {
        return;
    }
    try {
        ParserContext context = this.plugin.getParsers().createContext();
        this.setMaxGameId(context.type(Integer.class).parse(node.property("restart-after")).orFail());
    } catch (ParserNotSupportedException | ParserException ex) {
        ex.printStackTrace();
    }
}
Also used : ParserException(pl.themolka.arcade.parser.ParserException) Node(pl.themolka.arcade.dom.Node) ParserContext(pl.themolka.arcade.parser.ParserContext) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Example 8 with Node

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

the class JDOMEngine method convert.

// 
// Converting
// 
public static Node convert(org.jdom2.Element jdom) {
    List<Element> children = jdom.getChildren();
    Node node = Node.of(JDOMEngine.convert(jdom.getNamespace()), jdom.getName());
    String maybeValue = jdom.getValue();
    if (children.isEmpty() && maybeValue != null) {
        // primitive value
        node.setValue(jdom.getValue());
    } else {
        // children
        List<Node> parsed = new ArrayList<>();
        for (org.jdom2.Element child : children) {
            parsed.add(JDOMEngine.convert(child));
        }
        node.add(parsed);
    }
    // properties
    for (org.jdom2.Attribute attribute : jdom.getAttributes()) {
        node.setProperty(JDOMEngine.convert(attribute));
    }
    // location
    if (jdom instanceof JDOMElement) {
        JDOMElement located = (JDOMElement) jdom;
        Cursor start = located.getStartCursor();
        Cursor end = located.getEndCursor();
        if (start != null && end != null) {
            node.locate(start, end);
        }
    }
    return node;
}
Also used : Element(org.jdom2.Element) Node(pl.themolka.arcade.dom.Node) ArrayList(java.util.ArrayList) Cursor(pl.themolka.arcade.dom.Cursor) Element(org.jdom2.Element)

Example 9 with Node

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

the class FilterSetParser method parseTree.

@Override
protected ParserResult<FilterSet.Config> parseTree(Node node, String name) throws ParserException {
    String id = this.parseRequiredId(node);
    Set<Filter.Config<?>> filters = new HashSet<>();
    for (Node filterNode : node.children()) {
        filters.add(this.filterParser.parse(filterNode).orFail());
    }
    if (ParserUtils.ensureNotEmpty(filters)) {
        throw this.fail(node, name, null, "No filters defined");
    }
    return ParserResult.fine(node, name, new FilterSet.Config() {

        public String id() {
            return id;
        }

        public Ref<Set<Filter.Config<?>>> filters() {
            return Ref.ofProvided(filters);
        }
    });
}
Also used : Ref(pl.themolka.arcade.config.Ref) Node(pl.themolka.arcade.dom.Node) HashSet(java.util.HashSet)

Example 10 with Node

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

the class TreePreprocess method invoke.

@Override
public final void invoke(Node node) throws PreprocessException {
    List<Node> nodeDefinition = this.defineNode(node);
    if (nodeDefinition != null) {
        for (Node definedChild : nodeDefinition) {
            this.invokeNode(definedChild);
            List<Property> propertyDefinition = this.defineProperty(definedChild);
            if (propertyDefinition != null) {
                for (Property property : propertyDefinition) {
                    this.invokeProperty(property);
                }
            }
        }
    }
    for (Node child : this.define(node)) {
        this.preprocess(child);
    }
}
Also used : Node(pl.themolka.arcade.dom.Node) Property(pl.themolka.arcade.dom.Property)

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