### Tab Completer - Basic Source: https://github.com/despical/commandframework/wiki/Command-Examples A basic tab completer for the 'example' command and its aliases, providing a static list of suggestions. ```java @Completer( name = "example", aliases = {"firstAlias", "secondAlias"} ) public List exampleCommandCompletion() { return Arrays.asList("first", "second", "third"); } ``` -------------------------------- ### CommandArguments Basic Methods and Usage Source: https://github.com/despical/commandframework/wiki/Command-arguments Demonstrates how to retrieve sender information, command details, and arguments using the CommandArguments class. Includes examples for checking sender type, accessing Bukkit and Annotation Command objects, and getting arguments by index or as a whole array. Also shows how to send messages to the sender and check permissions. ```java // We have created a basic command named "example" @Command( name = "example" ) public void exampleCommandMethod(CommandArguments arguments) { // --- Sender & Command Info --- // Retrieve the command sender CommandSender sender = arguments.getSender(); // Check the type of the sender if (arguments.isSenderPlayer()) { // The sender is a player } else { // The sender is the console } // Retrieve the underlying Bukkit Command object org.bukkit.command.Command bukkitCommand = arguments.getBukkitCommand(); // Retrieve the Annotation Command object associated with these arguments dev.despical.commandframework.annotations.Command command = arguments.getCommand(); // Get the command label used String label = arguments.getLabel(); // --- Argument Retrieval Basics --- // Get all arguments as an array String[] args = arguments.getArguments(); // Check if the argument array is empty boolean isArgsEmpty = arguments.isArgumentsEmpty(); // Get the number of arguments int argumentsLength = arguments.getLength(); // Get a specific argument by index (0-based) // Returns null if the index is out of bounds (no exception thrown) String firstArgument = arguments.getArgument(0); // Returns the first argument // Equivalent to arguments.getArgument(0)) String firstArg = arguments.getFirst(); // Returns the last argument // Equivalent to arguments.getArgument(arguments.getLength() - 1)) String lastArg = arguments.getLast(); // Get a specific argument with a default fallback value // Returns "default value" if index 0 is out of bounds String notNullArgument = arguments.getArgument(0, "default value"); // Retrieves the first argument and parses it as an integer int argAsInt = argument.getArgumentAsInt(0); // Retrieves the first argument and parses it as a double double argAsDouble = argument.getArgumentAsDouble(0); // Retrieves the first argument and parses it as a float float argAsFloat = argument.getArgumentAsFloat(0); // Retrieves the first argument and parses it as a long long argAsLong = argument.getArgumentAsLong(0); // Retrieves the first argument and parses it as a boolean boolean argAsBoolean = argument.getArgumentAsBoolean(0); // --- Permissions & Messaging --- // Send a message directly to the sender // Supports color codes, HEX colors are not supported by default // See Message.setFormatter() method to apply your own color converter arguments.sendMessage("&cHey there!"); // Sends a parameterized message directly to the sender arguments.sendMessage("&aHey there, {0}!", arguments.getSender().getName()); // Check permissions without manually retrieving the sender object if (arguments.hasPermission("command.framework")) { // Sender has the permission } } ``` -------------------------------- ### Command with Confirmation Source: https://github.com/despical/commandframework/wiki/Command-Examples An example command that requires confirmation before execution. The confirmation message and expiration time are configurable. ```java @Command( name = "confirmationTest" ) @Confirmation( message = "Are you sure? Please execute the command again to confirm.", expireAfter = 10, bypassPerm = "confirmation.bypass", timeUnit = TimeUnit.SECONDS, overrideConsole = true ) public void confirmationCommand(CommandArguments arguments) { arguments.sendMessage("Confirmation successful."); } ``` -------------------------------- ### Standard Command with Cooldown Source: https://github.com/despical/commandframework/wiki/Command-Examples Example of a standard command with various annotations for name, aliases, permissions, description, usage, sender type, and cooldown. The cooldown is set to 10 seconds and bypassable with a permission. ```java @Command( name = "example", fallbackPrefix = "prefix", aliases = {"firstAlias", "secondAlias"}, permission = "example.permission", desc = "Sends an example message to sender", usage = "/example", min = 1, max = 5, senderType = Command.SenderType.CONSOLE ) @Cooldown( cooldown = 10, timeUnit = TimeUnit.SECONDS, bypassPerm = "command.cooldownBypass", overrideConsole = true // Console is also affected by cooldown ) public void exampleCommand(CommandArguments arguments) { arguments.sendMessage("This is how you can create an example command using the framework."); } ``` -------------------------------- ### Handle Command Arguments in Java Source: https://github.com/despical/commandframework/wiki/Command-arguments Demonstrates various methods for processing command arguments, including player retrieval, string concatenation, and numeric checks. Ensure the Command Framework is set up and the method is registered as a command. ```java @Command( name = "example" ) public void exampleCommandMethod(CommandArguments arguments) { // --- Player Retrieval --- // Get an online player by name (returns Optional) Optional playerFromName = arguments.getPlayer("Despical"); playerFromName.ifPresent(player -> player.sendMessage("Hello World!")); // Get an online player from an argument index (returns Optional) Optional playerFromArgs = arguments.getPlayer(0); playerFromArgs.ifPresent(player -> player.sendMessage("Hello World!")); // --- String Concatenation --- // Assume arguments = ["example", "array", "with", "multiple", "arguments"] // Concatenate all arguments into a single string String concatenatedArgs = arguments.concatArguments(); // Result: "example array with multiple arguments" // Concatenate a range of arguments (fromIndex inclusive, toIndex exclusive) String concatRangeOf = arguments.concatRangeOf(1, 4); // Result: "array with multiple arguments" // --- Numeric Checks --- // Checks if the argument at index 0 is a valid number. boolean isNumeric = arguments.isNumeric(0); // Checks if the argument is a valid Integer. boolean isInteger = arguments.isInteger(0); // Checks if the argument is a floating point number (Double/Float). boolean isFloatingDecimal = arguments.isFloatingDecimal(0); // --- Miscellaneous --- // Check if the sender is currently on cooldown for this command boolean hasCooldown = arguments.checkCooldown(); // Send a pre-defined error message from the Message enum boolean success = arguments.sendMessage(Message.SHORT_ARG_SIZE); } ``` -------------------------------- ### CommandFramework Initialization and Registration Source: https://context7.com/despical/commandframework/llms.txt Initialize `CommandFramework` with your plugin instance in `onEnable()`. Optionally enable features like confirmations, custom cooldown checkers, or debug logging. Register commands by passing the current class or use `registerAllInPackage()` for a whole package. ```java public class MyPlugin extends JavaPlugin { private CommandFramework commandFramework; @Override public void onEnable() { commandFramework = new CommandFramework(this); // Enable optional features commandFramework.options().enable(FrameworkOption.CONFIRMATIONS); commandFramework.options().enable(FrameworkOption.CUSTOM_COOLDOWN_CHECKER); commandFramework.options().enable(FrameworkOption.DEBUG); // verbose logging // Register all @Command / @Completer methods in this class commandFramework.registerCommands(this); // Or register every class in a whole package (requires public no-args constructors) commandFramework.registerAllInPackage("com.myplugin.commands"); } @Override public void onDisable() { // Cleanly remove all commands registered by this framework instance commandFramework.unregisterCommands(); } } ``` -------------------------------- ### Register Command Framework Source: https://github.com/despical/commandframework/wiki/Command-Examples Initialize the CommandFramework with your plugin instance and register command classes. No need to define commands in plugin.yml. ```java public class ExampleClass extends JavaPlugin { private CommandFramework commandFramework; @Override public void onEnable() { // Initialize the framework with your plugin instance commandFramework = new CommandFramework(this); // Register the class containing your command methods. // There is no need to define these commands in your plugin.yml. commandFramework.registerCommands(this); } } ``` -------------------------------- ### Create Basic Command Source: https://github.com/despical/commandframework/wiki/Command-Examples Annotate a method with @Command and include CommandArguments. Customize name, aliases, permissions, description, usage, argument limits, operator-only flag, async execution, and sender type. ```java @Command( name = "example", aliases = {"firstAlias", "secondAlias"}, permission = "example.permission", desc = "Sends an example message to sender", usage = "/example", min = 1, max = 5, onlyOp = false, // If true, ignores permission checks async = false, // Set to true for async execution (ensure thread safety) senderType = Command.SenderType.CONSOLE ) public void exampleCommand(CommandArguments arguments) { arguments.sendMessage("This is how you can create an example command using the framework."); } ``` -------------------------------- ### Relocate Command Framework with Gradle Shadow Plugin Source: https://github.com/despical/commandframework/wiki/How-to-relocate? Configure the Gradle Shadow plugin to relocate the Command Framework package. Ensure the plugin version is up-to-date. This is typically added to the build.gradle.kts file. ```kotlin plugins { id 'com.github.johnrengelman.shadow' version '8.1.1' } shadowJar { relocate 'dev.despical.commandframework', 'your.package.here' } ``` -------------------------------- ### Gradle Dependency and Shadow Configuration Source: https://context7.com/despical/commandframework/llms.txt Configure your Gradle build (Kotlin DSL) to include the Command Framework dependency and set up the `shadowJar` plugin for relocation. This ensures the library is correctly shaded and avoids conflicts. ```kotlin dependencies { implementation("dev.despical:command-framework:1.6.2") } plugins { id("com.github.johnrengelman.shadow") version "8.1.1" } shadowJar { relocate("dev.despical.commandframework", "com.myplugin.lib.commandframework") } ``` -------------------------------- ### Accessing Command Arguments and Sender Information Source: https://context7.com/despical/commandframework/llms.txt Demonstrates how to access sender information, raw arguments, typed arguments, perform validation, and use string helpers within a command handler. ```java @Command(name = "info", min = 1, max = 4) public void infoCommand(CommandArguments arguments) { // --- Sender --- CommandSender sender = arguments.getSender(); // generic; cast-safe for Player/Console boolean isPlayer = arguments.isSenderPlayer(); boolean isConsole = arguments.isSenderConsole(); boolean hasPerm = arguments.hasPermission("myplugin.info"); // --- Raw arguments --- String[] all = arguments.getArguments(); // full array int count = arguments.getLength(); String first = arguments.getFirst(); // null-safe alias for getArgument(0) String last = arguments.getLast(); String arg1 = arguments.getArgument(1); // null if out-of-bounds String arg1d = arguments.getArgument(1, "N/A"); // default if out-of-bounds // --- Typed conversions --- int asInt = arguments.getArgumentAsInt(0); double asDouble = arguments.getArgumentAsDouble(0); long asLong = arguments.getArgumentAsLong(0); float asFloat = arguments.getArgumentAsFloat(0); boolean asBool = arguments.getArgumentAsBoolean(0); // --- Validation --- boolean numeric = arguments.isNumeric(0); // digits only boolean integer = arguments.isInteger(0); // parseable as int boolean decimal = arguments.isFloatingDecimal(0); // parseable as double // --- String helpers --- String full = arguments.concatArguments(); // "arg0 arg1 arg2 ..." String slice = arguments.concatRangeOf(1, 3); // "arg1 arg2" // --- Player lookup --- Optional target = arguments.getPlayer(0); // by argument index target.ifPresent(p -> p.sendMessage("Hello!")); // --- Messaging --- arguments.sendMessage("&aHello, &e{0}&a! Count: {1}", sender.getName(), count); arguments.sendMessage(Message.NO_PERMISSION); // send a framework system message // --- Cooldown inline check (requires FrameworkOption.CUSTOM_COOLDOWN_CHECKER) --- arguments.checkCooldown(); // stops execution & notifies sender if on cooldown } ``` -------------------------------- ### Add Gradle Dependency for Command Framework Source: https://github.com/despical/commandframework/wiki/Command-basics Use this implementation line in your build.gradle file to include the Command Framework. ```gradle dependencies { implementation 'dev.despical:command-framework:1.6.1' } ``` -------------------------------- ### Register Custom Parameters Source: https://github.com/despical/commandframework/wiki/Command-Examples Demonstrates how to register custom parameters for String and complex types. This allows the framework to automatically convert arguments. ```java commandFramework.addCustomParameter(String.class, CommandArguments::getFirst); commandFramework.addCustomParameter("secondAsInt", arguments -> arguments.getLength() > 1 ? arguments.getArgumentAsInt(1) : null); ``` -------------------------------- ### Customizing Framework Messages Source: https://context7.com/despical/commandframework/llms.txt Shows how to redirect framework messages through MiniMessage, replace specific messages like NO_PERMISSION and SHORT_ARG_SIZE, and inspect/unregister commands. ```java // Redirect framework messages through MiniMessage / Adventure Message.setColorFormatter(raw -> MiniMessage.miniMessage().serialize( LegacyComponentSerializer.legacyAmpersand().deserialize(raw) ) ); // Replace the "no permission" message Message.NO_PERMISSION.setMessage((command, args) -> { args.sendMessage("&4[!] &cYou lack the permission &e" + command.permission() + "&c."); return true; // return false to suppress the message }); // Replace the "wrong argument count" messages with usage hint Message.SHORT_ARG_SIZE.setMessage((command, args) -> { args.sendMessage("&cUsage: &f" + command.usage()); return true; }); // Inspect all registered commands at runtime CommandFramework framework = CommandFramework.getInstance(); List all = framework.getAllCommands(); List roots = framework.getCommands(); List subs = framework.getSubCommands(); all.forEach(cmd -> framework.getLogger().info("Registered: /" + cmd.name())); // Dynamically unregister a specific command framework.unregisterCommand("arena"); ``` -------------------------------- ### Create Command Without Arguments Source: https://github.com/despical/commandframework/wiki/Command-Examples Commands can be created without any parameters if no arguments are needed. ```java @Command( name = "nocommandargs" ) public void noCommandArgsTest() { Logger.getLogger(this.getClass().getSimpleName()).info("This command is running without any parameters."); } ``` -------------------------------- ### Implement Two-Step Confirmation with @Confirmation Source: https://context7.com/despical/commandframework/llms.txt Annotate a @Command method with @Confirmation to require the sender to run the command twice within a time window. The first execution sends a confirmation message, and the second executes the method body. Requires FrameworkOption.CONFIRMATIONS to be enabled. ```java // In onEnable: commandFramework.options().enable(FrameworkOption.CONFIRMATIONS); @Command(name = "wipe", permission = "myplugin.wipe") @Confirmation( message = "&cThis will delete ALL data! Run the command again within 10s to confirm.", expireAfter = 10, timeUnit = TimeUnit.SECONDS, bypassPerm = "myplugin.wipe.bypass", overrideConsole = true // console must also confirm ) public void wipeCommand(CommandArguments arguments) { // Only reached after the sender executes /wipe a second time within 10 seconds arguments.sendMessage("&cAll data wiped!"); } ``` -------------------------------- ### Relocate Command Framework with Maven Shade Plugin Source: https://github.com/despical/commandframework/wiki/How-to-relocate? Configure the Maven Shade Plugin to relocate the Command Framework package. Ensure the plugin version is up-to-date. This is typically used in the pom.xml file. ```xml org.apache.maven.plugins maven-shade-plugin 3.4.1 package shade dev.despical.commandframework your.package.here ``` -------------------------------- ### Custom Parameter Injection (Implicit) Source: https://github.com/despical/commandframework/wiki/Command-Examples This command demonstrates implicit custom parameter injection for a String type, which was registered earlier. It requires at least one argument. ```java @Command( name = "customParamWithoutAnnotations", min = 1 ) public void customParamCommand(String firstParameter, CommandArguments arguments) { arguments.sendMessage("First parameter is " + firstParameter); } ``` -------------------------------- ### Registering and Using Custom Parameters Source: https://github.com/despical/commandframework/wiki/Custom-Parameters Demonstrates how to register a custom parameter named 'test' and use it with @Default and @Param annotations in a command method. The custom parameter 'test' is handled by a lambda that checks argument length and creates a TestValue instance. ```java public class Main extends JavaPlugin { @Override public void onEnable() { CommandFramework commandFramework = new CommandFramework(this); commandFramework.registerCommands(this); commandFramework.addCustomParameter("test", arguments -> arguments.getLength() != 1 ? null : new TestValue(arguments.getArgument(0))); } // /test somRandomTextAsFirstArg - Output will be "Value: somRandomTextAsFirstArg" // /test - Output will be "Value: Default value" @Command(name = "test") public void test(CommandArguments arguments, @Default("Default value") @Param("test") TestValue testValue) { arguments.sendMessage("Value:" + testValue.value); } public static class TestValue { private final String value; public TestValue(String value) { this.value = value; } public static TestValue valueOf(String value) { return new TestValue(value); } public String getValue() { return value; } } } ``` -------------------------------- ### Maven Dependency and Shade Configuration Source: https://context7.com/despical/commandframework/llms.txt Add the Command Framework dependency to your Maven project and configure the `maven-shade-plugin` to relocate the library's package. This is crucial for avoiding classpath conflicts with other plugins. ```xml dev.despical command-framework 1.6.2 org.apache.maven.plugins maven-shade-plugin 3.4.1 package shade dev.despical.commandframework com.myplugin.lib.commandframework ``` -------------------------------- ### Add Maven Dependency for Command Framework Source: https://github.com/despical/commandframework/wiki/Command-basics Include this dependency in your pom.xml to add the Command Framework as a project dependency. ```xml dev.despical command-framework 1.6.1 ``` -------------------------------- ### Create Sub-Command Source: https://github.com/despical/commandframework/wiki/Command-Examples Define sub-commands by using dots in the @Command name. Arguments are split after the sub-command parts. ```java @Command( name = "example.subcommand" ) public void exampleSubCommandMethod(CommandArguments arguments) { // This method handles: /example subcommand arguments.sendMessage("You executed the sub-command!"); } ``` -------------------------------- ### Command without Parameters Source: https://github.com/despical/commandframework/wiki/Command-Examples A simple command that does not require any parameters and directly sends a message to the console. ```java @Command( name = "noParams" ) public void commandWithoutParameters() { Bukkit.getConsoleSender().sendMessage("This command is running without any parameters."); } ``` -------------------------------- ### Define Commands with @Command Source: https://context7.com/despical/commandframework/llms.txt Annotate methods with @Command to define commands. Specify name, aliases, permissions, and sender types. Sub-commands use dot notation. CommandArguments parameter is optional. ```java @Command( name = "arena", // /arena aliases = {"ar"}, permission = "myplugin.arena", desc = "Manage arenas", usage = "/arena ", min = 1, // requires at least 1 argument max = 3, // no more than 3 arguments onlyOp = false, async = false, // true = runs on a new thread (non-thread-safe Bukkit APIs risk) senderType = Command.SenderType.PLAYER // BOTH | PLAYER | CONSOLE ) public void arenaCommand(CommandArguments arguments) { String arenaName = arguments.getArgument(0); arguments.sendMessage("&aManaging arena: &e" + arenaName); } ``` ```java // Sub-command: /arena create @Command(name = "arena.create", permission = "myplugin.arena.create", min = 1) public void arenaCreate(CommandArguments arguments) { String name = arguments.getFirst(); arguments.sendMessage("&aArena '&e{0}&a' created!", name); } ``` ```java // Command that needs no CommandArguments @Command(name = "ping") public void ping() { Bukkit.broadcastMessage("Pong!"); } ``` -------------------------------- ### Declare Key-Value Options with @Option Source: https://context7.com/despical/commandframework/llms.txt Use @Option to declare expected key-value options. The framework parses --key=value tokens and exposes them through CommandArguments#getOption(). ```java @Option(value = "players", prefix = "--", valueSeparator = ",", keySeparator = "=") @Command(name = "team", permission = "myplugin.team", min = 1) public void teamCommand(CommandArguments arguments) { // /team create --players=Alice,Bob,Charlie String teamName = arguments.getFirst(); List members = arguments.getOption("players"); if (members == null || members.isEmpty()) { arguments.sendMessage("&cNo players specified with --players=..."); return; } arguments.sendMessage("&aTeam '&e{0}&a' created with {1} member(s).", teamName, members.size()); members.forEach(name -> arguments.sendMessage(" &7- &f" + name)); } ``` -------------------------------- ### Create Tab Completion Source: https://github.com/despical/commandframework/wiki/Command-Examples Annotate a method with @Completer and return a List for suggestions. Supports sub-commands by using dots in the completer name. ```java @Completer( name = "example", aliases = {"firstAlias", "secondAlias"} ) public List exampleCommandCompletion(CommandArguments arguments) { // Returns suggestions for the target command return Arrays.asList("first", "second", "third"); } ``` -------------------------------- ### Tab Completer - Advanced Source: https://github.com/despical/commandframework/wiki/Command-Examples An advanced tab completer that dynamically generates suggestions based on the command arguments and sender permissions. It uses a switch statement to provide context-aware completions. ```java @Completer( name = "example", permission = "plugin.tabcompleter" ) public List onTabComplete(CommandArguments arguments, CompleterHelper helper) { int index = arguments.getLength() - 1; return switch (index) { case 0 -> helper.copyMatches(0, commands); case 1 -> switch (arguments.getFirst()) { case "delete", "edit", "join" -> helper.copyMatches(1, List.of("arena1", "arena2", "arena3")); case null, default -> helper.empty(); }; default -> helper.empty(); }; } ``` -------------------------------- ### Implement Tab Completion with @Completer Source: https://context7.com/despical/commandframework/llms.txt Annotate methods returning List with @Completer to provide tab completion. The completer name must match the command name. CommandArguments parameter is optional. ```java @Completer(name = "arena", aliases = {"ar"}) public List arenaCompleter(CommandArguments arguments, CompleterHelper helper) { // helper.copyMatches filters the list against what the player has typed so far return switch (arguments.getLength()) { case 1 -> helper.copyMatches(0, List.of("create", "delete", "list", "join")); case 2 -> switch (arguments.getFirst()) { case "delete", "join" -> helper.copyMatches(1, Bukkit.getWorlds().stream().map(World::getName).toList()); default -> helper.empty(); }; default -> helper.empty(); }; } ``` ```java // Minimal completer — no CommandArguments needed @Completer(name = "ping") public List pingCompleter() { return List.of("--silent", "--broadcast"); } ``` -------------------------------- ### Register Custom Parameters with @Param - Java Source: https://github.com/despical/commandframework/wiki/Custom-Parameters Registers two custom parameters, 'firstArg' and 'second arg', each returning a specific argument. This allows using the same type (String) multiple times with distinct names. ```java public class ExampleClass extends JavaPlugin { @Override public void onEnable() { CommandFramework commandFramework = new CommandFramework(this); commandFramework.registerCommands(this); commandFramework.addCustomParameter("firstArg", arguments -> arguments.getArgument(0)); commandFramework.addCustomParameter("second arg", arguments -> arguments.getArgument(1)); } // /example firstArg secondArg - Output will be "First argument is 'firstArg' and the second is secondArg'." // We ensure that we have at least 2 arguments given. For default values check the part below. @Command(name = "example", min = 2) public void exampleCommand(CommandArguments arguments, @Param("firstArg") String first, @Param("second arg") String second) { arguments.sendMessage("First argument is '" + first + "' and the second is '" + second + "'."); } } ``` -------------------------------- ### Custom Parameter Injection (Explicit) Source: https://github.com/despical/commandframework/wiki/Command-Examples Shows explicit custom parameter injection using @Param and @Default annotations. The 'secondAsInt' parameter is expected as an integer and defaults to 50 if not provided. ```java @Command( name = "customParams", min = 1 ) public void customParamsCommand( CommandArguments arguments, @Param("secondAsInt") @Default("50") int secondArg ) { // If the argument is missing, it defaults to 50. arguments.sendMessage("Second argument as integer is " + secondArg); } ``` -------------------------------- ### Register Custom Parameter with @Default and @Param - Java Source: https://github.com/despical/commandframework/wiki/Custom-Parameters Registers a custom parameter 'arg' for a String, with a default value. If no argument is provided, 'default value of the argument' is used. ```java public class ExampleClass extends JavaPlugin { @Override public void onEnable() { CommandFramework commandFramework = new CommandFramework(this); commandFramework.registerCommands(this); commandFramework.addCustomParameter("arg", arguments -> arguments.getArgument(0)); commandFramework.addCustomParameter("secondAsInt", arguments -> arguments.getLength() > 1 ? arguments.getArgumentAsInt(1) : null); } // /example - Output will be "Value: default value of the argument" // /example test - Output will be "Value: test" @Command(name = "example") public void exampleCommand(CommandArguments arguments, @Default("default value of the argument") @Param("arg") String value) { arguments.sendMessage("Value: " + value); } // /example firstArg 123 - Output will be "Second argument as int is 123" // /example firstArg - Output will be "Second argument as int is 100" (100 is the value from default annotation) @Command(name = "intExample") public void exampleCommand(CommandArguments arguments, @Default("100") @Param("secondAsInt") int secondArg) { arguments.sendMessage("Second argument as int is " + secondArg); } } ``` -------------------------------- ### Register Custom Parameter (String) - Java Source: https://github.com/despical/commandframework/wiki/Custom-Parameters Registers a custom parameter named 'String' that simply returns the first argument. Useful when you need to differentiate parameters of the same type. ```java public class ExampleClass extends JavaPlugin { @Override public void onEnable() { CommandFramework commandFramework = new CommandFramework(this); commandFramework.registerCommands(this); commandFramework.addCustomParameter("String", arguments -> arguments.getArgument(0)); } // /example test - Output will be "Value: test" if the first argument is given in the command. @Command(name = "example") public void exampleCommand(CommandArguments arguments, String arg) { // If we add more String typed parameters all of them will be the same. // To add multiple parameters with the same type but different outputs check 'Custom Parameters with @Param annotation' part below. arguments.sendMessage("Value: " + arg); } } ``` -------------------------------- ### Register Custom Parameter Converters Source: https://context7.com/despical/commandframework/llms.txt Register converters to map CommandArguments to custom types. Registered parameters are injected directly into command method signatures. ```java // ---- Registration (onEnable) ---- commandFramework.addCustomParameter(String.class, CommandArguments::getFirst); // all String params → arg[0] commandFramework.addCustomParameter("secondAsInt", args -> args.getLength() > 1 ? args.getArgumentAsInt(1) : null); commandFramework.addCustomParameter(GameMode.class, args -> { String raw = args.getArgument(0, "survival"); return switch (raw.toLowerCase()) { case "creative", "c", "1" -> GameMode.CREATIVE; case "adventure", "a", "2" -> GameMode.ADVENTURE; default -> GameMode.SURVIVAL; }; }); // ---- Usage in commands ---- // Implicit injection by type — String resolves via the "String.class" parameter above @Command(name = "say", min = 1) public void sayCommand(String message, CommandArguments arguments) { arguments.sendMessage("&7You said: &f" + message); } // Explicit injection by name with a default fallback @Command(name = "setlevel", min = 1) public void setLevelCommand( CommandArguments arguments, @Param("secondAsInt") @Default("1") int level ) { // /setlevel Steve 42 → level = 42 // /setlevel Steve → level = 1 (from @Default) Player target = arguments.getPlayer(0).orElse(null); if (target == null) { arguments.sendMessage("&cPlayer not found."); return; } target.setLevel(level); arguments.sendMessage("&aSet {0}''s level to {1}.", target.getName(), level); } // Non-primitive custom type with valueOf(String) factory @Command(name = "gamemode", senderType = Command.SenderType.PLAYER) public void gamemodeCommand(CommandArguments arguments, GameMode mode) { Player player = arguments.getSender(); player.setGameMode(mode); arguments.sendMessage("&aGameMode set to &e" + mode.name()); } ``` -------------------------------- ### Enforce Rate-Limiting with @Cooldown Source: https://context7.com/despical/commandframework/llms.txt Use @Cooldown on a @Command method to enforce a per-sender wait period. Cooldowns are checked automatically before method execution by default. For inline checking, enable FrameworkOption.CUSTOM_COOLDOWN_CHECKER and call arguments.checkCooldown(). ```java // General cooldown — checked automatically before the method executes @Command(name = "heal", permission = "myplugin.heal", senderType = Command.SenderType.PLAYER) @Cooldown( value = 30, timeUnit = TimeUnit.SECONDS, bypassPerm = "myplugin.cooldown.bypass", overrideConsole = false // console bypasses cooldown by default ) public void healCommand(CommandArguments arguments) { Player player = arguments.getSender(); player.setHealth(player.getMaxHealth()); arguments.sendMessage("&aYou have been healed!"); } ``` ```java // Inline cooldown — checked at a custom point inside the method @Command(name = "broadcast", permission = "myplugin.broadcast", min = 1) @Cooldown(value = 60, timeUnit = TimeUnit.SECONDS) public void broadcastCommand(CommandArguments arguments) { // Execution stops here and the sender receives the cooldown message if on cooldown arguments.checkCooldown(); Bukkit.broadcastMessage(arguments.concatArguments()); arguments.sendMessage("&aBroadcast sent!"); } ``` -------------------------------- ### Custom Cooldown Check in Method Body Source: https://github.com/despical/commandframework/wiki/Cooldowns Implement custom cooldown checks within a command's method body using CommandArguments#hasCooldown. Ensure CommandFramework.enableOption(Option.CUSTOM_COOLDOWN_CHECKER) is called. This method will stop execution if a cooldown is active, so no explicit return is needed. ```java public class Main extends JavaPlugin { @Override public void onEnable() { CommandFramework commandFramework = new CommandFramework(this); commandFramework.registerCommands(this); // To be able to call CommandArguments#hasCooldown method, this option must be enabled. commandFramework.enableOption(Option.CUSTOM_COOLDOWN_CHECKER); } @Command(name = "test") @Cooldown(cooldown = 5) public void testCommand(CommandArguments args) { args.checkCooldown(); // In the first try, the command sender see the message below. // In the second try, if they haven't waited for 5 seconds, in this case, the code will be stopped right after // args.checkCooldown() method invoked and the sender will receive a message that says they have to wait a little bit. args.sendMessage("Test command executed successfully."); } } ``` -------------------------------- ### General Cooldown Annotation Source: https://github.com/despical/commandframework/wiki/Cooldowns Use the @Cooldown annotation to automatically apply a cooldown to a command. The framework handles the check before the command method is executed. ```java public class Main extends JavaPlugin { @Override public void onEnable() { CommandFramework commandFramework = new CommandFramework(this); commandFramework.registerCommands(this); } @Command(name = "test") @Cooldown(cooldown = 5) public void testCommand(CommandArguments args) { args.sendMessage("Test command executed successfully."); } } ``` -------------------------------- ### TestValue Class valueOf Method Source: https://github.com/despical/commandframework/wiki/Custom-Parameters This static method is required for non-primitive custom parameter types to convert a String argument into the desired class instance. ```java public static TestValue valueOf(String value) { return new TestValue(value); } ``` -------------------------------- ### Declare Boolean Flags with @Flag Source: https://context7.com/despical/commandframework/llms.txt Use @Flag to declare expected boolean flags. The framework parses --flagname tokens and makes them queryable via CommandArguments#isFlagPresent(). ```java @Flag(value = "silent", prefix = "--") @Flag(value = "broadcast", prefix = "--") @Command(name = "kick", permission = "myplugin.kick", min = 1, senderType = Command.SenderType.PLAYER) public void kickCommand(CommandArguments arguments) { // /kick Notch --silent --broadcast String target = arguments.getFirst(); boolean silent = arguments.isFlagPresent("silent"); boolean broadcast = arguments.isFlagPresent("broadcast"); Player targetPlayer = Bukkit.getPlayer(target); if (targetPlayer == null) { arguments.sendMessage("&cPlayer not found."); return; } targetPlayer.kickPlayer("You were kicked."); if (!silent) arguments.sendMessage("&eKicked " + target); if (broadcast) Bukkit.broadcastMessage(target + " was kicked."); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.