Search in sources :

Example 11 with Node

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

the class MobsGameParser method parseNode.

@Override
protected ParserResult<MobsGame.Config> parseNode(Node node, String name, String value) throws ParserException {
    List<MobSpawnRule.Config> rules = new ArrayList<>();
    for (Node ruleNode : node.children("rule")) {
        rules.add(this.ruleParser.parse(ruleNode).orFail());
    }
    boolean denyNatural = this.denyNautralParser.parse(node.property("deny-natural")).orDefault(false);
    if (!denyNatural && ParserUtils.ensureNotEmpty(rules)) {
        throw this.fail(node, name, value, "No rules defined");
    }
    return ParserResult.fine(node, name, value, new MobsGame.Config() {

        public List<MobSpawnRule.Config> rules() {
            return rules;
        }

        public boolean denyNatural() {
            return denyNatural;
        }
    });
}
Also used : Node(pl.themolka.arcade.dom.Node) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with Node

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

the class ArcadePlugin method loadModules.

private void loadModules() {
    Node ignoredModules = this.getSettings().getData().child("ignored-modules");
    if (ignoredModules == null) {
        ignoredModules = Node.empty();
    }
    List<String> ignoredModuleList = new ArrayList<>();
    for (Node ignoredModule : ignoredModules.children("module")) {
        String id = ignoredModule.getValue();
        if (id != null && !id.isEmpty()) {
            ignoredModuleList.add(id);
        }
    }
    List<Module<?>> moduleList = new ArrayList<>();
    try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ModulesFile.DEFAULT_FILENAME)) {
        ModulesFile file = new ModulesFile(this, input);
        for (Module<?> module : file.getModules()) {
            ModuleInfo infoAnnotation = module.getClass().getAnnotation(ModuleInfo.class);
            if (infoAnnotation == null) {
                continue;
            }
            if (!ignoredModuleList.contains(infoAnnotation.id().toLowerCase())) {
                moduleList.add(module);
            }
        }
    } catch (DOMException | IOException ex) {
        ex.printStackTrace();
    }
    ModulesLoadEvent loadEvent = new ModulesLoadEvent(this, moduleList);
    this.getEventBus().publish(loadEvent);
    List<Module<?>> success = new ArrayList<>();
    for (Module<?> module : loadEvent.getModules()) {
        try {
            module.initialize(this);
            module.registerCommandObject(module);
            success.add(module);
        } catch (Throwable th) {
            this.getLogger().log(Level.SEVERE, "Could not load module '" + module.getId() + "': " + th.getMessage(), th);
        }
    }
    this.getLogger().info("Successfully loaded " + success.size() + " of " + loadEvent.getModules().size() + " available modules.");
    this.getModules().register(success.toArray(new Module<?>[success.size()]));
    Node globalModules = this.getSettings().getData().child("modules");
    if (globalModules == null) {
        globalModules = Node.empty();
    }
    for (Module<?> module : this.getModules().getModules()) {
        try {
            Node moduleNode = globalModules.child(module.getId());
            module.setGlobal(moduleNode != null);
            module.registerListeners();
            module.onEnable(moduleNode);
        } catch (Throwable th) {
            this.getLogger().log(Level.SEVERE, "Could not enable module '" + module.getId() + "': " + th.getMessage(), th);
        }
    }
}
Also used : ModulesLoadEvent(pl.themolka.arcade.module.ModulesLoadEvent) InputStream(java.io.InputStream) Node(pl.themolka.arcade.dom.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DOMException(pl.themolka.arcade.dom.DOMException) ModulesFile(pl.themolka.arcade.module.ModulesFile) ModuleInfo(pl.themolka.arcade.module.ModuleInfo) Module(pl.themolka.arcade.module.Module)

Example 13 with Node

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

the class ArcadePlugin method loadServer.

private void loadServer() {
    Node node = this.getSettings().getData().child("server");
    if (node == null) {
        node = Node.empty();
    }
    String name = node.propertyValue("name");
    if (name != null && this.serverName.equals(DEFAULT_SERVER_NAME)) {
        this.serverName = name;
    }
    this.registerListenerObject(new BlockTransformListeners(this));
    this.registerListenerObject(new GeneralListeners(this));
    this.registerListenerObject(new ProtectionListeners(this));
    // dead events
    this.registerListenerObject(new DeadListeners(this));
    // sessions
    this.registerListenerObject(new Sessions(this));
    // windows
    this.registerListenerObject(new WindowListeners(this));
}
Also used : DeadListeners(pl.themolka.arcade.event.DeadListeners) Node(pl.themolka.arcade.dom.Node) GeneralListeners(pl.themolka.arcade.listener.GeneralListeners) Sessions(pl.themolka.arcade.session.Sessions) BlockTransformListeners(pl.themolka.arcade.listener.BlockTransformListeners) ProtectionListeners(pl.themolka.arcade.listener.ProtectionListeners) WindowListeners(pl.themolka.arcade.window.WindowListeners)

Example 14 with Node

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

the class ItemStackParser method parseTree.

@Override
protected ParserResult<ItemStack> parseTree(Node node, String name) throws ParserException {
    Property amountProperty = node.property("amount", "total");
    Property durabilityProperty = node.property("durability");
    MaterialData type = this.typeParser.parse(node.property(MaterialParser.MATERIAL_ELEMENT_NAMES)).orFail();
    int amount = this.amountParser.parse(amountProperty).orDefault(1);
    String displayName = this.displayNameParser.parse(node.firstChild("name", "display-name")).orDefaultNull();
    List<String> description = this.parseDescription(node);
    short durability = this.durabilityParser.parse(durabilityProperty).orDefault((short) 0);
    List<ItemEnchantment> enchantments = this.parseEnchantments(node);
    List<Material> canDestroy = this.parseDestroy(node);
    List<Material> canPlaceOn = this.parseCanPlaceOn(node);
    boolean unbreakable = this.unbreakableParser.parse(node.property("unbreakable", "permanent")).orDefault(false);
    List<ItemFlag> flags = this.parseFlags(node);
    if (amount <= 0) {
        throw this.fail(amountProperty, "Amount must be positive (greater than 0)");
    } else if (type.getData() != 0 && durability != 0) {
        // Notch made a huge mistake here... :(
        throw this.fail(durabilityProperty, "Sorry! Durability cannot be combined with material data!");
    }
    ItemStack itemStack = new ItemStack(type.getItemType());
    itemStack.setData(type);
    itemStack.setAmount(amount);
    itemStack.setDurability(durability);
    for (ItemEnchantment enchantment : enchantments) {
        enchantment.apply(itemStack);
    }
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (displayName != null) {
        itemMeta.setDisplayName(displayName);
    }
    if (!description.isEmpty()) {
        itemMeta.setLore(description);
    }
    if (!canDestroy.isEmpty()) {
        itemMeta.setCanDestroy(canDestroy);
    }
    if (!canPlaceOn.isEmpty()) {
        itemMeta.setCanPlaceOn(canPlaceOn);
    }
    for (Node modifierNode : node.children("modifier", "attribute-modifier", "attributemodifier", "attribute")) {
        BoundedItemModifier modifier = this.modifierParser.parse(modifierNode).orFail();
        itemMeta.addAttributeModifier(modifier.getKey().key(), modifier.getItemModifier());
    }
    itemMeta.setUnbreakable(unbreakable);
    itemMeta.addItemFlags(flags.toArray(new ItemFlag[flags.size()]));
    itemStack.setItemMeta(this.itemMetaParser.parse(node, itemStack, itemMeta));
    return ParserResult.fine(node, name, itemStack);
}
Also used : Node(pl.themolka.arcade.dom.Node) Material(org.bukkit.Material) BoundedItemModifier(pl.themolka.arcade.attribute.BoundedItemModifier) MaterialData(org.bukkit.material.MaterialData) ItemFlag(org.bukkit.inventory.ItemFlag) ItemStack(org.bukkit.inventory.ItemStack) Property(pl.themolka.arcade.dom.Property) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 15 with Node

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

the class BookMetaParser method parse.

@Override
public BookMeta parse(Node root, ItemStack itemStack, BookMeta itemMeta) throws ParserException {
    Node node = root.firstChild("book");
    if (node != null) {
        Property author = root.property("author", "signed", "signed-as");
        if (author != null) {
            itemMeta.setAuthor(this.authorParser.parse(author).orFail());
        }
        Property generation = root.property("generation");
        if (generation != null) {
            itemMeta.setGeneration(this.generationParser.parse(generation).orFail());
        }
        Property title = root.property("title", "name");
        if (title != null) {
            itemMeta.setTitle(this.titleParser.parse(title).orFail());
        }
        List<String> pages = new ArrayList<>();
        for (Node page : node.children("page")) {
            pages.add(this.pageParser.parse(page).orFail());
        }
        itemMeta.setPages(pages);
    }
    return itemMeta;
}
Also used : Node(pl.themolka.arcade.dom.Node) ArrayList(java.util.ArrayList) 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