JorelAli/CommandAPI

Feature: CommandSender in DynamicSuggestedStringArgument

Draycia opened this issue · 3 comments

Please describe your suggestion
Would be nice to dynamically suggest strings per user. For instance, each user has a set of homes, and I would like to display their homes as they're typing the argument.

Please supply examples of the desired inputs and outputs
Example:
Input: /home homename
Output: /home <home, farm, friend, newbase>

Example:

class CommandHome {
    private fun run(sender: CommandSender, args: Array<Any>) {
        if (sender !is Player) return;

        // Check if home exists and teleport player there.
    }

    private fun dynamicStringArgument(sender: CommandSender): Array<String> {
        if (sender !is Player) return arrayOf();
        return PluginMain.homes[sender.uniqueId] ?: arrayOf();
    }

    fun registerCommand() {
        val normal = LinkedHashMap<String, Argument>();
        normal["Home"] = DynamicSuggestedStringArgument(::dynamicStringArgument);
        CommandAPI.getInstance().register("home", CommandPermission.fromString("commands.home"), normal, ::run);

    }
}

Sounds doable. I'll take a look at it!

Thank you!

Implemented in this commit

This will be included in the 1.9 release which is due soon!