Search in sources :

Example 1 with Property

use of pl.themolka.arcade.dom.Property 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 2 with Property

use of pl.themolka.arcade.dom.Property 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 3 with Property

use of pl.themolka.arcade.dom.Property 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)

Example 4 with Property

use of pl.themolka.arcade.dom.Property 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 5 with Property

use of pl.themolka.arcade.dom.Property 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

Property (pl.themolka.arcade.dom.Property)8 Node (pl.themolka.arcade.dom.Node)7 ArrayList (java.util.ArrayList)2 Material (org.bukkit.Material)1 Enchantment (org.bukkit.enchantments.Enchantment)1 ItemFlag (org.bukkit.inventory.ItemFlag)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 MaterialData (org.bukkit.material.MaterialData)1 PotionData (org.bukkit.potion.PotionData)1 PotionEffect (org.bukkit.potion.PotionEffect)1 PotionType (org.bukkit.potion.PotionType)1 BoundedItemModifier (pl.themolka.arcade.attribute.BoundedItemModifier)1 ParserException (pl.themolka.arcade.parser.ParserException)1