Skip to content

Commit

Permalink
Allow triggers to support child definitions (#1074)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 authored Oct 10, 2022
1 parent c9e7d58 commit c563f4b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/src/main/java/tc/oc/pgm/action/ActionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -89,6 +90,17 @@ public <B> Action<? super B> parseReference(Node node, String id, Class<B> bound
return action;
}

public <B extends Filterable<?>> Action<? super B> parseProperty(
@NotNull Node node, Class<B> bound) throws InvalidXMLException {
if (node.isAttribute()) return this.parseReference(node, bound);

ActionNode<? super B> 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<ActionDefinition<?>> validation, Node node)
Expand Down Expand Up @@ -126,8 +138,8 @@ public <T extends Filterable<?>> Trigger<T> parseTrigger(Element el) throws Inva
Class<T> 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 <B extends Filterable<?>> Class<B> parseScope(Element el, Class<B> scope)
Expand Down

0 comments on commit c563f4b

Please sign in to comment.