Search in sources :

Example 1 with Region

use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.

the class Intersect method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Intersect{regions=[");
    for (Region region : this.regions) {
        sb.append(region.toString()).append(",");
    }
    sb.append("]}");
    return sb.toString();
}
Also used : Region(tc.oc.pgm.api.region.Region)

Example 2 with Region

use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.

the class LegacyRegionParser method parse.

public Region parse(Element el) throws InvalidXMLException {
    Region region = this.parseDynamic(el);
    String name = el.getAttributeValue("name");
    if (name == null || el.getName().equalsIgnoreCase("region")) {
        this.regionContext.add(region);
    } else {
        if (this.regionContext.get(name) == null) {
            this.regionContext.add(name, region);
        } else {
            throw new InvalidXMLException("The region '" + name + "' already exists", el);
        }
    }
    return region;
}
Also used : InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Region(tc.oc.pgm.api.region.Region)

Example 3 with Region

use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.

the class LegacyRegionParser method parseReference.

public Region parseReference(Attribute attr) throws InvalidXMLException {
    String name = attr.getValue();
    Region region = this.regionContext.get(name);
    if (region == null) {
        throw new InvalidXMLException("Unknown region '" + name + "'", attr);
    } else {
        return region;
    }
}
Also used : InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Region(tc.oc.pgm.api.region.Region)

Example 4 with Region

use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.

the class RegionParser method parseRegionProperty.

@Nullable
public Region parseRegionProperty(Element rootElement, @Nullable FeatureValidation<RegionDefinition> validation, Region def, String... names) throws InvalidXMLException {
    Attribute propertyAttribute = null;
    Element propertyElement = null;
    for (String name : names) {
        if (rootElement.getAttribute(name) != null && rootElement.getChild(name) != null) {
            throw new InvalidXMLException("Multiple defined region properties for " + name, rootElement);
        }
        if ((rootElement.getAttribute(name) != null || rootElement.getChild(name) != null) && (propertyAttribute != null || propertyElement != null)) {
            throw new InvalidXMLException("Multiple defined region properties for " + Arrays.toString(names), rootElement);
        }
        if (rootElement.getAttribute(name) != null) {
            propertyAttribute = rootElement.getAttribute(name);
        } else if (rootElement.getChild(name) != null) {
            propertyElement = rootElement.getChild(name);
        }
    }
    Region region = def;
    Node node = null;
    if (propertyAttribute != null) {
        region = this.parseReference(propertyAttribute);
        node = new Node(propertyAttribute);
    } else if (propertyElement != null) {
        region = this.parseChildren(propertyElement);
        node = new Node(propertyElement);
    }
    if (region != null && validation != null) {
        validate(region, validation, node);
    }
    return region;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Node(tc.oc.pgm.util.xml.Node) InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Region(tc.oc.pgm.api.region.Region) Nullable(javax.annotation.Nullable)

Example 5 with Region

use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.

the class RegionParser method parseHalves.

protected RegionDefinition parseHalves(Element el, double dir) throws InvalidXMLException {
    Double x = XMLUtils.parseNumber(el.getAttribute("x"), Double.class, (Double) null);
    Double y = XMLUtils.parseNumber(el.getAttribute("y"), Double.class, (Double) null);
    Double z = XMLUtils.parseNumber(el.getAttribute("z"), Double.class, (Double) null);
    List<HalfspaceRegion> halves = new ArrayList<>();
    if (x != null)
        halves.add(new HalfspaceRegion(new Vector(x, 0, 0), new Vector(dir, 0, 0)));
    if (y != null)
        halves.add(new HalfspaceRegion(new Vector(0, y, 0), new Vector(0, dir, 0)));
    if (z != null)
        halves.add(new HalfspaceRegion(new Vector(0, 0, z), new Vector(0, 0, dir)));
    switch(halves.size()) {
        case 0:
            throw new InvalidXMLException("Expected at least one of x, y, or z attributes", el);
        case 1:
            return halves.get(0);
        default:
            return new Intersect((Region[]) halves.toArray());
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) Region(tc.oc.pgm.api.region.Region) Vector(org.bukkit.util.Vector)

Aggregations

Region (tc.oc.pgm.api.region.Region)14 InvalidXMLException (tc.oc.pgm.util.xml.InvalidXMLException)6 Component (net.kyori.adventure.text.Component)5 Vector (org.bukkit.util.Vector)5 Filter (tc.oc.pgm.api.filter.Filter)5 Node (tc.oc.pgm.util.xml.Node)5 Attribute (org.jdom2.Attribute)4 StaticFilter (tc.oc.pgm.filters.StaticFilter)3 ArrayList (java.util.ArrayList)2 DenyFilter (tc.oc.pgm.filters.DenyFilter)2 FilterNode (tc.oc.pgm.filters.FilterNode)2 TeamFilter (tc.oc.pgm.filters.TeamFilter)2 TeamFactory (tc.oc.pgm.teams.TeamFactory)2 Duration (java.time.Duration)1 Nullable (javax.annotation.Nullable)1 Element (org.jdom2.Element)1 AnyFilter (tc.oc.pgm.filters.AnyFilter)1 BlockFilter (tc.oc.pgm.filters.BlockFilter)1 FilterParser (tc.oc.pgm.filters.FilterParser)1 Kit (tc.oc.pgm.kits.Kit)1