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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations