Skip to content

Commit

Permalink
⚡ Added event context for ReturningSections
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Apr 18, 2024
1 parent 62131ca commit f593ec4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,30 @@ public static <T, S extends ReturningSection<T>> void register(Class<S> sectionC
Class expression,
String... patterns) {
for (int i = 0; i < patterns.length; i++)
patterns[i] += " and store (it|the result) in %-objects%";
patterns[i] += " [and store (it|the result) in %-~objects%]";

Skript.registerSection(sectionClass, patterns);
Skript.registerExpression(expression, returnType, ExpressionType.SIMPLE, "[the] [last] "+expression.getSimpleName()+" [builder]");
Skript.registerExpression(expression, returnType, ExpressionType.SIMPLE, "[the] "+expression.getSimpleName()+" [builder]");
}

public abstract T createNewValue();
public abstract T createNewValue(@NotNull Event event);

private T currentValue;
private Variable<T> variable;

@Override
public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, @NotNull SkriptParser.ParseResult parseResult, @NotNull SectionNode sectionNode, @NotNull List<TriggerItem> triggerItems) {
loadOptionalCode(sectionNode);
variable = (Variable<T>) exprs[0];
variable = (Variable<T>) exprs[exprs.length - 1];
return true;
}

@Override
protected @Nullable TriggerItem walk(@NotNull Event e) {

currentValue = createNewValue();
variable.change(e, new Object[] {currentValue}, Changer.ChangeMode.SET);
currentValue = createNewValue(e);
if (variable != null)
variable.change(e, new Object[] {currentValue}, Changer.ChangeMode.SET);

return walk(e, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class rule extends LastBuilderExpression<AutoModRuleBuilder, Creat
}

@Override
public AutoModRuleBuilder createNewValue() {
public AutoModRuleBuilder createNewValue(Event event) {
return new AutoModRuleBuilder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class row extends LastBuilderExpression<ComponentRow, CreateRow> {
}

@Override
public ComponentRow createNewValue() {
public ComponentRow createNewValue(Event event) {
return new ComponentRow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul
}

@Override
public MessageCreateBuilder createNewValue() {
public MessageCreateBuilder createNewValue(Event event) {
return new MessageCreateBuilder().setSuppressedNotifications(silent);
}

Expand Down

0 comments on commit f593ec4

Please sign in to comment.