Skip to content
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

Allow parsing with custom Tag Resolvers #701

Merged
merged 4 commits into from Feb 24, 2022

Conversation

Joo200
Copy link
Contributor

@Joo200 Joo200 commented Feb 23, 2022

I want to create a new List tag to format lists.
My minimessage syntax is: <list:'[entry format]':'[separator]>

The entry format will have some placeholder tags so I modify the output of the list.
E.g.: My unique list is: <list:'<red><name></red>':', '> - that's it.

In java I would call:

    miniMessage.deserialize(format, new ListResolver(Placeholder.parsed("name", "Joo200"), Placeholder.parsed("name", "MiniDigger")));

this should result in the output My unique list is: Joo200, MiniDigger - that's it.

Unfortunatly I'm unable to pass the Placeholder for "name" as TagResolver:

    @Override
    public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException {
        if (!this.has(name)) return null;

        String format = arguments.popOr("expected list format").value();
        String separator = arguments.popOr("expected separator").value();
        return Tag.inserting(resolvers.stream().map(r -> ctx.parse(format /*, r (this doesn't work)*/))
             .collect(Component.toComponent(ctx.parse(separator))));
    }

With this PR it should be possible to pass the Context dynamic Tag Resolvers. This would be really handy.

@zml2008
Copy link
Member

zml2008 commented Feb 23, 2022

Could you add a test for this behavior, and rebase? otherwise, looks good

Co-authored-by: zml <zml@aoeu.xyz>
@Joo200
Copy link
Contributor Author

Joo200 commented Feb 24, 2022

Modified and resolves #705 now

@kezz kezz linked an issue Feb 24, 2022 that may be closed by this pull request
This was referenced Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename Context#parse to deserialize
3 participants