Skip to content
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

Registration API Compatibility #130

Merged
merged 46 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
aa9422a
Add tests for import structure and effect
Pikachu920 Dec 31, 2024
0eea331
Try to fix EffImport in test mode
Pikachu920 Dec 31, 2024
56caf03
See if JavaType classinfo parser is working
Pikachu920 Dec 31, 2024
f900a67
See if JavaType classinfo parser is working
Pikachu920 Dec 31, 2024
b29abfd
Strip out ImportHandler
Pikachu920 Dec 31, 2024
1cf909f
Strip out more usages of ImportHandler
Pikachu920 Dec 31, 2024
6ccbdcb
Fix function argument type error in EffImport.sk
Pikachu920 Dec 31, 2024
b1f09ed
Attempt to fix EffImport.sk test
Pikachu920 Dec 31, 2024
c3532f5
Add custom expression tests
Pikachu920 Jan 1, 2025
ea072b8
Organize existing tests into folders
Pikachu920 Jan 1, 2025
53f7cdb
Fix indents in custom expressions.sk
Pikachu920 Jan 14, 2025
5536191
Try to fix test
Pikachu920 Jan 14, 2025
004d6a6
Try to fix test
Pikachu920 Jan 14, 2025
3557356
Try to fix custom expressions.sk
Pikachu920 Jan 14, 2025
e413aae
Simplify custom expressions.sk
Pikachu920 Jan 14, 2025
6a26889
Add tests for events, conditions, and effects
Pikachu920 Jan 14, 2025
9d2665e
Fix silly willy test errors 😇👸✨✨✨✨
Pikachu920 Jan 14, 2025
8c4938a
Fix even more silly willy test errors 😇👸✨✨✨✨✨✨
Pikachu920 Jan 14, 2025
5463b68
Fix test error in custom condition.sk
Pikachu920 Jan 14, 2025
1e20519
Fix test error in custom condition.sk
Pikachu920 Jan 14, 2025
c104853
Add tests for custom constants
Pikachu920 Jan 14, 2025
cf5de11
Fix test for custom constants
Pikachu920 Jan 14, 2025
6bd0dea
Switch custom syntax to new registration API
Pikachu920 Jan 14, 2025
2720fdd
Use Java 17 for test runner
Pikachu920 Jan 14, 2025
1606cb7
Make sure to re-register when updating the patterns
Pikachu920 Jan 14, 2025
9ec3526
Fix custom constants.sk
Pikachu920 Jan 14, 2025
e16944a
Register placeholder pattern for custom syntax
Pikachu920 Jan 14, 2025
0afd5dc
Use new registration API for ParseOrderWorkarounds
Pikachu920 Jan 14, 2025
235bccc
Update tracker with new info when updating patterns
Pikachu920 Jan 14, 2025
23cca06
Check for placeholder pattern at index 0, not 1
Pikachu920 Jan 14, 2025
4786fab
Hack together default pattern
APickledWalrus Jan 14, 2025
7ef3bfc
Fix a silly
APickledWalrus Jan 14, 2025
0c704a1
Ensure default is always present
APickledWalrus Jan 14, 2025
926a305
Reposition default pattern insertion
APickledWalrus Jan 14, 2025
98755a9
maybe this is causing issues
APickledWalrus Jan 14, 2025
6829c4f
Remove temporary test
APickledWalrus Jan 14, 2025
b710a4d
Use dev/feature for testing for now
APickledWalrus Jan 14, 2025
e867a7a
Update skript-test-action to patch/submodule-pull
Pikachu920 Jan 14, 2025
abe1158
Update skript-test-action to v1.2
Pikachu920 Jan 14, 2025
8f65faa
Fix importing for effect commands
APickledWalrus Jan 14, 2025
44205c2
Remove obsolete expression reflection
APickledWalrus Jan 14, 2025
7cc0fe2
Update to Java 17
APickledWalrus Jan 14, 2025
ad19651
Rework EffImport test
APickledWalrus Jan 14, 2025
5121728
Update to 2.10.0 full release
APickledWalrus Jan 16, 2025
c0031d8
Address review concerns
APickledWalrus Jan 17, 2025
6b6f306
Generics bruh moment
APickledWalrus Jan 17, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand All @@ -36,7 +36,7 @@ jobs:
path: extra-plugins/
merge-multiple: true
- name: Run tests
uses: SkriptLang/skript-test-action@v1.1
uses: SkriptLang/skript-test-action@v1.2
with:
test_script_directory: src/test/scripts
extra_plugins_directory: extra-plugins/
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ processResources {
}

compileJava {
sourceCompatibility = '11'
targetCompatibility = '11'
sourceCompatibility = '17'
targetCompatibility = '17'
options.encoding = 'UTF-8'
}

dependencies {
implementation 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
implementation 'com.github.SkriptLang:Skript:2.9.0'
implementation 'com.github.SkriptLang:Skript:2.10.0'
implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0'
}
50 changes: 39 additions & 11 deletions src/main/java/com/btk5h/skriptmirror/ParseOrderWorkarounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

