From 78b12514bf0a7a01c927866d3663961e4895dfde Mon Sep 17 00:00:00 2001 From: Maple-YZ Date: Wed, 4 Sep 2024 13:22:52 +0800 Subject: [PATCH 1/2] Try to fix change problems of #122 --- .../btk5h/skriptmirror/skript/custom/ExprRawExpression.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java b/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java index a4560def..40896f20 100644 --- a/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java +++ b/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java @@ -5,6 +5,7 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.ConvertedExpression; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import com.btk5h.skriptmirror.WrappedEvent; @@ -56,6 +57,11 @@ public void change(Event event, Object[] delta, Changer.ChangeMode changeMode) { return; Expression source = expr.getSource(); + // !!! CAUTION: This is only a temporary fix and might cause other problems. + if (source instanceof ConvertedExpression) { + source.acceptChange(changeMode); + } + event = ((WrappedEvent) event).getDirectEvent(); source.change(event, delta, changeMode); } From d2c385d90520a2af8963a9c6fa9ddf5b7f216817 Mon Sep 17 00:00:00 2001 From: Pikachu920 <28607612+Pikachu920@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:35:58 -0600 Subject: [PATCH 2/2] Try new approach for handling exceptional changes --- .../skript/custom/ExprRawExpression.java | 17 +++++++++-------- .../skript/reflect/ExprJavaCall.java | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java b/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java index 40896f20..b55da9de 100644 --- a/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java +++ b/src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java @@ -5,10 +5,10 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser; -import ch.njol.skript.lang.util.ConvertedExpression; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import com.btk5h.skriptmirror.WrappedEvent; +import com.btk5h.skriptmirror.skript.reflect.ExprJavaCall; import com.btk5h.skriptmirror.util.SkriptUtil; import org.bukkit.event.Event; @@ -57,18 +57,19 @@ public void change(Event event, Object[] delta, Changer.ChangeMode changeMode) { return; Expression source = expr.getSource(); - // !!! CAUTION: This is only a temporary fix and might cause other problems. - if (source instanceof ConvertedExpression) { + Event unwrappedEvent = ((WrappedEvent) event).getDirectEvent(); + // Ensure acceptChange has been called before change + try { source.acceptChange(changeMode); + source.change(unwrappedEvent, delta, changeMode); + } catch (Throwable throwable) { + ExprJavaCall.lastError = throwable; } - - event = ((WrappedEvent) event).getDirectEvent(); - source.change(event, delta, changeMode); } @Override - public String toString(Event e, boolean debug) { - return "raw " + expr.toString(e, debug); + public String toString(Event event, boolean debug) { + return "raw " + expr.toString(event, debug); } @Override diff --git a/src/main/java/com/btk5h/skriptmirror/skript/reflect/ExprJavaCall.java b/src/main/java/com/btk5h/skriptmirror/skript/reflect/ExprJavaCall.java index 6a9d7eea..bf52619c 100644 --- a/src/main/java/com/btk5h/skriptmirror/skript/reflect/ExprJavaCall.java +++ b/src/main/java/com/btk5h/skriptmirror/skript/reflect/ExprJavaCall.java @@ -87,7 +87,7 @@ public String toString() { } } - static Throwable lastError; + public static Throwable lastError; private final LRUCache> callSiteCache = new LRUCache<>(8);