-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Script type. * Support script string/name conversion. * Script expression. * Add script lang entry. * Tests for script expression & names. * Support all scripts expression. * Script effects & tests. * Create dummy Script handle for disabled scripts. * Script reflection feature flag. * Restrict literal parsing to commands & parse. * Test feature flag for resolving name. * Split ExprScripts by feature to support disabled scripts. * Fix ExprName tests for new & old behaviour. * Add tests for disabled script handles. * Apply suggestions from code review Co-authored-by: Patrick Miller <[email protected]> * Improve script loading/unloading safety. * Add feature check for script hotswapping. * Use expression stream. * Conformity for file names and proper loading safety. * Document validity & add condition support. * Add script is loaded condition + tests. * Dynamic function calling + tests. * Add language entry for types. * Single-encounter input bootstrapping. * Apply suggestions from code review Co-authored-by: sovdee <[email protected]> * Fix inspection. * Update src/main/java/ch/njol/skript/expressions/ExprFunction.java Co-authored-by: sovdee <[email protected]> * Update src/main/java/ch/njol/skript/expressions/ExprResult.java Co-authored-by: sovdee <[email protected]> * Changes from review. * Fix merge problems. * Remove script command method usage. * Fix branch muck. * Fix more branch muck. * Fix up ExprName. * Add docs. * Add docs. * Add docs. * Fix bits. * Apply suggestions from code review Co-authored-by: Patrick Miller <[email protected]> * Fix some bits. * Function parsing by name. * Fix up some bits for Walrus. * Fix merge error. --------- Co-authored-by: Patrick Miller <[email protected]> Co-authored-by: sovdee <[email protected]>
- Loading branch information
1 parent
9acc08a
commit 1235d8d
Showing
21 changed files
with
991 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package ch.njol.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionList; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.function.DynamicFunctionReference; | ||
import ch.njol.skript.registrations.Feature; | ||
import ch.njol.skript.util.LiteralUtils; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.skriptlang.skript.util.Executable; | ||
|
||
@Name("Run (Experimental)") | ||
@Description("Executes a task (a function). Any returned result is discarded.") | ||
@Examples({ | ||
"set {_function} to the function named \"myFunction\"", | ||
"run {_function}", | ||
"run {_function} with arguments {_things::*}", | ||
}) | ||
@Since("INSERT VERSION") | ||
@Keywords({"run", "execute", "reflection", "function"}) | ||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
public class EffRun extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffRun.class, | ||
"run %executable% [arguments:with arg[ument]s %-objects%]", | ||
"execute %executable% [arguments:with arg[ument]s %-objects%]"); | ||
} | ||
|
||
// We don't bother with the generic type here because we have no way to verify it | ||
// from the expression, and it makes casting more difficult to no benefit. | ||
private Expression<Executable> executable; | ||
private Expression<?> arguments; | ||
private DynamicFunctionReference.Input input; | ||
private boolean hasArguments; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int pattern, Kleenean isDelayed, ParseResult result) { | ||
if (!this.getParser().hasExperiment(Feature.SCRIPT_REFLECTION)) | ||
return false; | ||
this.executable = ((Expression<Executable>) expressions[0]); | ||
this.hasArguments = result.hasTag("arguments"); | ||
if (hasArguments) { | ||
this.arguments = LiteralUtils.defendExpression(expressions[1]); | ||
Expression<?>[] arguments; | ||
if (this.arguments instanceof ExpressionList<?>) { | ||
arguments = ((ExpressionList<?>) this.arguments).getExpressions(); | ||
} else { | ||
arguments = new Expression[]{this.arguments}; | ||
} | ||
this.input = new DynamicFunctionReference.Input(arguments); | ||
return LiteralUtils.canInitSafely(this.arguments); | ||
} else { | ||
this.input = new DynamicFunctionReference.Input(); | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
Executable task = executable.getSingle(event); | ||
if (task == null) | ||
return; | ||
Object[] arguments; | ||
if (task instanceof DynamicFunctionReference<?> reference) { | ||
Expression<?> validated = reference.validate(input); | ||
if (validated == null) | ||
return; | ||
arguments = validated.getArray(event); | ||
} else if (hasArguments) { | ||
arguments = this.arguments.getArray(event); | ||
} else { | ||
arguments = new Object[0]; | ||
} | ||
task.execute(event, arguments); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
if (hasArguments) | ||
return "run " + executable.toString(event, debug) + " with arguments " + arguments.toString(event, debug); | ||
return "run " + executable.toString(event, debug); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.