Revxrsal / Lamp

A modern annotations-driven commands framework for Java and Kotlin
MIT License
202 stars 38 forks source link

feat: `@Length` Annotation for String Parameters #43

Closed gmitch215 closed 1 year ago

gmitch215 commented 1 year ago

Hello,

I am proposing to add a @Length annotation that would create a minimum/maximum length for Strings. I'm pretty sure this is natively supported by brigadier, but I'm not sure. I couldn't find an existing annotation that exists for this purpose, so I'm proposing a new one.

It would look like this:

public @interface Length {

    int min() default 0;

    int max() default Integer.MAX_VALUE; // Something like that
}

Could be used in scenarios like this:


@Command("nick")
@Description("Set a Player's Nickname")
public void nickPlayer(Player player, @Length(min = 3, max = 32) String name) {
    player.setDisplayName(name);
}

Also: I would recommend creating a build script that automatically updates the JavaDocs instead of manually copying files.

Revxrsal commented 1 year ago

This sounds like an excellent use case for parameter validators, see https://github.com/Revxrsal/Lamp/wiki/Parameter-validators. There's a good chance it may be natively added later as it could be used by brigadier.

Also: I would recommend creating a build script that automatically updates the JavaDocs instead of manually copying files. Thanks, I'll take a look. They are currently neglected as I believe most people either look at the wiki, examples, or inspect code themselves.