Skip to content

Allow wait/halt to be used as a section #8547

Open
ahmadmsaleem wants to merge 13 commits intoSkriptLang:dev/featurefrom
ahmadmsaleem:feature/delay-section
Open

Allow wait/halt to be used as a section #8547
ahmadmsaleem wants to merge 13 commits intoSkriptLang:dev/featurefrom
ahmadmsaleem:feature/delay-section

Conversation

@ahmadmsaleem
Copy link
Copy Markdown
Contributor

@ahmadmsaleem ahmadmsaleem commented Apr 16, 2026

Problem

wait / halt only work as effects today, they block the entire trigger until the delay elapses. There is no way in Skript to schedule a block of code to run later while the rest of the trigger continues immediately.

Solution

Make Delay an EffectSection. EffectSectionEffect delegated setNext/getNext but not getActualNext or executionIntent, so Section.loadCode's intent walk stopped at the wrapper and missed trailing stop intents — letting inner delays leak past the section. Override both to delegate.

Effect form: unchanged.

Section form: body parses as a separate trigger under outer events with hasDelayBefore=TRUE. walk() snapshots locals, schedules the task, swaps locals in the callback so mutations stay isolated. Outer isn't delayed.

Testing Completed

Manual in game testing on a Paper server covering:

command /test1:
    trigger:
        broadcast "A"
        wait 1 second:
            broadcast "B"
            wait 2 seconds:
                broadcast "C"
            broadcast "D"
            wait 1 second
            broadcast "E"
        broadcast "F"
# expect: A, F, (1s) B, D, (2s) E, (3s) C


command /test2:
    trigger:
        set {_shared} to "outer"
        loop 3 times:
            set {_i} to loop-number
            wait 1 second:
                set {_shared} to "body-%{_i}%"
                broadcast "iter %{_i}% shared=%{_shared}% %unix timestamp of now%"
        wait 2 seconds
        broadcast "done shared=%{_shared}% %unix timestamp of now%"
# expect: (1s) 3 messages "iter 1..3" each with correct number and shared=body-N, (3s after start) done shared=outer


command /test3:
    trigger:
        broadcast "1"
        wait 2 seconds
        broadcast "2"
# expect: 1, (2s) 2 — effect form unchanged
> test1
[19:04:44 INFO]: A
[19:04:44 INFO]: F
[19:04:45 INFO]: B
[19:04:45 INFO]: D
[19:04:46 INFO]: E
[19:04:47 INFO]: C
> test2
[19:04:50 INFO]: iter 1 shared=body-1 1776272690.29
[19:04:50 INFO]: iter 2 shared=body-2 1776272690.29
[19:04:50 INFO]: iter 3 shared=body-3 1776272690.29
[19:04:51 INFO]: done shared=outer 1776272691.29
> test3
[19:04:53 INFO]: 1
[19:04:55 INFO]: 2

No skript test files added in this PR wait / halt do not currently have test scripts under src/test/skript/tests/ and adding the first ones for this feature felt out of scope. Happy to add them in a follow up

Supporting Information

This PR was made by eult :)


Completes: none
Related: none
AI assistance: Claude Opus 4.6, Used to help me writing the walk method, tests and rewrite the description

@ahmadmsaleem ahmadmsaleem requested a review from a team as a code owner April 16, 2026 05:10
@ahmadmsaleem ahmadmsaleem requested review from Absolutionism and erenkarakal and removed request for a team April 16, 2026 05:10
@skriptlang-automation skriptlang-automation Bot added the needs reviews A PR that needs additional reviews label Apr 16, 2026
@ahmadmsaleem ahmadmsaleem force-pushed the feature/delay-section branch from fa65249 to f461ac0 Compare April 16, 2026 05:16
@ahmadmsaleem ahmadmsaleem requested a review from a team as a code owner April 16, 2026 10:29
@ahmadmsaleem ahmadmsaleem requested review from UnderscoreTud and removed request for a team April 16, 2026 10:29
Comment thread src/main/java/ch/njol/skript/effects/Delay.java
@TheLimeGlass
Copy link
Copy Markdown
Contributor

That's a neat way to do it

@ahmadmsaleem
Copy link
Copy Markdown
Contributor Author

That's a neat way to do it

this approach worked surprisingly well, idk how

Copy link
Copy Markdown
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work so far

Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
@sovdeeth sovdeeth self-requested a review April 21, 2026 01:25
@sovdeeth sovdeeth added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Apr 21, 2026
@skriptlang-automation skriptlang-automation Bot moved this to In Review in 2.16 Releases Apr 21, 2026
Copy link
Copy Markdown
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/Delay.java
Comment thread src/main/java/ch/njol/skript/effects/Delay.java Outdated
@skriptlang-automation skriptlang-automation Bot removed the needs reviews A PR that needs additional reviews label Apr 25, 2026
ahmadmsaleem and others added 4 commits April 26, 2026 11:39
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
@ahmadmsaleem ahmadmsaleem requested a review from sovdeeth April 26, 2026 09:55
Comment on lines +118 to +119
if (!isSection)
addDelayedEvent(event);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event is delayed regardless, no?

Skript.debug(getIndentation() + "... continuing after " + (System.nanoTime() - start) / 1_000_000_000. + "s");

// Re-set local variables
Object outerLocals = isSection ? Variables.removeLocals(event) : null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this? I don't think the variable handling needs to be any different for sections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature request, an issue about something that could be improved, or a PR improving something.

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

4 participants