Skip to content

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

Description

@Starmism

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions