SkriptLang / skript-reflect

Powerful reflection utilities for Skript.
MIT License
56 stars 19 forks source link

Parse section is broken in custom event #88

Open Lotzyprod opened 3 months ago

Lotzyprod commented 3 months ago

Describe the bug You can't do anything in parse section. Variables isn't saved to use it in check section, you cant get literals and e.t.c

To reproduce

event "custom_event":
    pattern: custom_event [<(.+)>]
    event-values: string
    parse:
        set {_regex} to first element of regex-1
        set {_a} to 1
        continue
    check:
        broadcast "%{_a}%"
        broadcast "%{_regex}%"
        continue

on custom_event regex:
    broadcast "Event called"

on load:
    set {_evt} to custom event "custom_event"
    call event {_evt}

Expected behavior {_a} variable is 1 at start of check section {_regex} will = "regex"

Server information

Lotzyprod commented 3 months ago

Analysing this problem further, a new problem emerged, I believe that now Skript is trying to parse events before structures (or custom event parsed before custom event creation section for no reason). Because of this, when parsing a custom event (not the custom event creation section), on this line:

https://github.com/SkriptLang/skript-reflect/blob/7c3cbfdb24e1c59e836c7f04276aae87c66fdb66/src/main/java/org/skriptlang/reflect/syntax/event/elements/CustomEvent.java#L52 always be null if we has custom event structure and handler in same script file. It turns out that regardless of the presence of a parse section, the event can be used before loading parse section.

In the case when the event handler is located in another script file, everything seems to be fine, but the parse section still works strangely. Somehow, magically, instance of SyntaxParseEvent is automatically marked to continue, even if 'continue' was not specified in the parse section: https://github.com/SkriptLang/skript-reflect/blob/7c3cbfdb24e1c59e836c7f04276aae87c66fdb66/src/main/java/org/skriptlang/reflect/syntax/event/elements/CustomEvent.java#L66C1-L76C37