Skip to content

Commit 3cc1a60

Browse files
committed
A lot of stuff, should've worked on one thing at a time.
Fixed: #21 #19 #7 btk5h/skript-mirror#122 (the warning, but that was the only thing wrong with it) btk5h/skript-mirror#154 (partly, see #22) Added: warnings for using features that require consent when no consent is given cancellability for custom events (see https://skript-mirror-tp.gitbook.io/skript-mirror-tp/advanced/custom-syntax/events#calling-the-event)
1 parent 6fe0ca6 commit 3cc1a60

26 files changed

+596
-104
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# skript-mirror(-tp)
1+
# skript-mirror-tp
22

33
This fork of [skript-mirror](https://github.com/btk5h/skript-mirror) aims to fix multiple issues that I believe have been present for too long, and implement some long-wanted features.
44

docs/advanced/custom-syntax/events.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,24 @@ If this section is included, you must also [`continue`](./#continue) if you want
8787

8888
### Calling the event
8989

90-
{% code-tabs %}
91-
{% code-tabs-item title="Syntax" %}
90+
You can get an instance of a custom event using the following expression:
9291
```text
93-
call custom event %string% [(with|using) [[event-]values] %-objects%] [[and] [(with|using)] data %-objects%]
92+
[a] [new] custom event %string% [(with|using) [[event-]values] %-objects%] [[and] [(with|using)] data %-objects%]
9493
```
95-
{% endcode-tabs-item %}
96-
{% endcode-tabs %}
97-
9894
The first argument should contain the name of the event you want to call. The second argument is a list variable, with each element of the following format: `{list::%type%} = %value%`. The third argument is almost the same, the only difference is that `%type%` is replaced with a string, which is just the index.
9995
The first list variable is for [the event-values](#option-event-values), while the second is for [the extra data](#extra-data).
10096

97+
You can then call it using the following effect:
98+
```text
99+
call [event] %events%
100+
```
101+
102+
If you want to check if an event has been cancelled, after you've called it, you can use the following condition:
103+
```text
104+
%events% (is|are) cancelled
105+
%events% (isn't|is not|aren't|are not) cancelled
106+
```
107+
101108
### Extra data
102109

103110
If the event-values aren't enough for your desire, you can make use of the extra data feature.

src/main/java/com/btk5h/skriptmirror/FunctionWrapper.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
package com.btk5h.skriptmirror;
22

3-
import ch.njol.skript.Skript;
4-
import ch.njol.skript.lang.function.*;
5-
import ch.njol.skript.registrations.Classes;
3+
import ch.njol.skript.lang.function.Function;
4+
import ch.njol.skript.lang.function.Functions;
65
import org.eclipse.jdt.annotation.Nullable;
76

87
public class FunctionWrapper {
98

10-
private static final Function<?> NO_OP_FUNCTION = new JavaFunction<Object>("$noop", new Parameter[0],
11-
Classes.getExactClassInfo(Object.class), true) {
12-
@Nullable
13-
@Override
14-
public Object[] execute(FunctionEvent e, Object[][] params) {
15-
return null;
16-
}
17-
};
18-
199
private final String name;
2010
private final Object[] arguments;
2111

@@ -32,13 +22,9 @@ public Object[] getArguments() {
3222
return arguments;
3323
}
3424

25+
@Nullable
3526
public Function<?> getFunction() {
36-
Function<?> function = Functions.getFunction(name);
37-
if (function == null) {
38-
Skript.warning(String.format("The function '%s' could not be resolved.", name));
39-
return NO_OP_FUNCTION;
40-
}
41-
return function;
27+
return Functions.getFunction(name);
4228
}
4329

4430
}

src/main/java/com/btk5h/skriptmirror/SkriptMirror.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import ch.njol.skript.Skript;
44
import ch.njol.skript.SkriptAddon;
5+
import ch.njol.skript.SkriptConfig;
6+
import ch.njol.skript.config.Option;
57
import org.bukkit.plugin.java.JavaPlugin;
68

79
import java.io.IOException;
10+
import java.lang.reflect.Field;
811
import java.nio.file.Path;
912

1013
public class SkriptMirror extends JavaPlugin {
@@ -28,6 +31,18 @@ public void onEnable() {
2831
LibraryLoader.loadLibraries(dataFolder);
2932

3033
ParseOrderWorkarounds.reorderSyntax();
34+
35+
// Disable *all* and/or warnings
36+
Option<Boolean> option = SkriptConfig.disableMissingAndOrWarnings;
37+
if (!option.value()) {
38+
try {
39+
Field field = Option.class.getDeclaredField("parsedValue");
40+
field.setAccessible(true);
41+
field.set(option, true);
42+
} catch (NoSuchFieldException | IllegalAccessException e) {
43+
e.printStackTrace();
44+
}
45+
}
3146
} catch (IOException e) {
3247
e.printStackTrace();
3348
}

src/main/java/com/btk5h/skriptmirror/skript/CondExpressionStatement.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.btk5h.skriptmirror.skript;
22

3+
import ch.njol.skript.ScriptLoader;
34
import ch.njol.skript.Skript;
45
import ch.njol.skript.config.SectionNode;
56
import ch.njol.skript.lang.Condition;
67
import ch.njol.skript.lang.Expression;
78
import ch.njol.skript.lang.SkriptParser;
89
import ch.njol.skript.lang.TriggerItem;
910
import ch.njol.skript.log.SkriptLogger;
10-
import ch.njol.skript.variables.Variables;
1111
import ch.njol.util.Kleenean;
1212
import com.btk5h.skriptmirror.ObjectWrapper;
1313
import com.btk5h.skriptmirror.SkriptMirror;
@@ -48,15 +48,16 @@ private boolean isTruthy(Object o) {
4848
@Override
4949
protected TriggerItem walk(Event e) {
5050
if (isAsynchronous) {
51-
Object localVariables = Variables.removeLocals(e);
51+
Object localVariables = SkriptReflection.getLocals(e);
5252
CompletableFuture.runAsync(() -> {
5353
SkriptReflection.copyVariablesMapFromMap(localVariables, e);
5454
check(e);
5555
}, threadPool)
5656
.thenAccept(res -> Bukkit.getScheduler().runTask(SkriptMirror.getInstance(), () -> {
57-
if (getNext() != null) {
57+
if (getNext() != null)
5858
TriggerItem.walk(getNext(), e);
59-
}
59+
60+
SkriptReflection.removeLocals(e);
6061
}));
6162
return null;
6263
}
@@ -85,6 +86,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
8586
Skript.error("Asynchronous java calls may not be used as conditions.");
8687
return false;
8788
}
89+
if (isAsynchronous)
90+
ScriptLoader.hasDelayBefore = Kleenean.TRUE;
8891

8992
return SkriptUtil.canInitSafely(arg);
9093
}

src/main/java/com/btk5h/skriptmirror/skript/CondParseLater.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public String toString(Event e, boolean debug) {
5353
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
5454
SkriptParser.ParseResult parseResult) {
5555
if (!Consent.Feature.DEFERRED_PARSING.hasConsent(SkriptUtil.getCurrentScript())) {
56+
Skript.error("This feature requires consent, because it is experimental.");
5657
return false;
5758
}
5859

@@ -83,7 +84,7 @@ private Condition getParsedCondition() {
8384
scriptLoaderState.applyToCurrentState();
8485
parsedStatement = Condition.parse(statement,
8586
String.format("Could not parse condition at runtime: %s", statement));
86-
87+
8788
if (parsedStatement == null) {
8889
return null;
8990
}

src/main/java/com/btk5h/skriptmirror/skript/EffExpressionStatement.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.btk5h.skriptmirror.skript;
22

3+
import ch.njol.skript.ScriptLoader;
34
import ch.njol.skript.Skript;
45
import ch.njol.skript.lang.Effect;
56
import ch.njol.skript.lang.Expression;
67
import ch.njol.skript.lang.SkriptParser;
78
import ch.njol.skript.lang.TriggerItem;
8-
import ch.njol.skript.variables.Variables;
99
import ch.njol.util.Kleenean;
1010
import com.btk5h.skriptmirror.SkriptMirror;
1111
import com.btk5h.skriptmirror.skript.reflect.ExprJavaCall;
@@ -37,16 +37,17 @@ protected void execute(Event e) {
3737
@Override
3838
protected TriggerItem walk(Event e) {
3939
if (isAsynchronous) {
40-
Object localVariables = Variables.removeLocals(e);
40+
Object localVariables = SkriptReflection.getLocals(e);
4141
CompletableFuture.runAsync(() -> {
4242
SkriptReflection.copyVariablesMapFromMap(localVariables, e);
4343
execute(e);
4444
}, threadPool)
45-
.thenAccept(res -> Bukkit.getScheduler().runTask(SkriptMirror.getInstance(), () -> {
46-
if (getNext() != null) {
47-
TriggerItem.walk(getNext(), e);
48-
}
49-
}));
45+
.thenAccept(res -> Bukkit.getScheduler().runTask(SkriptMirror.getInstance(), () -> {
46+
if (getNext() != null)
47+
TriggerItem.walk(getNext(), e);
48+
49+
SkriptReflection.removeLocals(e);
50+
}));
5051
return null;
5152
}
5253
return super.walk(e);
@@ -67,6 +68,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
6768
}
6869

6970
isAsynchronous = (parseResult.mark & 1) == 1;
71+
if (isAsynchronous)
72+
ScriptLoader.hasDelayBefore = Kleenean.TRUE;
7073
return SkriptUtil.canInitSafely(arg);
7174
}
7275
}

src/main/java/com/btk5h/skriptmirror/skript/custom/CustomSyntaxSection.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.btk5h.skriptmirror.skript.custom;
22

33
import ch.njol.skript.Skript;
4-
import ch.njol.skript.config.EntryNode;
5-
import ch.njol.skript.config.Node;
6-
import ch.njol.skript.config.SectionNode;
4+
import ch.njol.skript.config.*;
75
import ch.njol.skript.lang.*;
86
import ch.njol.skript.log.SkriptLogger;
97
import com.btk5h.skriptmirror.util.SkriptReflection;
@@ -187,7 +185,7 @@ protected static boolean handleEntriesAndSections(SectionNode node,
187185
Predicate<SectionNode> sectionHandler) {
188186
boolean ok = true;
189187

190-
for (Node subNode : node) {
188+
for (Node subNode : SkriptReflection.getNodes(node)) {
191189
SkriptLogger.setNode(subNode);
192190

193191
if (subNode instanceof EntryNode) {
@@ -202,8 +200,8 @@ protected static boolean handleEntriesAndSections(SectionNode node,
202200
subNode.getKey()));
203201
ok = false;
204202
}
205-
} else {
206-
throw new IllegalStateException();
203+
} else if (subNode instanceof InvalidNode || !(subNode instanceof VoidNode )) {
204+
ok = false;
207205
}
208206

209207
SkriptLogger.setNode(null);

src/main/java/com/btk5h/skriptmirror/skript/custom/condition/CustomCondition.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import ch.njol.skript.Skript;
66
import ch.njol.skript.lang.*;
77
import ch.njol.skript.lang.util.SimpleLiteral;
8-
import ch.njol.skript.variables.Variables;
98
import ch.njol.util.Kleenean;
109
import com.btk5h.skriptmirror.skript.custom.SyntaxParseEvent;
1110
import com.btk5h.skriptmirror.util.SkriptReflection;
@@ -90,7 +89,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
9089
// Because of link below, Trigger#execute removes local variables
9190
// https://github.com/SkriptLang/Skript/commit/a6661c863bae65e96113b69bebeaab51d814e2b9
9291
TriggerItem.walk(parseHandler, event);
93-
variablesMap = Variables.removeLocals(event);
92+
variablesMap = SkriptReflection.removeLocals(event);
9493

9594
return event.isMarkedContinue();
9695
}

src/main/java/com/btk5h/skriptmirror/skript/custom/effect/CustomEffect.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ch.njol.skript.ScriptLoader;
44
import ch.njol.skript.Skript;
55
import ch.njol.skript.lang.*;
6-
import ch.njol.skript.variables.Variables;
76
import ch.njol.util.Kleenean;
87
import com.btk5h.skriptmirror.skript.custom.SyntaxParseEvent;
98
import com.btk5h.skriptmirror.util.SkriptReflection;
@@ -80,7 +79,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
8079
// Because of link below, Trigger#execute removes local variables
8180
// https://github.com/SkriptLang/Skript/commit/a6661c863bae65e96113b69bebeaab51d814e2b9
8281
TriggerItem.walk(parseHandler, event);
83-
variablesMap = Variables.removeLocals(event);
82+
variablesMap = SkriptReflection.removeLocals(event);
8483

8584
return event.isMarkedContinue();
8685
}

0 commit comments

Comments
 (0)