Search in sources :

Example 6 with Property

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

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

the class ItemEnchantmentParser method parsePrimitive.

@Override
protected ParserResult<ItemEnchantment> parsePrimitive(Node node, String name, String value) throws ParserException {
    Enchantment type = this.typeParser.parseWithDefinition(node, name, value).orFail();
    Property levelProperty = node.property("level", "lvl");
    int level = this.levelParser.parse(levelProperty).orDefault(1);
    if (level <= 0) {
        throw this.fail(levelProperty, "Level must be positive (greater than 0)");
    }
    return ParserResult.fine(node, name, value, new ItemEnchantment(type, level));
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment) Property(pl.themolka.arcade.dom.Property)

Example 8 with Property

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

the class OfflineMapParser method parseTree.

@Override
protected ParserResult<OfflineMap> parseTree(Node node, String name) throws ParserException {
    Property fileVersionProperty = node.property("fileversion", "file-version", "ver", "version", "proto", "manifest");
    MapFileVersion fileVersion = this.fileVersionParser.parse(fileVersionProperty).orDefault(MapFileVersions.NEWEST);
    Node nameNode = node.firstChild("name");
    Node versionNode = node.firstChild("version", "ver");
    if (nameNode == null || versionNode == null) {
        throw new ParserException(node, MISSING_NAME_VERSION);
    }
    String mapName = this.nameParser.parse(nameNode).orFail();
    MapVersion version = this.versionParser.parse(versionNode).orFail();
    String description = this.descriptionParser.parse(node.firstChild("description", "objective", "goal", "about")).orNull();
    int mapNameLength = mapName.length();
    if (mapNameLength < OfflineMap.NAME_MIN_LENGTH) {
        throw this.fail(nameNode, nameNode.getName(), nameNode.getValue(), "Map name is shorter than " + OfflineMap.NAME_MIN_LENGTH + " characters");
    } else if (mapNameLength > OfflineMap.NAME_MAX_LENGTH) {
        throw this.fail(nameNode, nameNode.getName(), nameNode.getValue(), "Map name is longer than " + OfflineMap.NAME_MAX_LENGTH + " characters");
    }
    List<Author> authors = this.parseAuthors(node);
    Node authorsNode = node.firstChild("authors", "contributors", "teams");
    if (authorsNode != null) {
        authors.addAll(this.parseAuthors(authorsNode));
    }
    List<Changelog> changelogs = new ArrayList<>();
    Node changelogsNode = node.firstChild("changelog", "change-log", "changes");
    if (changelogsNode != null) {
        changelogs.addAll(this.parseChangelogs(changelogsNode));
    }
    return ParserResult.fine(node, name, new OfflineMap(fileVersion, mapName, version, description, authors, changelogs));
}
Also used : ParserException(pl.themolka.arcade.parser.ParserException) 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