Search in sources :

Example 1 with Node

use of tc.oc.pgm.util.xml.Node in project PGM by PGMDev.

the class FilterParser method parseOffsetFilter.

// Methods for parsing QueryModifiers
@MethodParser("offset")
public LocationQueryModifier parseOffsetFilter(Element el) throws InvalidXMLException {
    String value = el.getAttributeValue("vector");
    if (value == null)
        throw new InvalidXMLException("No vector provided", el);
    // Check vector format
    Vector vector = XMLUtils.parseVector(new Node(el), value.replaceAll("[\\^~]", ""));
    String[] coords = value.split("\\s*,\\s*");
    boolean[] relative = new boolean[3];
    Boolean local = null;
    for (int i = 0; i < coords.length; i++) {
        String coord = coords[i];
        if (local == null) {
            local = coord.startsWith("^");
        }
        if (coord.startsWith("^") != local)
            throw new InvalidXMLException("Cannot mix world & local coordinates", el);
        relative[i] = coord.startsWith("~");
    }
    if (local == null)
        throw new InvalidXMLException("No coordinates provided", el);
    if (local) {
        return new LocalLocationQueryModifier(parseChild(el), vector);
    } else {
        return new WorldLocationQueryModifier(parseChild(el), vector, relative);
    }
}
Also used : WorldLocationQueryModifier(tc.oc.pgm.filters.modifier.location.WorldLocationQueryModifier) LocalLocationQueryModifier(tc.oc.pgm.filters.modifier.location.LocalLocationQueryModifier) Node(tc.oc.pgm.util.xml.Node) InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Vector(org.bukkit.util.Vector) MethodParser(tc.oc.pgm.util.MethodParser)

Example 2 with Node

use of tc.oc.pgm.util.xml.Node in project PGM by PGMDev.

the class FilterParser method parseFiltersProperty.

/**
 * Return a list containing any and all of the following: - A filter reference in an attribute of
 * the given name - Inline filters inside child tags of the given name
 */
public List<Filter> parseFiltersProperty(Element el, String name) throws InvalidXMLException {
    List<Filter> filters = new ArrayList<>();
    Attribute attr = el.getAttribute(name);
    if (attr != null) {
        filters.add(this.parseReference(new Node(attr)));
    }
    for (Element elFilter : el.getChildren(name)) {
        filters.addAll(this.parseChildren(elFilter));
    }
    return filters;
}
Also used : Filter(tc.oc.pgm.api.filter.Filter) Attribute(org.jdom2.Attribute) Node(tc.oc.pgm.util.xml.Node) Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 3 with Node

use of tc.oc.pgm.util.xml.Node in project PGM by PGMDev.

the class KitParser method parseDefinition.

protected KitDefinition parseDefinition(Element el) throws InvalidXMLException {
    List<Kit> kits = Lists.newArrayList();
    Node attrParents = Node.fromAttr(el, "parent", "parents");
    if (attrParents != null) {
        Iterable<String> parentNames = Splitter.on(',').split(attrParents.getValue());
        for (String parentName : parentNames) {
            kits.add(parseReference(attrParents, parentName.trim()));
        }
    }
    Boolean force = XMLUtils.parseBoolean(Node.fromAttr(el, "force"));
    Boolean potionParticles = XMLUtils.parseBoolean(Node.fromAttr(el, "potion-particles"));
    Filter filter = factory.getFilters().parseFilterProperty(el, "filter", StaticFilter.ALLOW);
    // must be added before anything else
    kits.add(this.parseClearItemsKit(el));
    for (Element child : el.getChildren("kit")) {
        kits.add(this.parse(child));
    }
    kits.add(this.parseArmorKit(el));
    kits.add(this.parseItemKit(el));
    kits.add(this.parsePotionKit(el));
    kits.add(this.parseAttributeKit(el));
    kits.add(this.parseHealthKit(el));
    kits.add(this.parseHungerKit(el));
    kits.add(this.parseKnockbackReductionKit(el));
    kits.add(this.parseWalkSpeedKit(el));
    kits.add(this.parseDoubleJumpKit(el));
    kits.add(this.parseEnderPearlKit(el));
    kits.add(this.parseFlyKit(el));
    kits.add(this.parseGameModeKit(el));
    kits.add(this.parseShieldKit(el));
    kits.add(this.parseTeamSwitchKit(el));
    kits.add(this.parseMaxHealthKit(el));
    kits.addAll(this.parseRemoveKits(el));
    // Remove any nulls returned above
    kits.removeAll(Collections.singleton((Kit) null));
    this.kits.addAll(kits);
    return new KitNode(kits, filter, force, potionParticles);
}
Also used : Filter(tc.oc.pgm.api.filter.Filter) StaticFilter(tc.oc.pgm.filters.StaticFilter) ShieldKit(tc.oc.pgm.shield.ShieldKit) DoubleJumpKit(tc.oc.pgm.doublejump.DoubleJumpKit) Node(tc.oc.pgm.util.xml.Node) Element(org.jdom2.Element)

