Skip to content

Loop Expression System Enhancement | DEVS #7871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cooffeeRequired
Copy link
Contributor

@cooffeeRequired cooffeeRequired commented May 16, 2025

Description

This PR introduces a new abstract system for working with loop expressions in Skript, which simplifies implementation and improves code clarity.

Main Changes:

  1. Added new AbstractLoopExpression class for basic loop expression functionality
  2. Added new AbstractExpressionInitializer class for loop expression initialization

Implementation Examples

1. Basic Loop Expression

public class CustomToLoopExpression extends SimpleExpression<String> {
    static {
        Skript.registerExpression(CustomToLoopExpression.class, String.class, ExpressionType.SIMPLE, "custom loop section");
    }

    @Override
    protected String @Nullable [] get(Event event) {
        return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }

    @Override
    public boolean isSingle() {
        return false;
    }

    @Override
    public Class<? extends String> getReturnType() {
        return String.class;
    }

    @Override
    public String toString(@Nullable Event event, boolean debug) {
        return "custom loop section";
    }

    @Override
    public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
        return true;
    }
}

public class LoopCustomExpression extends AbstractLoopExpression<Object> {
    static {
        register(LoopCustomExpression.class, Object.class, "custom");
    }

    @Override
    public boolean isIntendedLoop(SecLoop loop, AbstractExpressionInitializer initializer) {
        // any condition, similar as like init method in SimpleExpression
        return true;
    }

    @Override
    public Class<? extends Expression<?>> getExpressionToLoop() {
        return CustomToLoopExpression.class;
    }

    @Override
    protected Object[] get(Event event) {
        return new Object[] { loop.getCurrent(event) };
    }
}

Usage in Skript

# Basic usage
loop custom loop section:
    send loop-custom

Technical Details

  • AbstractLoopExpression provides basic functionality for all loop expressions
  • AbstractExpressionInitializer ensures proper initialization of loop expressions

Target Minecraft Versions: any

@cooffeeRequired cooffeeRequired requested review from a team as code owners May 16, 2025 13:30
@cooffeeRequired cooffeeRequired requested review from UnderscoreTud and cheeezburga and removed request for a team May 16, 2025 13:30
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label May 16, 2025
Copy link
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.

Thank you very much for the contribution. My current concern is that this conflicts with ExprLoopValue to some extent. I think any system should integrate with that rather than registering new patterns. I had started some work on that (as part of upcoming context changes), so this feature might be better left to the core team.

@APickledWalrus APickledWalrus added the feature Pull request adding a new feature. label May 16, 2025
@cooffeeRequired
Copy link
Contributor Author

Okey thank you for answering. Would you sent your concepts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature. needs reviews A PR that needs additional reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants