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