Skip to content

Commit 272078c

Browse files
committed
preloading, see docs (advanced > experiments)
remove bugs add bugs
1 parent a45b0f7 commit 272078c

38 files changed

+828
-371
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
run: ./gradlew build
2323
- uses: actions/upload-artifact@master
2424
with:
25-
path: build/libs/skript-reflect-2.1.0.jar
25+
path: build/libs/skript-reflect-2.2-alpha1.jar

build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import org.apache.tools.ant.filters.ReplaceTokens
22

33
group 'com.btk5h.skript-mirror'
4-
version '2.1.0'
4+
version '2.2-alpha1'
55

66
apply plugin: 'java'
77

8-
sourceCompatibility = 1.8
9-
108
repositories {
119
mavenCentral()
1210
maven {

docs/advanced/experiments.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,21 @@ Deferred parsing allows you to prefix any line with `(parse[d] later)` to defer
2626
This should only be used when two custom syntaxes refer to each other. Other issues should be resolved by reordering custom syntax definitions and ensuring that libraries containing custom syntax load before other scripts.
2727
{% endhint %}
2828

29+
30+
## Preloading
31+
When preloading is enabled in `config.yml`, custom syntax will be available from any scripts, independent of file names.
32+
Preloading is only available from Skript 2.5-alpha6+, using skript-reflect 2.2-alpha1 or above.
33+
34+
There is one case for which custom syntax can't be preloaded, that is when it has a `parse` section. `parse` sections
35+
can't be used in preloadable syntax, so to still allow for custom syntax to run code when being parsed, there are the
36+
`safe parse` sections. These sections have the same purpose as normal `parse` sections, with a few differences:
37+
- In safe parse sections
38+
- Functions can't be used.
39+
- Options (including computed options) can't be used.
40+
- Some imports can't be used (if they contain options for example).
41+
42+
Because of these differences, custom syntax with `safe parse` sections are preloadable.
43+
44+
{% hint style="warning" %}
45+
Be careful when using custom syntax in `on script load` events, as the custom syntax might not have been fully parsed yet.
46+
{% endhint %}

docs/basics/reading-javadocs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Most public APIs and libraries offer documentation in the form of Javadocs. Javadocs outline what features of a library are publicly accessible to developers.
44

55
Here are a few links to some commonly referenced Javadocs:
6-
[Java SE 8 Javadocs](https://docs.oracle.com/javase/8/docs/api/overview-summary.html)
7-
[Spigot Javadocs]https://hub.spigotmc.org/javadocs/spigot/overview-summary.html)
6+
[Java SE 8 Javadocs](https://docs.oracle.com/javase/8/docs/api/overview-summary.html), [Spigot Javadocs](https://hub.spigotmc.org/javadocs/spigot/overview-summary.html)
87

98
## Fully qualified names
109

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
import ch.njol.skript.Skript;
44
import ch.njol.skript.effects.EffReturn;
5+
import ch.njol.skript.lang.ExpressionInfo;
56
import ch.njol.skript.lang.SyntaxElement;
67
import ch.njol.skript.lang.SyntaxElementInfo;
78
import com.btk5h.skriptmirror.skript.EffExpressionStatement;
9+
import com.btk5h.skriptmirror.skript.custom.ExprMatchedPattern;
810
import com.btk5h.skriptmirror.skript.custom.condition.CustomCondition;
911
import com.btk5h.skriptmirror.skript.custom.effect.CustomEffect;
12+
import com.btk5h.skriptmirror.skript.custom.expression.CustomExpression;
13+
import com.btk5h.skriptmirror.util.SkriptReflection;
1014

1115
import java.util.Arrays;
1216
import java.util.Collection;
17+
import java.util.List;
1318
import java.util.Optional;
1419

1520
/**
@@ -20,13 +25,18 @@
2025
* guarantee that another addon's syntax will be parsed before skript-reflect.
2126
*/
2227
public class ParseOrderWorkarounds {
23-
private static String[] PARSE_ORDER = {
28+
private static final String[] PARSE_ORDER = {
2429
EffExpressionStatement.class.getCanonicalName(),
2530
CustomEffect.class.getCanonicalName(),
2631
CustomCondition.class.getCanonicalName(),
32+
CustomExpression.class.getCanonicalName(),
2733
"com.w00tmast3r.skquery.elements.conditions.CondBoolean",
2834
"com.pie.tlatoani.Miscellaneous.CondBoolean",
29-
EffReturn.class.getCanonicalName()
35+
"us.tlatoani.tablisknu.core.base.CondBoolean",
36+
"com.pie.tlatoani.CustomEvent.EvtCustomEvent",
37+
EffReturn.class.getCanonicalName(),
38+
ExprMatchedPattern.class.getCanonicalName(),
39+
"ch.njol.skript.effects.EffContinue"
3040
};
3141

3242
public static void reorderSyntax() {
@@ -35,6 +45,7 @@ public static void reorderSyntax() {
3545
ensureLast(Skript.getStatements(), c);
3646
ensureLast(Skript.getConditions(), c);
3747
ensureLast(Skript.getEffects(), c);
48+
ensureLastExpression(c);
3849
});
3950
}
4051

@@ -49,4 +60,20 @@ private static <E extends SyntaxElement> void ensureLast(Collection<SyntaxElemen
4960
elements.add(elementInfo);
5061
});
5162
}
63+
64+
private static void ensureLastExpression(String element) {
65+
List<ExpressionInfo<?, ?>> elements = SkriptReflection.getExpressions();
66+
if (elements == null)
67+
return;
68+
69+
Optional<ExpressionInfo<?, ?>> optionalExpressionInfo = elements.stream()
70+
.filter(info -> info.c.getName().equals(element))
71+
.findFirst();
72+
73+
optionalExpressionInfo.ifPresent(elementInfo -> {
74+
elements.remove(elementInfo);
75+
elements.add(elementInfo);
76+
});
77+
}
78+
5279
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
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;
75
import com.btk5h.skriptmirror.util.SkriptReflection;
86
import org.bukkit.plugin.java.JavaPlugin;
97

108
import java.io.IOException;
11-
import java.lang.reflect.Field;
129
import java.nio.file.Path;
1310

1411
public class SkriptMirror extends JavaPlugin {
@@ -25,25 +22,26 @@ public SkriptMirror() {
2522

2623
@Override
2724
public void onEnable() {
25+
saveDefaultConfig();
26+
2827
try {
2928
getAddonInstance().loadClasses("com.btk5h.skriptmirror.skript");
3029

3130
Path dataFolder = SkriptMirror.getInstance().getDataFolder().toPath();
3231
LibraryLoader.loadLibraries(dataFolder);
33-
34-
ParseOrderWorkarounds.reorderSyntax();
35-
36-
// Disable *all* and/or warnings
37-
SkriptReflection.disableAndOrWarnings();
3832
} catch (IOException e) {
3933
e.printStackTrace();
4034
}
35+
36+
ParseOrderWorkarounds.reorderSyntax();
37+
38+
// Disable *all* and/or warnings
39+
SkriptReflection.disableAndOrWarnings();
4140
}
4241

4342
public static SkriptAddon getAddonInstance() {
4443
if (addonInstance == null) {
45-
addonInstance = Skript.registerAddon(getInstance())
46-
.setLanguageFileDirectory("lang");
44+
addonInstance = Skript.registerAddon(getInstance()).setLanguageFileDirectory("lang");
4745
}
4846
return addonInstance;
4947
}
@@ -54,4 +52,5 @@ public static SkriptMirror getInstance() {
5452
}
5553
return instance;
5654
}
55+
5756
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected void execute(Event e) {
3737
@Override
3838
protected TriggerItem walk(Event e) {
3939
if (isAsynchronous) {
40+
// TODO how to implement async, Bukkit or just other Java (CondExpressionStatement#walk(Event))
4041
Object localVariables = SkriptReflection.getLocals(e);
4142
CompletableFuture.runAsync(() -> {
4243
SkriptReflection.putLocals(localVariables, e);

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

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

3-
import org.bukkit.event.Event;
4-
5-
import java.util.Arrays;
6-
73
import ch.njol.skript.classes.Changer;
84
import ch.njol.skript.expressions.base.PropertyExpression;
95
import ch.njol.skript.lang.Expression;
106
import ch.njol.skript.lang.SkriptParser;
117
import ch.njol.skript.lang.util.SimpleExpression;
128
import ch.njol.util.Kleenean;
9+
import org.bukkit.event.Event;
10+
11+
import java.util.Arrays;
1312

1413
public class ExprBits extends SimpleExpression<Number> {
1514
static {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import ch.njol.skript.registrations.Classes;
99
import ch.njol.skript.registrations.Converters;
1010
import ch.njol.yggdrasil.Fields;
11-
import com.btk5h.skriptmirror.*;
11+
import com.btk5h.skriptmirror.JavaType;
12+
import com.btk5h.skriptmirror.LibraryLoader;
13+
import com.btk5h.skriptmirror.Null;
14+
import com.btk5h.skriptmirror.ObjectWrapper;
1215
import com.btk5h.skriptmirror.skript.custom.CustomImport;
1316
import com.btk5h.skriptmirror.skript.reflect.sections.Section;
1417
import com.btk5h.skriptmirror.util.SkriptUtil;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.btk5h.skriptmirror.skript.custom;
2+
3+
public interface Continuable {
4+
5+
void markContinue();
6+
7+
}

0 commit comments

Comments
 (0)