Skip to content

Commit e3a5a6b

Browse files
committed
revert EffWaitAsync
1 parent d417b96 commit e3a5a6b

3 files changed

Lines changed: 39 additions & 35 deletions

File tree

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package gg.projects.mundoskasync;
22

33
import ch.njol.skript.Skript;
4+
import ch.njol.skript.effects.Delay;
45
import ch.njol.skript.lang.Effect;
56
import ch.njol.skript.lang.Expression;
6-
import ch.njol.skript.lang.SkriptParser;
7+
import ch.njol.skript.lang.SkriptParser.ParseResult;
78
import ch.njol.skript.lang.TriggerItem;
9+
import ch.njol.skript.variables.Variables;
810
import ch.njol.util.Kleenean;
911
import org.bukkit.event.Event;
1012

@@ -17,8 +19,10 @@ public class EffSynchronicity extends Effect {
1719
private boolean isSync;
1820

1921
@Override
20-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
22+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
2123
isSync = matchedPattern == 1;
24+
25+
getParser().setHasDelayBefore(Kleenean.TRUE);
2226
return true;
2327
}
2428

@@ -27,23 +31,33 @@ protected void execute(Event e) { }
2731

2832
@Override
2933
public TriggerItem walk(Event e) {
30-
Runnable task = () -> {
34+
debug(e, true);
35+
36+
Object localVars = Variables.removeLocals(e);
37+
Delay.addDelayedEvent(e);
38+
39+
Runnable runnable = () -> {
40+
if (localVars != null)
41+
Variables.setLocalVariables(e, localVars);
42+
3143
TriggerItem next = getNext();
32-
if (next != null) {
33-
walk(next, e);
34-
}
44+
if (next != null)
45+
walk(getNext(), e);
46+
47+
Variables.removeLocals(e);
3548
};
3649

37-
if (isSync) {
38-
Scheduling.sync(task);
39-
} else {
40-
Scheduling.async(task);
41-
}
50+
if (isSync)
51+
Scheduling.sync(runnable);
52+
else
53+
Scheduling.async(runnable);
54+
4255
return null;
4356
}
4457

4558
@Override
4659
public String toString(Event e, boolean debug) {
4760
return isSync ? "sync" : "async";
4861
}
49-
}
62+
63+
}

src/main/java/gg/projects/mundoskasync/EffWaitAsync.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
import ch.njol.skript.util.Timespan;
1010
import ch.njol.skript.variables.Variables;
1111
import ch.njol.util.Kleenean;
12-
import org.bukkit.Bukkit;
1312
import org.bukkit.event.Event;
1413

15-
import java.util.logging.Level;
16-
1714
public class EffWaitAsync extends Effect {
1815

1916
static {
@@ -41,26 +38,19 @@ public TriggerItem walk(Event e) {
4138
Object localVars = Variables.removeLocals(e);
4239

4340
Timespan delay = this.delay.getSingle(e);
44-
if (delay == null) {
41+
if (delay == null)
4542
return null;
46-
}
4743

48-
Bukkit.getScheduler().runTaskLater(MundoSKAsync.getInstance(), () -> {
49-
try {
50-
if (localVars != null) {
51-
Variables.setLocalVariables(e, localVars);
52-
}
53-
TriggerItem next = getNext();
54-
if (next != null) {
55-
walk(next, e);
56-
}
57-
} catch (Exception ex) {
58-
MundoSKAsync.getInstance().getLogger().severe("Error in async wait continuation: " + ex.getMessage());
59-
} finally {
60-
Variables.removeLocals(e);
61-
}
62-
}, delay.getTicks_i());
44+
Scheduling.asyncDelay((int) delay.getTicks_i(), () -> {
45+
if (localVars != null)
46+
Variables.setLocalVariables(e, localVars);
47+
48+
TriggerItem next = getNext();
49+
if (next != null)
50+
walk(getNext(), e);
6351

52+
Variables.removeLocals(e);
53+
});
6454
return null;
6555
}
6656

src/main/java/gg/projects/mundoskasync/Scheduling.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.bukkit.Bukkit;
44
import org.bukkit.scheduler.BukkitScheduler;
55

6-
import java.util.logging.Level;
7-
86
public class Scheduling {
97

108
private static final BukkitScheduler scheduler = Bukkit.getScheduler();
@@ -14,6 +12,7 @@ public static void sync(Runnable runnable) {
1412
}
1513

1614
public static void async(Runnable runnable) {
15+
//scheduler.runTaskAsynchronously(MundoSKAsync.getInstance(), runnable);
1716
TaskExecutor.executeAsync(runnable);
1817
}
1918

@@ -24,4 +23,5 @@ public static void syncDelay(long ticks, Runnable runnable) {
2423
public static void asyncDelay(long ticks, Runnable runnable) {
2524
scheduler.runTaskLaterAsynchronously(MundoSKAsync.getInstance(), runnable, ticks);
2625
}
27-
}
26+
27+
}

0 commit comments

Comments
 (0)