### Create and Install Default Bindings for PartInjector Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/part-injector.md Demonstrates how to create a PartInjector and install the default bindings for native and core types. ```java PartInjector partInjector = PartInjector.create(); // install the default bindings! // parts for native and core types like String, Boolean, Double, Float, Integer, // Text(String), ArgumentStack, CommandContext, also modifiers like LimitModifier, // OptionalModifier, ValueFlagModifier partInjector.install(new DefaultsModule()); ``` -------------------------------- ### Create a Basic Command Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/basic.md Use Command.builder to define a command named 'test' that prints 'Hello World!' when executed. No arguments, subcommands, or permissions are required for this basic setup. ```java Command testCommand = Command.builder("test") .action(context -> { System.out.println("Hello World!"); }) .build(); ``` -------------------------------- ### Install Bukkit-Specific Bindings for PartInjector Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/part-injector.md Shows how to install platform-specific bindings for Bukkit, including common Bukkit types like Player and World. ```java // install bindings for the default bindings for Bukkit, such as // CommandSender, OfflinePlayer, Player, World, GameMode and @Sender Player partInjector.install(new BukkitModule()); ``` -------------------------------- ### Registering a Bukkit Command with Command Flow Source: https://github.com/fixeddev/command-flow/blob/main/docs/platforms/bukkit.md Example demonstrating how to register a command class using `BukkitCommandManager` and `BukkitModule` in a Bukkit plugin. ```java @Command(names = "gamemode", permission = "myplugin.gamemode") class GameModeCommand implements CommandClass { @Command(names = "") public void run(@Sender Player sender, GameMode gameMode, @OptArg Player target) { if (target == null) { sender.setGameMode(gameMode); } else { target.setGameMode(gameMode); } sender.sendMessage("Success!"); } } class MyPlugin extends JavaPlugin { @Override public void onEnable() { registerCommands(); // now you can use '/gamemode [target]' in game! } private void registerCommands() { CommandManager manager = new BukkitCommandManager("myplugin"); // <-- your plugin name // annotated! PartInjector injector = PartInjector.create(); injector.install(new DefaultsModule()); injector.install(new BukkitModule()); // <-- BukkitModule! AnnotatedCommandTreeBuilder builder = AnnotatedCommandTreeBuilder.create(injector); // register manager.registerCommands(builder.fromClass(new GameModeCommand())); } } ``` -------------------------------- ### Declare a Simple Command with Annotations Source: https://github.com/fixeddev/command-flow/blob/main/docs/getting-started.md Use annotations to define a command class and its methods. This example shows how to create a basic command named 'test' with a sub-command 'hello' that sends a message. ```java @Command("test") public class TestCommand implements CommandClass { @Command("hello") public void hello(CommandSender sender) { sender.sendMessage("Hello World!"); } } ``` -------------------------------- ### Accessing Variables within Command Action Source: https://github.com/fixeddev/command-flow/blob/main/docs/execution/execution.md This example shows how to register a command and then execute it, accessing a variable previously set in the namespace from within the command's action. This is useful for commands that need context from where they are executed. ```java CommandManager manager = ...; Command command = Command.builder("test") .action(context -> { User sender = context.getObject(User.class, "SENDER"); System.out.println("'test' command used by " + sender.getName()); }) .build(); manager.registerCommand(command); Namespace namespace = Namespace.create(); namespace.setObject(User.class, "SENDER", new User("Yusshu", 18)); manager.execute(namespace, "test"); ``` -------------------------------- ### Create a Basic Command Source: https://github.com/fixeddev/command-flow/blob/main/docs/concepts/command.md Demonstrates how to create a simple command with an action using the Command.builder(). ```java Command command = Command.builder("Test") .action(context -> { System.out.println("Hi!"); }) .build(); ``` -------------------------------- ### Define Command with Multiple Arguments Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/multiple-arguments.md This snippet shows how to create a command named 'greet' that accepts a string argument 'name' and a boolean argument 'formal'. It defines the command parts and an action to process these arguments. ```java CommandPart name = string("name"); CommandPart formalPart = booleanPart("formal"); Command greetCommand = Command.builder("greet") .addPart(name) .addPart(formalPart) .action(context -> { boolean formal = context.getValue(formalPart).orElse(false); context.getValue(name).ifPresent(s -> { if (formal) { System.out.println("Hello, " + s + "!"); } else { System.out.println("Hi, " + s + "!"); } }); }) .build(); ``` -------------------------------- ### Create a Namespace Source: https://github.com/fixeddev/command-flow/blob/main/docs/concepts/namespaces.md Instantiates a new, empty namespace object. This is the first step before adding any arguments. ```java // Create a namespace Namespace namespace = Namespace.create(); ``` -------------------------------- ### Setting a Custom Input Tokenizer Source: https://github.com/fixeddev/command-flow/blob/main/docs/configuration/tokenizer.md Demonstrates how to create an InputTokenizer and set it on the CommandManager. This is useful when you need custom tokenization logic beyond the defaults. ```java InputTokenizer tokenizer = ...; CommandManager manager = ...; manager.setInputTokenizer(tokenizer); ``` -------------------------------- ### Annotated Command with String and Boolean Arguments Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/multiple-arguments.md Defines a 'greet' command that accepts a 'name' (String) and a 'formal' (boolean) argument. Use this when your command logic depends on multiple distinct inputs. ```java @Command(names = "greet") public class GreetingCommand implements CommandClass { @Command(names = "") public void run(String name, boolean formal) { if (formal) { System.out.println("Hello, " + name + "!"); } else { System.out.println("Hi, " + name + "!"); } } } ``` -------------------------------- ### Java Command with Single String Argument Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/argument.md Defines a command named 'hello' that takes one string argument and prints a greeting. Ensure the argument is provided during execution to avoid errors. ```java import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameter; @Parameters(commandNames = "hello") public class HelloCommand { @Parameter(names = "--name") private String name; public void run() { System.out.println("Hi " + name); } } ``` -------------------------------- ### Basic Java Command Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/basic.md This snippet shows how to define a simple command named 'test' that prints 'Hello World!' when executed. It uses the @Command annotation for both the main command and its execution method. ```java import com.github.twitch4j.common.annotation.Command; import com.github.twitch4j.common.command.CommandClass; @Command(names = "test") public class TestCommand implements CommandClass { @Command(names = "") public void run() { System.out.println("Hello World!"); } } ``` -------------------------------- ### Create Command with Permission Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/with-permission.md Defines a command named 'test' that requires the 'admin' permission to execute. If the user lacks the permission, a NoPermissionException will be thrown. ```java Command testUserCommand = Command.builder("test") // We set the permission of the test command into admin .permission("admin") .action(context -> { System.out.println("Hi"); }) .build(); ``` -------------------------------- ### Define a Command with Permission Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/with-permission.md Use the 'permission' parameter in the @Command annotation to specify the required permission for command execution. This ensures that only users with the 'myperm.command.greet' permission can run the 'greet' command. ```java import com.velocitypowered.api.command.Command; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.annotation.Command; @Command(names = "greet", permission = "myperm.command.greet") public class GreetingCommand implements CommandClass { @Command(names = "") public void run(String name) { System.out.println("Hello, " + name + "!"); } } ``` -------------------------------- ### Execute a Command with Arguments Source: https://github.com/fixeddev/command-flow/blob/main/docs/execution/execution.md This snippet demonstrates how to execute a command with arguments by providing a namespace and a command string to the CommandManager#execute method. The namespace can be used to pass variables to the command. ```java CommandManager manager = ...; Namespace namespace = Namespace.create(); namespace.setObject(User.class, "USER", new User("Fixed", 16)); manager.execute(namespace, "greet Yusshu"); ``` -------------------------------- ### Define and Use a Command with a Switch Argument Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/with-switches.md This snippet shows how to define a command with a switch argument ('goodBye' or '-g') and a string argument ('name'). The command's action checks the value of the switch to determine whether to print a greeting or a farewell. ```java CommandPart name = string("name"); // If the -g argument is present, then the switch value will be true, otherwise false // It can be in any position, but the parts registered before will take priority, // that means that if the name part is registered before the switch part, the -g only // can be after the name CommandPart goodByeSwitch = switchPart("goodBye", "g"); Command testUserCommand = Command.builder("test") .addPart(goodByeSwitch) .addPart(name) .action(context -> { // The value for a switch is never absent boolean goodBye = context.getValue(goodByeSwitch).get(); context.getValue(name).ifPresent(s -> { if (goodBye) { System.out.println("Goodbye " + s); return; } System.out.println("Hi " + s); }); }) .build(); ``` -------------------------------- ### Accessing Command Context in Action Source: https://github.com/fixeddev/command-flow/blob/main/docs/execution/context.md Demonstrates how to access and use the CommandContext within a command's action. The context provides labels, which are the names used for commands and subcommands. ```java CommandManager manager = ...; Command command = Command.builder("test") .addAlias("testalias") .action(context -> { // Here we have an action of the command, and here we can use the context for this command // The CommandContext is the result of parsing the arguments of a command. // It also extends Namespace, so you can use the Namespace methods on it. // The labels are the names for every command/subcommand executed. // This is the name of the last subcommand/command String label = context.getLabels().get(context.getLabels().size() - 1); System.out.println("Label: " + label); }) .build(); manager.registerCommand(command); // execute the command manager.execute(Namespace.create(), "testalias"); // Will print 'Label: testalias' manager.execute(Namespace.create(), "test"); // Will print 'Label: test' ``` -------------------------------- ### Build Commands from Class Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/command-tree-builder.md Build a list of Command objects from an annotated class using the fromClass method. These commands can then be registered with the CommandManager. ```java // create the builder AnnotatedCommandTreeBuilder builder = ...; // build the Command list from our class List commands = builder.fromClass(MyCommand.class); // now we can register them using the CommandManager#registerCommands convenience method commandManager.registerCommands(commands); ``` -------------------------------- ### Java Command with Value Flag Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/with-value-flags.md Demonstrates creating a command with a value flag argument using the command-flow library. The value flag consumes the next argument as its value. ```java CommandPart name = string("name"); // This part is like a switch part, the difference is that when the main "switch" is found // the part provided in the first argument takes the parsing, consuming one or more arguments // from the stack at that position. CommandPart greetingValue = string("greeting"); CommandPart greetingValueFlag = valueFlag(greetingValue, "g"); Command testUserCommand = Command.builder("test") .addPart(greetingValueFlag) .addPart(name) .action(context -> { // The value for a value flag can be absent String greeting = context.getValue(greetingValue).orElse("Hi"); context.getValue(name).ifPresent(s -> { System.out.println(greeting + " " + s); }); }) .build(); ``` -------------------------------- ### Define Command with Optional Argument Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/optional-arguments.md This snippet demonstrates how to create a command with an optional argument that has a default value. The optional argument is defined using the `optional()` method, specifying the argument part and its default value. ```java CommandPart titleValue = string("title"); // This makes the titleValue argument optional, with the default value "Mr." CommandPart title = optional(titleValue, Collections.singletonList("Mr.")); CommandPart name = string("name"); Command greetCommand = Command.builder("greet") .addPart(name) .addPart(title) .action(context -> { String nameString = context.getValue(nameValue).orElse("User"); // Should be present every time, since it has a default value // If the default value is not valid for the specified part, then the argument could be absent String titleString = context.getValue(titleValue).get(); System.out.println("Hello, " + titleString + " " + nameString); }) .build(); ``` -------------------------------- ### Define and Use a String Argument in a Command Source: https://github.com/fixeddev/command-flow/blob/main/docs/imperatively/argument.md This snippet shows how to create a command with a single string argument named 'name'. It demonstrates accessing the argument's value within the command's action to print a personalized greeting. The argument is required for the action to print anything. ```java //... // create an (argument) part of type string, with the name 'name' CommandPart nameArg = string("name"); // create the command Command helloCommand = Command.builder("hello") .addPart(nameArg) .action(context -> { // get the value of the name argument and print 'Hi ' context.getValue(nameArg).ifPresent(name -> { System.out.println("Hi " + name); }); }) .build(); ``` -------------------------------- ### Create AnnotatedCommandTreeBuilder Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/command-tree-builder.md Instantiate an AnnotatedCommandTreeBuilder by first creating a PartInjector and optionally a SubCommandInstanceCreator. ```java PartInjector injector = ...; SubCommandInstanceCreator instanceCreator = ...; AnnotatedCommandTreeBuilder builder = AnnotatedCommandTreeBuilder.create(injector, instanceCreator); ``` -------------------------------- ### SubCommandInstanceCreator for Dependency Injection Frameworks Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/subcommand-instance-creator.md Provides a SubCommandInstanceCreator implementation suitable for dependency injection frameworks like Guice or Unnamed Team's inject. It obtains subcommand instances from the provided Injector. ```java Injector injector = ...; SubCommandInstanceCreator subCommandCreator = (clazz, parent) -> injector.getInstance(clazz); AnnotatedCommandTreeBuilder commandBuilder = AnnotatedCommandTreeBuilder.create( partInjector, subCommandCreator ); ``` -------------------------------- ### Add Unnamed Public Repository to Gradle Source: https://github.com/fixeddev/command-flow/blob/main/docs/installation.md Configure your Gradle project to use the Unnamed Public repository for fetching command-flow artifacts. ```kotlin repositories { maven("https://repo.unnamed.team/repository/unnamed-public/") } ``` -------------------------------- ### Create AnnotatedCommandTreeBuilder with Default SubCommandInstanceCreator Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/subcommand-instance-creator.md Instantiates an AnnotatedCommandTreeBuilder using the default SubCommandInstanceCreator, which relies on reflection for subcommand instantiation. ```java AnnotatedCommandTreeBuilder commandBuilder = AnnotatedCommandTreeBuilder.create(partInjector); ``` -------------------------------- ### Add Command Flow Bukkit Dependency (Gradle) Source: https://github.com/fixeddev/command-flow/blob/main/docs/platforms/bukkit.md Include the `commandflow-bukkit` dependency in your Gradle project to enable Bukkit integration. ```kotlin dependencies { // ... implementation("team.unnamed:commandflow-bukkit:%%REPLACE_latestReleaseOrSnapshot{team.unnamed:commandflow-bukkit}%%") } ``` -------------------------------- ### Create SimpleCommandManager Source: https://github.com/fixeddev/command-flow/blob/main/docs/concepts/command-manager.md Instantiates the default SimpleCommandManager. This can be used across different platforms. ```java CommandManager commandManager = new SimpleCommandManager(); ``` -------------------------------- ### Create AnnotatedCommandTreeBuilder with Custom SubCommandInstanceCreator Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/subcommand-instance-creator.md Instantiates an AnnotatedCommandTreeBuilder with a custom SubCommandInstanceCreator implementation for controlling subcommand instantiation. ```java AnnotatedCommandTreeBuilder commandBuilder = AnnotatedCommandTreeBuilder.create( partInjector, new MyCustomSubCommandInstanceCreator() ); ``` -------------------------------- ### Register a Command Source: https://github.com/fixeddev/command-flow/blob/main/docs/concepts/command-manager.md Registers a new command with the CommandManager. Commands are defined using a builder pattern and an action lambda. ```java // create CommandManager CommandManager manager = ...; // create Command using builder Command command = Command.builder("test") .description("A test command") .action(context -> { System.out.println("Hello world!"); }) .build(); // register the command manager.registerCommand(command); ``` -------------------------------- ### Setting a Custom Authorizer Source: https://github.com/fixeddev/command-flow/blob/main/docs/configuration/authorizer.md Set your custom Authorizer implementation in the CommandManager instance. ```java CommandManager commandManager = ...; commandManager.setAuthorizer(new MyAuthorizer()); ``` -------------------------------- ### Custom Authorizer Implementation Source: https://github.com/fixeddev/command-flow/blob/main/docs/configuration/authorizer.md Implement the Authorizer interface to define custom permission logic. Ensure the User object is correctly retrieved from the namespace. ```java public class MyAuthorizer implements Authorizer { @Override public boolean isAuthorized(Namespace namespace, String permission) { User user = namespace.getObject(User.class, "USER"); // User not set! if (user == null) { return false; } return user.hasPermission(permission); } } ``` -------------------------------- ### Defining Command Permission with Annotation Source: https://github.com/fixeddev/command-flow/blob/main/docs/configuration/authorizer.md Set the permission string for a command using annotations. ```java @Command(names = "test", permission = "this.is.the.permission.string") public class TestCommand implements CommandClass { ... } ``` -------------------------------- ### Define Command with Boolean Switch Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/with-switches.md Defines a command named 'test' with a 'name' argument and a boolean switch '-g' for 'goodBye'. The command prints a greeting or farewell based on the switch's presence. ```java import com.github.holger.command.Command; import com.github.holger.command.CommandClass; import com.github.holger.command.Switch; @Command(names = "test") public class TestCommand implements CommandClass { @Command(names = "") public void run(String name, @Switch("g") boolean goodBye) { if (goodBye) { System.out.println("Goodbye " + name); return; } System.out.println("Hi " + name); } } ``` -------------------------------- ### Java Command with Value Flag Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/with-value-flags.md Defines a command named 'test' that accepts a required string argument 'name' and an optional string value flag 'g'. The flag takes the next argument as its value. ```java @Command(names = "test") public class TestCommand implements CommandClass { @Command(names = "") public void run(String name, @Flag("g") String greeting) { System.out.println(greeting + " " + name); } } ``` -------------------------------- ### Add Unnamed Public Repository to Maven Source: https://github.com/fixeddev/command-flow/blob/main/docs/installation.md Configure your Maven project to use the Unnamed Public repository for fetching command-flow artifacts. ```xml unnamed-public https://repo.unnamed.team/repository/unnamed-public/ ``` -------------------------------- ### Define Command with Optional Argument Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/optional-arguments.md This snippet demonstrates how to define a command with an optional argument using the @OptArg annotation. The default value 'Mr.' is used if the optional argument is not provided. ```java import com.github.rvesse.airline.annotations.Command; import com.github.rvesse.airline.annotations.Option; import com.github.rvesse.airline.annotations.OptArg; import com.github.rvesse.airline.model.CommandClass; @Command(names = "greet") public class GreetingCommand implements CommandClass { @Command(names = "") public void run(String name, @OptArg("Mr.") String title) { System.out.println("Hello, " + title + " " + name + "!"); } } ``` -------------------------------- ### Defining Command Permission with Builder Source: https://github.com/fixeddev/command-flow/blob/main/docs/configuration/authorizer.md Set the permission string for a command when using the Command builder. ```java Command command = Command.builder("test") .permission("this.is.the.permission.string") .action(context -> { System.out.println("Hello World!"); }) .build(); ``` -------------------------------- ### Friends Command with Subcommands Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/command-class.md Defines a '/friends' command with multiple subcommands for managing friend lists, including add, remove, list, and broadcast. Supports aliases for the main command. ```java import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.command.Command; import org.spongepowered.api.command.CommandClass; import org.spongepowered.api.command.CommandManager; import org.spongepowered.api.command.args.CommandContext; import org.spongepowered.api.command.spec.CommandSpec; import org.spongepowered.api.text.Text; @Command(names = { "friends", "friend", "f", "fr" }) // name, ...aliases public class FriendsCommand implements CommandClass { @Command(names = "add") public void add(@Sender Player sender, Player target) { // add 'target' to 'sender' friend list } @Command(names = "remove") public void remove(@Sender Player sender, Player target) { // remove 'target' from 'sender' friend list } @Command(names = "list") public void list(@Sender Player sender) { // list all 'sender' friends and show } @Command(names = "broadcast") public void broadcast(@Sender Player sender, @Text String message) { // send 'message' to all the friends of 'sender' } } ``` -------------------------------- ### Add Command Flow Bukkit Dependency (Maven) Source: https://github.com/fixeddev/command-flow/blob/main/docs/platforms/bukkit.md Add the `commandflow-bukkit` dependency to your Maven project's pom.xml for Bukkit integration. ```xml team.unnamed commandflow-bukkit %%REPLACE_latestReleaseOrSnapshot{team.unnamed:commandflow-bukkit}%% ``` -------------------------------- ### Teleport Command Definition Source: https://github.com/fixeddev/command-flow/blob/main/docs/annotated/command-class.md Defines a '/teleport' command that teleports the sender to a target player. The target player is parsed as an argument. ```java import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.command.Command; import org.spongepowered.api.command.CommandClass; import org.spongepowered.api.command.CommandManager; import org.spongepowered.api.command.args.CommandContext; import org.spongepowered.api.command.spec.CommandSpec; import org.spongepowered.api.text.Text; @Command(names = "teleport") public class TeleportCommand implements CommandClass { @Command(names = "") // empty name indicates the root command public void run( @Sender Player sender, // the sender player Player target // the target player (argument) ) { sender.teleport(target); } } ``` -------------------------------- ### Add CommandFlow API Dependency to Gradle Source: https://github.com/fixeddev/command-flow/blob/main/docs/installation.md Include the command-flow API as an implementation dependency in your Gradle project. Replace %%REPLACE_latestReleaseOrSnapshot{team.unnamed:commandflow-api}%% with your desired version. ```kotlin dependencies { implementation("team.unnamed:commandflow-api:%%REPLACE_latestReleaseOrSnapshot{team.unnamed:commandflow-api}%%") } ``` -------------------------------- ### Retrieve Object from Namespace Source: https://github.com/fixeddev/command-flow/blob/main/docs/concepts/namespaces.md Retrieves an object from the namespace using its class type and name. Ensure the object was previously set with the exact same identifiers. ```java User user = namespace.getObject(User.class, "USER"); System.out.println(user.getName()); // Fixed ``` -------------------------------- ### Set Object in Namespace Source: https://github.com/fixeddev/command-flow/blob/main/docs/concepts/namespaces.md Stores an object within the namespace, identified by its class type and a unique name. This makes the object available for later retrieval. ```java namespace.setObject(User.class, "USER", new User("Fixed", 16)); ``` -------------------------------- ### Add CommandFlow API Dependency to Maven Source: https://github.com/fixeddev/command-flow/blob/main/docs/installation.md Include the command-flow API as a dependency in your Maven project. Replace %%REPLACE_latestReleaseOrSnapshot{team.unnamed:commandflow-api}%% with your desired version. ```xml team.unnamed commandflow-api %%REPLACE_latestReleaseOrSnapshot{team.unnamed:commandflow-api}%% ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.