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

GH-357 Add priority api, strict mode, event api and @DefaultExecute. Snapshot 3.6.0-SNAPSHOT #366

Merged
merged 28 commits into from
Sep 15, 2024

Conversation

Rollczi
Copy link
Owner

@Rollczi Rollczi commented Jan 23, 2024

WiP
Resolve: #357
Resolve: #220
Resolve: #428

🟢 Add an option to disable strict mode.
If you disable strict mode for a command, then users will be able to add unexpected arguments e.g.
/help first asdfioaosdf asodfn asodimf <- this will work!

@Command(name = "help", strict = StrictMode.DISABLED)
class HelpCommand {

    @Execute
    void helpCommand(@Arg String arg) {
        
    }

}

You can also disable strict mode by calling:

.strictMode(StrictMode.DISABLED);

on builder.

⚠️ Experimental @ExecuteDefault

@Command(name = "kick")
public class KickCommand {
    @ExecuteDefault
    void commandHelp(@Context SENDER sender) {
        // /kick incorrect input
    }

    @Execute(name = "-all")
    void kickAll() {
        // /kick -all
    }
}

⚠️ Experimental @Priority

@Command(name = "test")
public class TestCommand {
    @Execute
    @Priority(PriorityValue.HIGH)
    void execute(int number) {
        // ...
    }

    @Execute
    @Priority(PriorityValue.LOW)
    void execute(String text) {
        // ...
    }
}

⚠️ Experimental Event system
Available events:

  • CandidateExecutorFoundEvent
  • CandidateExecutorMatchEvent
  • CommandPreExecutionEvent
  • CommandPostExecutionEvent

Simple example, how to block the execution of a command:

public class TellCommandController<SENDER> implements EventListener {
    
    @Subscriber
    public void onEvent(CommandPreExecutionEvent<SENDER> event) {
        SENDER sender = event.getInvocation().sender();

        if (event.getInvocation().name().equals("tell") && sender.isMuted()) {
            event.stopFlow(FailedReason.of("&cYou are muted!"));
        }
    }
}

@Rollczi Rollczi marked this pull request as draft January 23, 2024 08:58
@Rollczi Rollczi changed the title GH-357 Add priority API. Base executors sorting on priority. GH-357 Add priority API. Base executor execution on priority sorting Jan 23, 2024
@Rollczi Rollczi added enhancement New feature or request feature labels Jan 23, 2024
# Conflicts:
#	litecommands-core/src/dev/rollczi/litecommands/command/executor/CommandExecuteService.java
# Conflicts:
#	litecommands-core/src/dev/rollczi/litecommands/command/executor/CommandExecuteService.java
#	litecommands-core/src/dev/rollczi/litecommands/meta/Meta.java
#	litecommands-framework/src/dev/rollczi/litecommands/LiteCommandsBaseBuilder.java
#	litecommands-framework/src/dev/rollczi/litecommands/LiteCommandsBuilder.java
…ultController. Add IGNORE_TOO_MANY_ARGUMENTS to Meta.
@Rollczi Rollczi self-assigned this Sep 11, 2024
@Rollczi Rollczi marked this pull request as ready for review September 11, 2024 14:45
@Rollczi Rollczi changed the title GH-357 Add priority API. Base executor execution on priority sorting GH-357 Add priority api, strict mode, event api and @DefaultExecute. Sep 15, 2024
@Rollczi Rollczi changed the title GH-357 Add priority api, strict mode, event api and @DefaultExecute. GH-357 Add priority api, strict mode, event api and @DefaultExecute. Snapshot 3.6.0-SNAPSHOT Sep 15, 2024
@Rollczi Rollczi merged commit 6fb8b76 into master Sep 15, 2024
6 checks passed
@Rollczi Rollczi deleted the priority-executors branch September 15, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
1 participant