Example 4 with Node

use of tc.oc.pgm.util.xml.Node in project PGM by PGMDev.

the class KitParser method parseCustomNBT.

public void parseCustomNBT(Element el, ItemStack itemStack) throws InvalidXMLException {
    if (XMLUtils.parseBoolean(el.getAttribute("grenade"), false)) {
        Grenade.ITEM_TAG.set(itemStack, new Grenade(XMLUtils.parseNumber(el.getAttribute("grenade-power"), Float.class, 1f), XMLUtils.parseBoolean(el.getAttribute("grenade-fire"), false), XMLUtils.parseBoolean(el.getAttribute("grenade-destroy"), true)));
    }
    if (XMLUtils.parseBoolean(el.getAttribute("prevent-sharing"), false)) {
        ItemTags.PREVENT_SHARING.set(itemStack, true);
    }
    if (itemStack.getAmount() == -1) {
        ItemTags.INFINITE.set(itemStack, true);
    }
    Node projectileNode = Node.fromAttr(el, "projectile");
    if (projectileNode != null) {
        ItemTags.PROJECTILE.set(itemStack, factory.getFeatures().createReference(projectileNode, ProjectileDefinition.class).getId());
        String name = itemStack.getItemMeta().getDisplayName();
        ItemTags.ORIGINAL_NAME.set(itemStack, name != null ? name : "");
    }
}
Also used : Node(tc.oc.pgm.util.xml.Node) Grenade(tc.oc.pgm.kits.tag.Grenade)

Example 5 with Node

use of tc.oc.pgm.util.xml.Node in project PGM by PGMDev.

the class KitParser method parseRemoveKits.

public Collection<RemoveKit> parseRemoveKits(Element parent) throws InvalidXMLException {
    Set<RemoveKit> kits = Collections.emptySet();
    for (Element el : parent.getChildren("remove")) {
        if (kits.isEmpty())
            kits = new HashSet<>();
        Node idAttr = Node.fromAttr(el, "id");
        RemoveKit kit;
        if (idAttr != null) {
            kit = new RemoveKit(parseReference(idAttr, idAttr.getValue()));
        } else {
            kit = new RemoveKit(parse(el));
        }
        kits.add(kit);
        factory.getFeatures().addFeature(el, // So we can retrieve the node from KitModule#postParse
        kit);
    }
    return kits;
}
Also used : Element(org.jdom2.Element) Node(tc.oc.pgm.util.xml.Node) HashSet(java.util.HashSet)

Aggregations

Node (tc.oc.pgm.util.xml.Node)23 InvalidXMLException (tc.oc.pgm.util.xml.InvalidXMLException)12 Element (org.jdom2.Element)11 Attribute (org.jdom2.Attribute)9 Filter (tc.oc.pgm.api.filter.Filter)8 ArrayList (java.util.ArrayList)7 StaticFilter (tc.oc.pgm.filters.StaticFilter)6 Region (tc.oc.pgm.api.region.Region)5 TeamFactory (tc.oc.pgm.teams.TeamFactory)5 Component (net.kyori.adventure.text.Component)4 Vector (org.bukkit.util.Vector)4 MethodParser (tc.oc.pgm.util.MethodParser)4 TeamFilter (tc.oc.pgm.filters.TeamFilter)3 Kit (tc.oc.pgm.kits.Kit)3 AbstractMap (java.util.AbstractMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DenyFilter (tc.oc.pgm.filters.DenyFilter)2 FilterNode (tc.oc.pgm.filters.FilterNode)2 TeamModule (tc.oc.pgm.teams.TeamModule)2