Skip to content

LiteCommands v3.7.0

Compare
Choose a tag to compare
@Rollczi Rollczi released this 13 Oct 12:12
· 56 commits to master since this release
98b803f

What's Changed

Thanks @OOP-778 for the important bug fix ❤️

🟢 Add alias for @Context annotation

@Command(name = "hello")
public class HelloCommand {
    @Execute
    void command(@Sender CommandSender sender, @Arg String name) {
        // ...
    }
}

🟢 Add an option to create Annotation aliases like as @Sender

You can implement your annotation:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@RequirementDefinition(type = RequirementDefinition.Type.CONTEXT)
public @interface MySender {
}

And use it in your commands:

    @Execute
    void command(@MySender CommandSender sender, @Arg String name) {
        // ...
    }

🟢 Support completableFuture/async parse/context result:

public class UserArgumentResolver extends ArgumentResolver<CommandSender, User> {

    private final Pattern VALID_USER_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{3,16}$");
    private final UserService userService;

    public UserArgumentResolver(UserService userService) {
        this.userService = userService;
    }

    @Override
    protected ParseResult<User> parse(Invocation<CommandSender> invocation, Argument<User> context, String argument) {
        CompletableFuture<ParseResult<User>> userNotFound = userService.getUser(argument)
            .thenApply(user -> user != null ? ParseResult.success(user) : ParseResult.failure("User not found"));

        return ParseResult.completableFuture(userNotFound);
    }

    @Override
    public boolean match(Invocation<CommandSender> invocation, Argument<User> context, String argument) {
        return VALID_USER_PATTERN.matcher(argument).matches();
    }
}

🟢 when you call blocking methods you can use ParseResult.async()

    @Override
    protected ParseResult<User> parse(Invocation<CommandSender> invocation, Argument<User> context, String argument) {
        return ParseResult.async(() -> userDatabase.getUser(argument));
    }

⚠️ When you return async/completableFuture result then you must also implement match method for correct suggestion validation

🟢 See also same API for ContextResult

ContextResult.completableFuture()
ContextResult.async()

🔴 Removed wrapper API

🔴 Breaking changes (Internal API)

See more #435

Update dependencies

implementation("dev.rollczi:{artifact}:3.7.0")
<dependency>
    <groupId>dev.rollczi</groupId>
    <artifactId>{artifact}</artifactId>
    <version>3.7.0</version>
</dependency>

⚠️ Replace {artifact} with platform artifact

Discord Sponsor

New Contributors

Full Changelog: v3.6.1...v3.7.0