Search in sources :

Example 1 with Node

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

the class ArcadePlugin method loadEnvironment.

private void loadEnvironment() throws DOMException {
    Node node = this.getSettings().getData().child("environment");
    Parser<Environment> parser;
    try {
        parser = this.parsers.forType(Environment.class);
    } catch (ParserNotSupportedException ex) {
        throw new RuntimeException("No " + Environment.class.getSimpleName() + " parser installed");
    }
    this.environment = parser.parse(node).orFail();
    this.environment.initialize(this);
}
Also used : Node(pl.themolka.arcade.dom.Node) Environment(pl.themolka.arcade.environment.Environment) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Example 2 with Node

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

the class FireworkMetaParser method parse.

@Override
public FireworkMeta parse(Node root, ItemStack itemStack, FireworkMeta itemMeta) throws ParserException {
    Node node = root.firstChild("firework", "firework");
    if (node != null) {
        Property power = node.property("power");
        if (power != null) {
            int powerInt = this.powerParser.parse(power).orFail();
            if (powerInt > 127) {
                throw this.fail(power, "Power cannot be greater than 127");
            } else if (powerInt <= 0) {
                throw this.fail(power, "Power cannot be smaller than 0");
            }
            itemMeta.setPower(this.powerParser.parse(power).orFail());
        }
        for (Node effect : node.children("effect", "firework-effect", "fireworkeffect")) {
            itemMeta.addEffect(this.fireworkEffectParser.parse(effect).orFail());
        }
    }
    return itemMeta;
}
Also used : Node(pl.themolka.arcade.dom.Node) Property(pl.themolka.arcade.dom.Property)

Example 3 with Node

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

the class PotionMetaParser method parse.

@Override
public PotionMeta parse(Node root, ItemStack itemStack, PotionMeta itemMeta) throws ParserException {
    Node node = root.firstChild("potion");
    if (node != null) {
        Property type = node.property("type", "of");
        if (type != null) {
            PotionType value = this.typeParser.parse(type).orFail();
            boolean extended = this.extendedParser.parse(node.property("extended")).orDefault(false);
            boolean upgraded = this.upgradedParser.parse(node.property("upgraded")).orDefault(false);
            if (extended && !value.isUpgradeable()) {
                throw this.fail(type, "Potion is not extendable");
            } else if (upgraded && !value.isUpgradeable()) {
                throw this.fail(type, "Potion is not upgradeable");
            } else if (extended && upgraded) {
                throw this.fail(type, "Potion cannot be both extended and upgraded");
            }
            itemMeta.setBasePotionData(new PotionData(value, extended, upgraded));
        }
        Property color = node.property("color");
        if (color != null) {
            itemMeta.setColor(this.colorParser.parse(color).orFail());
        }
        for (Node effect : node.children("effect", "potion-effect", "potioneffect")) {
            PotionEffect value = this.potionEffectParser.parse(effect).orFail();
            if (!itemMeta.hasCustomEffect(value.getType())) {
                itemMeta.addCustomEffect(value, false);
            }
        }
    }
    return itemMeta;
}
Also used : PotionData(org.bukkit.potion.PotionData) PotionEffect(org.bukkit.potion.PotionEffect) Node(pl.themolka.arcade.dom.Node) PotionType(org.bukkit.potion.PotionType) Property(pl.themolka.arcade.dom.Property)

Example 4 with Node

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

the class MapLoaderModule method onEnable.

@Override
public void onEnable(Node options) throws DOMException {
    for (Node directory : options.children("directory")) {
        String path = directory.propertyValue("path");
        List<Node> exclude = directory.children("exclude");
        List<Node> include = directory.children("include");
        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                if (!exclude.isEmpty()) {
                    for (Node node : exclude) {
                        if (name.equals(node.getValue())) {
                            return false;
                        }
                    }
                    return true;
                } else if (!include.isEmpty()) {
                    for (Node node : include) {
                        if (name.equals(node.getValue())) {
                            return true;
                        }
                    }
                    return false;
                }
                return true;
            }
        };
        File file = new File(path);
        if (file.exists()) {
            for (File worldFile : file.listFiles(filter)) {
                if (!this.worldFiles.contains(worldFile)) {
                    this.worldFiles.add(worldFile);
                }
            }
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Node(pl.themolka.arcade.dom.Node) File(java.io.File)

Example 5 with Node

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

the class ArchiveModule method onEnable.

@Override
public void onEnable(Node options) {
    if (options == null) {
        return;
    }
    Node directoryNode = options.firstChild("directory");
    if (directoryNode == null) {
        directoryNode = Node.ofPrimitive(null, "directory", DEFAULT_DIRECTORY_NAME);
    }
    File file = new File(directoryNode.getValue());
    if (!file.isDirectory()) {
        FileUtils.deleteQuietly(file);
    } else if (!file.exists()) {
        file.mkdir();
    }
    this.directory = file;
}
Also used : Node(pl.themolka.arcade.dom.Node) File(java.io.File)

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