Search in sources :

Example 1 with InvalidXMLException

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

the class FlagParser method parsePost.

public Post parsePost(Element el) throws InvalidXMLException {
    checkDeprecatedFilter(el);
    @Nullable String name = el.getAttributeValue("name");
    String id = el.getAttributeValue("id");
    FeatureReference<TeamFactory> owner = factory.getFeatures().createReference(Node.fromAttr(el, "owner"), TeamFactory.class, null);
    boolean sequential = XMLUtils.parseBoolean(el.getAttribute("sequential"), false);
    boolean permanent = XMLUtils.parseBoolean(el.getAttribute("permanent"), false);
    double pointsPerSecond = XMLUtils.parseNumber(el.getAttribute("points-rate"), Double.class, 0D);
    Filter pickupFilter = filterParser.parseFilterProperty(el, "pickup-filter", StaticFilter.ALLOW);
    Duration recoverTime = XMLUtils.parseDuration(Node.fromAttr(el, "recover-time", "return-time"), Post.DEFAULT_RETURN_TIME);
    Duration respawnTime = XMLUtils.parseDuration(el.getAttribute("respawn-time"), null);
    Double respawnSpeed = XMLUtils.parseNumber(el.getAttribute("respawn-speed"), Double.class, (Double) null);
    ImmutableList<PointProvider> returnPoints = ImmutableList.copyOf(pointParser.parse(el, new PointProviderAttributes()));
    if (respawnTime == null && respawnSpeed == null) {
        respawnSpeed = Post.DEFAULT_RESPAWN_SPEED;
    }
    if (respawnTime != null && respawnSpeed != null) {
        throw new InvalidXMLException("post cannot have both respawn-time and respawn-speed", el);
    }
    if (returnPoints.isEmpty()) {
        throw new InvalidXMLException("post must have at least one point provider", el);
    }
    Post post = new Post(id, // Can be null
    name, owner, recoverTime, respawnTime, respawnSpeed, returnPoints, sequential, permanent, pointsPerSecond, pickupFilter);
    posts.add(post);
    factory.getFeatures().addFeature(el, post);
    return post;
}
Also used : Duration(java.time.Duration) PointProviderAttributes(tc.oc.pgm.points.PointProviderAttributes) PointProvider(tc.oc.pgm.points.PointProvider) Filter(tc.oc.pgm.api.filter.Filter) StaticFilter(tc.oc.pgm.filters.StaticFilter) InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) TeamFactory(tc.oc.pgm.teams.TeamFactory) Nullable(javax.annotation.Nullable)

Example 2 with InvalidXMLException

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

the class XMLFeatureReference method resolve.

@Override
public void resolve() throws InvalidXMLException {
    String id = this.getId();
    FeatureDefinition feature = this.context.get(id, FeatureDefinition.class);
    if (feature == null) {
        throw new InvalidXMLException("Unknown " + this.getTypeName() + " ID '" + id + "'", getNode());
    }
    if (!this.type.isInstance(feature)) {
        throw new InvalidXMLException("Wrong type for ID '" + id + "': expected " + this.getTypeName() + " rather than " + SelfIdentifyingFeatureDefinition.makeTypeName(feature.getClass()), getNode());
    }
    this.referent = this.type.cast(feature);
}
Also used : InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) FeatureDefinition(tc.oc.pgm.api.feature.FeatureDefinition)

Example 3 with InvalidXMLException

use of tc.oc.pgm.util.xml.InvalidXMLException 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 4 with InvalidXMLException

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

the class FilterParser method parseKillStreak.

@MethodParser("kill-streak")
public KillStreakFilter parseKillStreak(Element el) throws InvalidXMLException {
    boolean repeat = XMLUtils.parseBoolean(el.getAttribute("repeat"), false);
    Integer count = XMLUtils.parseNumber(el.getAttribute("count"), Integer.class, (Integer) null);
    Integer min = XMLUtils.parseNumber(el.getAttribute("min"), Integer.class, (Integer) null);
    Integer max = XMLUtils.parseNumber(el.getAttribute("max"), Integer.class, (Integer) null);
    Range<Integer> range;
    if (count != null) {
        range = Range.singleton(count);
    } else if (min == null) {
        if (max == null) {
            throw new InvalidXMLException("kill-streak filter must have a count, min, or max", el);
        } else {
            range = Range.atMost(max);
        }
    } else {
        if (max == null) {
            range = Range.atLeast(min);
        } else {
            range = Range.closed(min, max);
        }
    }
    if (!range.hasUpperBound() && repeat) {
        throw new InvalidXMLException("kill-streak filters with repeat=\"true\" must define a max or count", el);
    }
    return new KillStreakFilter(range, repeat);
}
Also used : InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) MethodParser(tc.oc.pgm.util.MethodParser)

Example 5 with InvalidXMLException

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

the class FilterParser method parseLives.

@MethodParser("lives")
public LivesFilter parseLives(Element el) throws InvalidXMLException {
    Integer count = XMLUtils.parseNumber(el.getAttribute("count"), Integer.class, (Integer) null);
    Integer min = XMLUtils.parseNumber(el.getAttribute("min"), Integer.class, (Integer) null);
    Integer max = XMLUtils.parseNumber(el.getAttribute("max"), Integer.class, (Integer) null);
    Range<Integer> range;
    if (count != null) {
        range = Range.singleton(count);
    } else if (min == null) {
        if (max == null) {
            throw new InvalidXMLException("lives filter must have a count, min, or max", el);
        } else {
            range = Range.atMost(max);
        }
    } else {
        if (max == null) {
            range = Range.atLeast(min);
        } else {
            range = Range.closed(min, max);
        }
    }
    return new LivesFilter(range);
}
Also used : InvalidXMLException(tc.oc.pgm.util.xml.InvalidXMLException) MethodParser(tc.oc.pgm.util.MethodParser)

Aggregations

InvalidXMLException (tc.oc.pgm.util.xml.InvalidXMLException)38 Element (org.jdom2.Element)13 Node (tc.oc.pgm.util.xml.Node)12 MethodParser (tc.oc.pgm.util.MethodParser)10 Vector (org.bukkit.util.Vector)9 Attribute (org.jdom2.Attribute)7 ArrayList (java.util.ArrayList)6 Filter (tc.oc.pgm.api.filter.Filter)6 Region (tc.oc.pgm.api.region.Region)6 TeamFactory (tc.oc.pgm.teams.TeamFactory)6 StaticFilter (tc.oc.pgm.filters.StaticFilter)4 Duration (java.time.Duration)2 Nullable (javax.annotation.Nullable)2 Component (net.kyori.adventure.text.Component)2 ItemStack (org.bukkit.inventory.ItemStack)2 Kit (tc.oc.pgm.kits.Kit)2 PointProvider (tc.oc.pgm.points.PointProvider)2 PointProviderAttributes (tc.oc.pgm.points.PointProviderAttributes)2 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1