Search in sources :

Example 1 with FilterNode

use of tc.oc.pgm.filters.FilterNode in project PGM by PGMDev.

the class RegionFilterApplicationParser method parse.

public void parse(Element el) throws InvalidXMLException {
    Region region = parseRegion(el);
    Component message = XMLUtils.parseFormattedText(el, "message");
    boolean earlyWarning = XMLUtils.parseBoolean(el.getAttribute("early-warning"), false);
    Filter effectFilter = filterParser.parseFilterProperty(el, "filter");
    Kit kit = factory.getKits().parseKitProperty(el, "kit");
    if (kit != null) {
        add(el, new RegionFilterApplication(RFAScope.EFFECT, region, effectFilter, kit, false));
    }
    kit = factory.getKits().parseKitProperty(el, "lend-kit");
    if (kit != null) {
        add(el, new RegionFilterApplication(RFAScope.EFFECT, region, effectFilter, kit, true));
    }
    Attribute attrVelocity = el.getAttribute("velocity");
    if (attrVelocity != null) {
        // Legacy support
        String velocityText = attrVelocity.getValue();
        if (velocityText.charAt(0) == '@')
            velocityText = velocityText.substring(1);
        Vector velocity = XMLUtils.parseVector(attrVelocity, velocityText);
        add(el, new RegionFilterApplication(RFAScope.EFFECT, region, effectFilter, velocity));
    }
    for (String tag : RFAScope.byTag.keySet()) {
        Filter filter;
        if (useId()) {
            filter = filterParser.parseFilterProperty(el, tag);
        } else {
            // Legacy syntax allows a list of filter names in the attribute
            Node node = Node.fromAttr(el, tag);
            if (node == null) {
                filter = null;
            } else {
                List<Filter> filters = new ArrayList<>();
                for (String name : Splitter.on(" ").split(node.getValue())) {
                    filters.add(filterParser.parseReference(node, name));
                }
                switch(filters.size()) {
                    case 0:
                        filter = null;
                        break;
                    case 1:
                        filter = filters.get(0);
                        break;
                    default:
                        filter = new FilterNode(filters, Collections.<Filter>emptyList(), Collections.<Filter>emptyList());
                }
            }
        }
        if (filter != null) {
            for (RFAScope scope : RFAScope.byTag.get(tag)) {
                add(el, new RegionFilterApplication(scope, region, filter, message, earlyWarning));
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Node(tc.oc.pgm.util.xml.Node) FilterNode(tc.oc.pgm.filters.FilterNode) FilterNode(tc.oc.pgm.filters.FilterNode) ArrayList(java.util.ArrayList) TeamFilter(tc.oc.pgm.filters.TeamFilter) DenyFilter(tc.oc.pgm.filters.DenyFilter) Filter(tc.oc.pgm.api.filter.Filter) StaticFilter(tc.oc.pgm.filters.StaticFilter) Kit(tc.oc.pgm.kits.Kit) Region(tc.oc.pgm.api.region.Region) Component(net.kyori.adventure.text.Component) Vector(org.bukkit.util.Vector)

Aggregations

ArrayList (java.util.ArrayList)1 Component (net.kyori.adventure.text.Component)1 Vector (org.bukkit.util.Vector)1 Attribute (org.jdom2.Attribute)1 Filter (tc.oc.pgm.api.filter.Filter)1 Region (tc.oc.pgm.api.region.Region)1 DenyFilter (tc.oc.pgm.filters.DenyFilter)1 FilterNode (tc.oc.pgm.filters.FilterNode)1 StaticFilter (tc.oc.pgm.filters.StaticFilter)1 TeamFilter (tc.oc.pgm.filters.TeamFilter)1 Kit (tc.oc.pgm.kits.Kit)1 Node (tc.oc.pgm.util.xml.Node)1