import ch.njol.skript.Skript;
import ch.njol.skript.effects.EffReturn;
import ch.njol.util.Checker;
import org.skriptlang.reflect.syntax.CustomSyntaxStructure;
import org.skriptlang.reflect.syntax.condition.elements.CustomCondition;
import org.skriptlang.reflect.syntax.condition.elements.StructCustomCondition;
import org.skriptlang.reflect.syntax.effect.elements.CustomEffect;
import org.skriptlang.reflect.syntax.effect.elements.StructCustomEffect;
import org.skriptlang.reflect.syntax.expression.elements.CustomExpression;
import com.btk5h.skriptmirror.skript.EffExpressionStatement;
import com.btk5h.skriptmirror.skript.custom.ExprMatchedPattern;
import com.btk5h.skriptmirror.util.SkriptReflection;
import org.skriptlang.reflect.syntax.expression.elements.StructCustomExpression;
import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;
import org.skriptlang.skript.util.Priority;

import javax.naming.ServiceUnavailableException;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Predicate;

/**
* Explicitly declares the relative parse orders of different statement types. Classes at the start of the list should
Expand All @@ -20,7 +29,11 @@
* This class should only be used to guarantee that skript-mirror's syntax is parsed before other addons. It cannot
* guarantee that another addon's syntax will be parsed before skript-reflect.
*/
@SuppressWarnings("UnstableApiUsage")
public class ParseOrderWorkarounds {

private static final Priority POSITION = Priority.before(SyntaxInfo.PATTERN_MATCHES_EVERYTHING);

private static final String[] PARSE_ORDER = {
EffExpressionStatement.class.getCanonicalName(),
CustomEffect.class.getCanonicalName(),
Expand All @@ -38,22 +51,37 @@ public class ParseOrderWorkarounds {

public static void reorderSyntax() {
for (String c : PARSE_ORDER) {
ensureLast(Skript.getStatements(), o -> o.getElementClass().getName().equals(c));
ensureLast(Skript.getConditions(), o -> o.getElementClass().getName().equals(c));
ensureLast(Skript.getEffects(), o -> o.getElementClass().toString().equals(c));
ensureLast(SkriptReflection.getExpressions(), o -> o.getElementClass().getName().equals(c));
ensureLast(Skript.getEvents(), o -> o.getElementClass().getName().equals(c));
ensureLast(SyntaxRegistry.CONDITION, o -> o.type().getName().equals(c));
ensureLast(SyntaxRegistry.EFFECT, o -> o.type().getName().equals(c));
ensureLast(SyntaxRegistry.EXPRESSION, o -> o.type().getName().equals(c));
ensureLast(BukkitRegistryKeys.EVENT, o -> o.type().getName().equals(c));
ensureLast(SyntaxRegistry.STRUCTURE, o -> o.type().getName().equals(c));
}
}

private static <E> void ensureLast(Collection<E> elements, Checker<E> checker) {
Optional<E> optionalE = elements.stream()
.filter(checker::check)
private static <T> void ensureLast(SyntaxRegistry.Key<? extends SyntaxInfo<? extends T>> elementKey, Predicate<SyntaxInfo<? extends T>> checker) {
SyntaxRegistry syntaxRegistry = SkriptMirror.getAddonInstance().syntaxRegistry();
Optional<? extends SyntaxInfo<? extends T>> optionalE = syntaxRegistry.syntaxes(elementKey).stream()
.filter(checker)
.findFirst();

optionalE.ifPresent(value -> {
elements.remove(value);
elements.add(value);
syntaxRegistry.unregister((SyntaxRegistry.Key) elementKey, value);
var newInfo = value.toBuilder().priority(POSITION).build();
syntaxRegistry.register((SyntaxRegistry.Key) elementKey, newInfo);

// need to update custom syntax references
CustomSyntaxStructure.DataTracker<?> tracker = null;
if (elementKey == (SyntaxRegistry.Key) SyntaxRegistry.EFFECT) {
tracker = StructCustomEffect.dataTracker;
} else if (elementKey == (SyntaxRegistry.Key) SyntaxRegistry.CONDITION) {
tracker = StructCustomCondition.dataTracker;
} else if (elementKey == (SyntaxRegistry.Key) SyntaxRegistry.EXPRESSION) {
tracker = StructCustomExpression.dataTracker;
}
if (tracker != null && tracker.getInfo() == value) {
tracker.setInfo(newInfo);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.function.Predicate;

public class ExprArrayAccess<T> implements Expression<T> {

Expand Down Expand Up @@ -106,12 +107,12 @@ public boolean isSingle() {
}

@Override
public boolean check(Event e, Checker<? super T> c, boolean negated) {
public boolean check(Event e, Predicate<? super T> c, boolean negated) {
return SimpleExpression.check(getAll(e), c, negated, getAnd());
}

@Override
public boolean check(Event e, Checker<? super T> c) {
public boolean check(Event e, Predicate<? super T> c) {
return SimpleExpression.check(getAll(e), c, false, getAnd());
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/java/com/btk5h/skriptmirror/skript/ExprPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import com.btk5h.skriptmirror.JavaType;
Expand All @@ -22,15 +23,19 @@ public class ExprPlugin extends SimplePropertyExpression<Object, ObjectWrapper>

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
super.init(exprs, matchedPattern, isDelayed, parseResult);
if (!super.init(exprs, matchedPattern, isDelayed, parseResult)) {
return false;
}

if (exprs[0] instanceof StructImport.ImportHandler) {
JavaType javaType = ((StructImport.ImportHandler) exprs[0]).getJavaType();
Class<?> clazz = javaType.getJavaClass();
if (getExpr() instanceof Literal<?> literal) {
Object literalValue = literal.getSingle();
if (literalValue instanceof JavaType javaType) {
Class<?> clazz = javaType.getJavaClass();

if (!JavaPlugin.class.isAssignableFrom(clazz) || JavaPlugin.class.equals(clazz)) {
Skript.error("The class " + clazz.getSimpleName() + " is not a plugin class");
return false;
if (!JavaPlugin.class.isAssignableFrom(clazz) || JavaPlugin.class.equals(clazz)) {
Skript.error("The class " + clazz.getSimpleName() + " is not a plugin class");
return false;
}
}
}

Expand All @@ -39,8 +44,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
public ObjectWrapper convert(Object plugin) {
if (plugin instanceof String) {
String pluginName = (String) plugin;
if (plugin instanceof String pluginName) {
for (Plugin pluginInstance : Bukkit.getPluginManager().getPlugins()) {
if (pluginInstance.getName().equalsIgnoreCase(pluginName)) {
return ObjectWrapper.create(pluginInstance);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/btk5h/skriptmirror/skript/ExprSpread.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class ExprSpread<T> implements Expression<T> {
Expand Down Expand Up @@ -97,12 +98,12 @@ public boolean isSingle() {
}

@Override
public boolean check(Event e, Checker<? super T> c, boolean negated) {
public boolean check(Event e, Predicate<? super T> c, boolean negated) {
return SimpleExpression.check(getAll(e), c, negated, getAnd());
}

@Override
public boolean check(Event e, Checker<? super T> c) {
public boolean check(Event e, Predicate<? super T> c) {
return SimpleExpression.check(getAll(e), c, false, getAnd());
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/btk5h/skriptmirror/skript/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public JavaType parse(String s, ParseContext context) {

@Override
public boolean canParse(ParseContext context) {
// default context handled in StructImport$ImportHandler
return context != ParseContext.DEFAULT;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.skriptlang.skript.lang.converter.Converters;

import java.util.Iterator;
import java.util.function.Predicate;

public class ExprExpression<T> implements Expression<T> {
static {
Expand Down Expand Up @@ -123,12 +124,12 @@ public boolean isSingle() {
}

@Override
public boolean check(Event e, Checker<? super T> c, boolean negated) {
public boolean check(Event e, Predicate<? super T> c, boolean negated) {
return SimpleExpression.check(getAll(e), c, negated, getAnd());
}

@Override
public boolean check(Event e, Checker<? super T> c) {
public boolean check(Event e, Predicate<? super T> c) {
return SimpleExpression.check(getAll(e), c, false, getAnd());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class ExprRawExpression extends SimpleExpression<Expression> {
static {
Skript.registerExpression(ExprRawExpression.class, Expression.class, ExpressionType.COMBINED,
"[the] raw %objects%");
"[the] raw [expression] %objects%");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provides a means to workaround conflict with skript's raw expr

}

private Expression<?> expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionList;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.*;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.Utils;
Expand Down Expand Up @@ -49,6 +46,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -165,10 +163,11 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
}

if (staticDescriptor.getJavaClass() == null
&& rawTarget instanceof StructImport.ImportHandler) {
staticDescriptor = staticDescriptor.orDefaultClass(
((StructImport.ImportHandler) rawTarget).getJavaType().getJavaClass()
);
&& rawTarget instanceof Literal<?> literal) {
Object rawTargetValue = literal.getSingle();
if (rawTargetValue instanceof JavaType) {
staticDescriptor = staticDescriptor.orDefaultClass(((JavaType) rawTargetValue).getJavaClass());
}
}

if (staticDescriptor.getParameterTypes() != null && type.equals(CallType.FIELD)) {
Expand Down Expand Up @@ -253,12 +252,12 @@ public boolean isSingle() {
}

@Override
public boolean check(Event e, Checker<? super T> c, boolean negated) {
public boolean check(Event e, Predicate<? super T> c, boolean negated) {
return SimpleExpression.check(getAll(e), c, negated, getAnd());
}

@Override
public boolean check(Event e, Checker<? super T> c) {
public boolean check(Event e, Predicate<? super T> c) {
return SimpleExpression.check(getAll(e), c, false, getAnd());
}

Expand Down
Loading
Loading