Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow triggers to support child definitions #1074

Merged
merged 2 commits into from
Oct 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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