Skip to content

preInit Follow Up + SectionExpression#isSectionOnly #7929

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

Merged
Merged
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions src/main/java/ch/njol/skript/effects/EffWakeupSleep.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.bukkit.entity.*;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;

@Name("Wake And Sleep")
@Description({
Expand All @@ -36,7 +35,7 @@
"make player wake up without spawn location update"
})
@Since("2.11")
public class EffWakeupSleep extends Effect implements SyntaxRuntimeErrorProducer {
public class EffWakeupSleep extends Effect {

static {
Skript.registerEffect(EffWakeupSleep.class,
Expand All @@ -55,7 +54,6 @@ public class EffWakeupSleep extends Effect implements SyntaxRuntimeErrorProducer
private boolean sleep;
private boolean force;
private boolean setSpawn;
private Node node;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
Expand All @@ -70,7 +68,6 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
//noinspection unchecked
this.location = Direction.combine((Expression<Direction>) exprs[1], (Expression<Location>) exprs[2]);
}
node = getParser().getNode();
return true;
}

Expand Down Expand Up @@ -111,11 +108,6 @@ protected void execute(Event event) {
warning("The provided location is not set. This effect will have no effect for villagers and players.");
}

@Override
public Node getNode() {
return node;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.bukkit.WorldBorder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;

@Name("Expand/Shrink World Border")
@Description({
Expand All @@ -30,7 +29,7 @@
"shrink world border of world \"world\" to 100 in 10 seconds"
})
@Since("2.11")
public class EffWorldBorderExpand extends Effect implements SyntaxRuntimeErrorProducer {
public class EffWorldBorderExpand extends Effect {

static {
Skript.registerEffect(EffWorldBorderExpand.class,
Expand All @@ -48,7 +47,6 @@ public class EffWorldBorderExpand extends Effect implements SyntaxRuntimeErrorPr
private Expression<Number> numberExpr;
private @Nullable Expression<Timespan> timespan;
private static final double MAX_WORLDBORDER_SIZE = 59999968;
private Node node;

@Override
@SuppressWarnings("unchecked")
Expand All @@ -59,7 +57,6 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
shrink = matchedPattern > 1;
radius = parseResult.hasTag("radius");
to = parseResult.hasTag("to");
node = getParser().getNode();
return true;
}

Expand Down Expand Up @@ -97,11 +94,6 @@ protected void execute(Event event) {
}
}

@Override
public Node getNode() {
return node;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import org.bukkit.WorldBorder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;

@Name("Center of World Border")
@Description("The center of a world border.")
@Examples("set world border center of {_worldborder} to location(10, 0, 20)")
@Since("2.11")
public class ExprWorldBorderCenter extends SimplePropertyExpression<WorldBorder, Location> implements SyntaxRuntimeErrorProducer {
public class ExprWorldBorderCenter extends SimplePropertyExpression<WorldBorder, Location> {

static {
registerDefault(ExprWorldBorderCenter.class, Location.class, "world[ ]border (center|middle)", "worldborders");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.bukkit.WorldBorder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;

@Name("Damage Amount of World Border")
@Description({
Expand All @@ -19,7 +18,7 @@
})
@Examples("set world border damage amount of {_worldborder} to 1")
@Since("2.11")
public class ExprWorldBorderDamageAmount extends SimplePropertyExpression<WorldBorder, Double> implements SyntaxRuntimeErrorProducer {
public class ExprWorldBorderDamageAmount extends SimplePropertyExpression<WorldBorder, Double> {

static {
registerDefault(ExprWorldBorderDamageAmount.class, Double.class, "world[ ]border damage amount", "worldborders");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public final boolean init(Expression<?>[] expressions, int matchedPattern, Kleen
return section.init(expressions, matchedPattern, isDelayed, parseResult);
}

/**
* Get if this {@link SectionExpression} can only be used as a {@link Section}.
*/
public boolean isSectionOnly() {
return false;
}

/**
* @return A dummy trigger item representing the section belonging to this
*/
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/ch/njol/skript/lang/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.config.Node;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.condition.Conditional;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.util.Priority;

Expand All @@ -20,7 +22,7 @@
*
* @see Skript#registerCondition(Class, String...)
*/
public abstract class Condition extends Statement implements Conditional<Event> {
public abstract class Condition extends Statement implements Conditional<Event>, SyntaxRuntimeErrorProducer {

public enum ConditionType {
/**
Expand Down Expand Up @@ -62,6 +64,14 @@ public Priority priority() {

protected Condition() {}

private Node node;

@Override
public boolean preInit() {
node = getParser().getNode();
return super.preInit();
}

/**
* Checks whether this condition is satisfied with the given event. This should not alter the event or the world in any way, as conditions are only checked until one returns
* false. All subsequent conditions of the same trigger will then be omitted.<br/>
Expand Down Expand Up @@ -97,6 +107,11 @@ public final boolean isNegated() {
return negated;
}

@Override
public Node getNode() {
return node;
}

@Override
public @NotNull String getSyntaxTypeName() {
return "condition";
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/ch/njol/skript/lang/Effect.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ch.njol.skript.lang;

import ch.njol.skript.Skript;
import ch.njol.skript.config.Node;
import ch.njol.skript.lang.function.EffFunctionCall;
import ch.njol.skript.log.ParseLogHandler;
import ch.njol.skript.log.SkriptLogger;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;

import java.util.Iterator;

Expand All @@ -16,10 +18,18 @@
*
* @see Skript#registerEffect(Class, String...)
*/
public abstract class Effect extends Statement {
public abstract class Effect extends Statement implements SyntaxRuntimeErrorProducer {

protected Effect() {}

private Node node;

@Override
public boolean preInit() {
node = getParser().getNode();
return super.preInit();
}

/**
* Executes this effect.
*
Expand Down Expand Up @@ -64,6 +74,11 @@ public final boolean run(Event event) {
}
}

@Override
public Node getNode() {
return node;
}

@Override
public @NotNull String getSyntaxTypeName() {
return "effect";
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/ch/njol/skript/lang/ExpressionSection.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ch.njol.skript.lang;

import ch.njol.skript.Skript;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.expressions.base.SectionExpression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -30,8 +32,13 @@ public ExpressionSection(SectionExpression<?> expression) {
}

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
SectionContext context = getParser().getData(SectionContext.class);
assert context != null;
if (context.sectionNode == null && expression.isSectionOnly()) {
Skript.error("This expression requires a section.");
return false;
}
return this.init(expressions, matchedPattern, isDelayed, parseResult, context.sectionNode, context.triggerItems)
&& context.claim(expression);
}
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/ch/njol/skript/lang/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.parser.ParserInstance;
Expand All @@ -10,6 +11,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -40,7 +42,15 @@
*
* @see Skript#registerSection(Class, String...)
*/
public abstract class Section extends TriggerSection implements SyntaxElement {
public abstract class Section extends TriggerSection implements SyntaxElement, SyntaxRuntimeErrorProducer {

private Node node;

@Override
public boolean preInit() {
node = getParser().getNode();
return SyntaxElement.super.preInit();
}

/**
* This method should not be overridden unless you know what you are doing!
Expand Down Expand Up @@ -246,6 +256,11 @@ public boolean claimed() {

}

@Override
public Node getNode() {
return node;
}

@Override
public @NotNull String getSyntaxTypeName() {
return "section";
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ch/njol/skript/test/runner/ExprSecRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.Trigger;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.variables.Variables;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
Expand Down Expand Up @@ -46,10 +45,6 @@ public boolean init(Expression<?>[] expressions,
ParseResult result,
@Nullable SectionNode node,
@Nullable List<TriggerItem> triggerItems) {
if (node == null) {
Skript.error("Runnable expression needs a section!");
return false;
}
loadCode(node);
return true;
}
Expand All @@ -66,6 +61,11 @@ public boolean isSingle() {
return true;
}

@Override
public boolean isSectionOnly() {
return true;
}

@Override
public Class<?> getReturnType() {
return Runnable.class;
Expand Down