Skip to content

Commit

Permalink
Fix change being called without calling acceptChange in some cases (#123
Browse files Browse the repository at this point in the history
)

* Try to fix change problems of #122

* Try new approach for handling exceptional changes

---------

Co-authored-by: Pikachu920 <28607612+Pikachu920@users.noreply.github.com>
  • Loading branch information
Maple-YZ and Pikachu920 authored Dec 19, 2024
1 parent 226fdb7 commit b62ccaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;

Expand Down Expand Up @@ -56,13 +57,19 @@ public void change(Event event, Object[] delta, Changer.ChangeMode changeMode) {
return;
Expression<?> source = expr.getSource();

event = ((WrappedEvent) event).getDirectEvent();
source.change(event, delta, changeMode);
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;
}
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public String toString() {
}
}

static Throwable lastError;
public static Throwable lastError;

private final LRUCache<Descriptor, Collection<MethodHandle>> callSiteCache = new LRUCache<>(8);

Expand Down

0 comments on commit b62ccaa

Please sign in to comment.