From aacbe87f6e94fa3977be25f3a22527f89ecc5148 Mon Sep 17 00:00:00 2001 From: Pablete1234 Date: Mon, 10 Oct 2022 01:56:47 +0200 Subject: [PATCH 1/2] Allow triggers to support child definitions Signed-off-by: Pablete1234 --- .../main/java/tc/oc/pgm/action/ActionParser.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/action/ActionParser.java b/core/src/main/java/tc/oc/pgm/action/ActionParser.java index c35e569a85..fdd80026d3 100644 --- a/core/src/main/java/tc/oc/pgm/action/ActionParser.java +++ b/core/src/main/java/tc/oc/pgm/action/ActionParser.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableList; import java.lang.reflect.Method; import java.util.Map; +import javax.annotation.Nonnull; import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; import org.bukkit.inventory.ItemStack; @@ -89,6 +90,17 @@ public Action parseReference(Node node, String id, Class bound return action; } + public > Action parseProperty( + @Nonnull Node node, Class bound) throws InvalidXMLException { + if (node.isAttribute()) return this.parseReference(node, bound); + + ActionNode result = this.parseAction(node.getElement(), bound); + + if (bound != null) validate(result, ActionScopeValidation.of(bound), node); + features.addFeature(node.getElement(), result); + return result; + } + @SuppressWarnings("rawtypes, unchecked") public void validate( Action action, FeatureValidation> validation, Node node) @@ -126,8 +138,8 @@ public > Trigger parseTrigger(Element el) throws Inva Class cls = Filterables.parse(Node.fromRequiredAttr(el, "scope")); return new Trigger<>( cls, - filters.parseReference(Node.fromRequiredAttr(el, "filter")), - parseReference(Node.fromRequiredAttr(el, "trigger", "action"), cls)); + filters.parseProperty(el, "filter"), + parseProperty(Node.fromRequiredChildOrAttr(el, "trigger", "action"), cls)); } private > Class parseScope(Element el, Class scope) From 82bdb566843c2e906cd88af08e19ea79411c0204 Mon Sep 17 00:00:00 2001 From: Pablete1234 Date: Mon, 10 Oct 2022 06:10:45 +0200 Subject: [PATCH 2/2] Comply with new formatting Signed-off-by: Pablete1234 --- core/src/main/java/tc/oc/pgm/action/ActionParser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/action/ActionParser.java b/core/src/main/java/tc/oc/pgm/action/ActionParser.java index fdd80026d3..0557a9d922 100644 --- a/core/src/main/java/tc/oc/pgm/action/ActionParser.java +++ b/core/src/main/java/tc/oc/pgm/action/ActionParser.java @@ -5,11 +5,11 @@ import com.google.common.collect.ImmutableList; import java.lang.reflect.Method; import java.util.Map; -import javax.annotation.Nonnull; import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; import org.bukkit.inventory.ItemStack; import org.jdom2.Element; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import tc.oc.pgm.action.actions.ActionNode; import tc.oc.pgm.action.actions.KillEntitiesAction; @@ -91,7 +91,7 @@ public Action parseReference(Node node, String id, Class bound } public > Action parseProperty( - @Nonnull Node node, Class bound) throws InvalidXMLException { + @NotNull Node node, Class bound) throws InvalidXMLException { if (node.isAttribute()) return this.parseReference(node, bound); ActionNode result = this.parseAction(node.getElement(), bound);