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

Registering parsers with a narrower type of the sender type #770

Open
Starmism opened this issue Sep 10, 2024 · 0 comments
Open

Registering parsers with a narrower type of the sender type #770

Starmism opened this issue Sep 10, 2024 · 0 comments

Comments

@Starmism
Copy link

Making a custom parser that accepts a subtype of your sender type (in my case org.bukkit.entity.Player of org.bukkit.command.CommandSender) is very useful as to automatically utilize existing error infrastructure (specifically the TerminalConsoleCommandSender is not allowed to execute that command. Must be of type Player message).

Currently, the existing ParserRegistry#registerParser(ParserDescriptor) method does not allow type narrowing and requires an unchecked cast to allow it to compile.

Example in Kotlin:

manager.parserRegistry().registerParser(ParserDescriptor.of(MineParser() as ArgumentParser<CommandSender, Mine>, Mine::class.java))

I was told by @jpenilla that there could be a method added that gives a view of the parser registry for subtypes specifically, so that this can be validated correctly. Here is the Discord message where this was mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant