Skip to content

Commit

Permalink
Merge pull request #116 from SkriptLang/feature/2.9
Browse files Browse the repository at this point in the history
2.9 support
  • Loading branch information
sovdeeth authored Jul 15, 2024
2 parents afa90a3 + 27b4488 commit 26facfa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -28,13 +28,13 @@ processResources {
}

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

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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<? extends Event> eventClass;
private final ListeningBehavior listeningBehavior;
private final Trigger trigger;

public MyEventExecutor(Class<? extends Event> eventClass, Trigger trigger) {
this.eventClass = eventClass;
this.listeningBehavior = ListeningBehavior.UNCANCELLED;
this.trigger = trigger;
}

public MyEventExecutor(Class<? extends Event> 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);
Expand Down Expand Up @@ -77,12 +88,11 @@ public void setCancelled(boolean cancel) {
}

private Class<? extends Event>[] 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<JavaType>) args[0]).getArray();

classes = new Class[javaTypes.length];
Expand All @@ -99,8 +109,6 @@ public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseRes
classes[i] = (Class<? extends Event>) clazz;
}

ignoreCancelled = (parseResult.mark & 1) != 1;

listener = new Listener() {};

return true;
Expand All @@ -114,10 +122,10 @@ public boolean check(Event event) {
@Override
public boolean postLoad() {
for (Class<? extends Event> 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;
}
Expand All @@ -126,12 +134,20 @@ public void unload() {
HandlerList.unregisterAll(listener);
}

@Override
public boolean isListeningBehaviorSupported() {
return true;
}

@SuppressWarnings("unchecked")
@Override
public Class<? extends Event>[] getEventClasses() {
boolean hasUncancellable = false;
boolean hasCancellable = false;

if (classes == null)
return new Class[]{BukkitEvent.class};

for (Class<? extends Event> eventClass : classes) {
if (Cancellable.class.isAssignableFrom(eventClass)) {
hasCancellable = true;
Expand All @@ -151,8 +167,7 @@ public Class<? extends Event>[] 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(", "));
}
Expand Down

0 comments on commit 26facfa

Please sign in to comment.