From b75df87c1267134c19a78ad5c08cab063d8dad03 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:33:26 -0700 Subject: [PATCH 1/5] fallback for getEventClasses before init and bump version --- build.gradle | 2 +- .../reflect/java/elements/events/EvtByReflection.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index beab3d3..14a9a0d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ import org.apache.tools.ant.filters.ReplaceTokens group 'com.btk5h.skript-mirror' -version '2.4' +version '2.5' apply plugin: 'java' diff --git a/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java b/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java index 1b55513..10c4d9f 100644 --- a/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java +++ b/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java @@ -132,6 +132,9 @@ public Class[] getEventClasses() { boolean hasUncancellable = false; boolean hasCancellable = false; + if (classes == null) + return new Class[]{BukkitEvent.class}; + for (Class eventClass : classes) { if (Cancellable.class.isAssignableFrom(eventClass)) { hasCancellable = true; From d1a3d6380161e850ef9f5485321282f2ec94769e Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:16:09 -0700 Subject: [PATCH 2/5] require 2.9, add support for new listening behavior api --- build.gradle | 2 +- .../java/elements/events/EvtByReflection.java | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 14a9a0d..2181a76 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,6 @@ compileJava { dependencies { implementation 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT' - implementation 'com.github.SkriptLang:Skript:2.8.0' + implementation 'com.github.SkriptLang:Skript:2.9.0' implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0' } diff --git a/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java b/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java index 10c4d9f..7e5ef29 100644 --- a/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java +++ b/src/main/java/org/skriptlang/reflect/java/elements/events/EvtByReflection.java @@ -3,7 +3,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.Trigger; import com.btk5h.skriptmirror.JavaType; import com.btk5h.skriptmirror.SkriptMirror; @@ -22,21 +22,32 @@ public class EvtByReflection extends SkriptEvent { static { - Skript.registerEvent("*reflection", EvtByReflection.class, BukkitEvent.class, "[1:all] %javatypes%"); + Skript.registerEvent("*reflection", EvtByReflection.class, BukkitEvent.class, "%javatypes%"); } private static class MyEventExecutor implements EventExecutor { private final Class eventClass; + private final ListeningBehavior listeningBehavior; private final Trigger trigger; public MyEventExecutor(Class eventClass, Trigger trigger) { this.eventClass = eventClass; + this.listeningBehavior = ListeningBehavior.UNCANCELLED; + this.trigger = trigger; + } + + public MyEventExecutor(Class eventClass, ListeningBehavior listeningBehavior, Trigger trigger) { + this.eventClass = eventClass; + this.listeningBehavior = listeningBehavior; this.trigger = trigger; } @Override public void execute(Listener listener, Event event) throws EventException { if (eventClass.isInstance(event)) { + if (event instanceof Cancellable && !listeningBehavior.matches(((Cancellable) event).isCancelled())) + return; + Event scriptEvent; scriptEvent = event instanceof Cancellable ? new CancellableBukkitEvent((Cancellable) event) : new BukkitEvent(event); @@ -77,12 +88,11 @@ public void setCancelled(boolean cancel) { } private Class[] classes; - private boolean ignoreCancelled; private Listener listener; @SuppressWarnings("unchecked") @Override - public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { JavaType[] javaTypes = ((Literal) args[0]).getArray(); classes = new Class[javaTypes.length]; @@ -99,8 +109,6 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes classes[i] = (Class) clazz; } - ignoreCancelled = (parseResult.mark & 1) != 1; - listener = new Listener() {}; return true; @@ -114,10 +122,10 @@ public boolean check(Event event) { @Override public boolean postLoad() { for (Class eventClass : classes) { - EventExecutor executor = new MyEventExecutor(eventClass, trigger); + EventExecutor executor = new MyEventExecutor(eventClass, listeningBehavior, trigger); Bukkit.getPluginManager() - .registerEvent(eventClass, listener, getEventPriority(), executor, SkriptMirror.getInstance(), ignoreCancelled); + .registerEvent(eventClass, listener, getEventPriority(), executor, SkriptMirror.getInstance(), listeningBehavior == ListeningBehavior.UNCANCELLED); } return true; } @@ -126,6 +134,11 @@ public void unload() { HandlerList.unregisterAll(listener); } + @Override + public boolean isListeningBehaviorSupported() { + return true; + } + @SuppressWarnings("unchecked") @Override public Class[] getEventClasses() { @@ -154,8 +167,7 @@ public Class[] getEventClasses() { @Override public String toString(Event e, boolean debug) { - return (ignoreCancelled ? "all " : "") - + Arrays.stream(classes) + return Arrays.stream(classes) .map(Class::getSimpleName) .collect(Collectors.joining(", ")); } From 075ca2e65d056a8baf499bf31b7bf3e925cd515a Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:19:20 -0700 Subject: [PATCH 3/5] bump java to 11 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 2181a76..2181686 100644 --- a/build.gradle +++ b/build.gradle @@ -28,8 +28,8 @@ processResources { } compileJava { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility = '1.11' + targetCompatibility = '1.11' options.encoding = 'UTF-8' } From 94938dd61d29160f7e8fe16a900d91a27802b24b Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:20:37 -0700 Subject: [PATCH 4/5] i'm dumb --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 2181686..24fbdd4 100644 --- a/build.gradle +++ b/build.gradle @@ -28,8 +28,8 @@ processResources { } compileJava { - sourceCompatibility = '1.11' - targetCompatibility = '1.11' + sourceCompatibility = '11' + targetCompatibility = '11' options.encoding = 'UTF-8' } From 442c76575ee022d268918fd54b3eaf28d7515d06 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:24:41 -0700 Subject: [PATCH 5/5] Update gradle.yml --- .github/workflows/gradle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f99335b..73012e9 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle