From 0da9bd35806f3457f10bd60a54305bc24d3bc597 Mon Sep 17 00:00:00 2001 From: lokka30 Date: Sun, 5 Jan 2025 20:53:50 +0800 Subject: [PATCH] CurrencySubcommand: fix args and casting Fixed arguments being added to the parent commands and thus not trickling down to the leaf subcommands, as CommandAPI/Brigadier will discard arguments on subcommands. Fixed startingBalance being cast as String rather than Double --- .../subcommand/CurrencySubcommand.kt | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/plugin-bukkit/src/main/kotlin/io/github/arcaneplugins/polyconomy/plugin/bukkit/command/polyconomy/subcommand/CurrencySubcommand.kt b/plugin-bukkit/src/main/kotlin/io/github/arcaneplugins/polyconomy/plugin/bukkit/command/polyconomy/subcommand/CurrencySubcommand.kt index 9a2b965..6eb0928 100644 --- a/plugin-bukkit/src/main/kotlin/io/github/arcaneplugins/polyconomy/plugin/bukkit/command/polyconomy/subcommand/CurrencySubcommand.kt +++ b/plugin-bukkit/src/main/kotlin/io/github/arcaneplugins/polyconomy/plugin/bukkit/command/polyconomy/subcommand/CurrencySubcommand.kt @@ -33,26 +33,28 @@ object CurrencySubcommand : InternalCmd { private fun buildSetSubcommand(plugin: Polyconomy): CommandAPICommand { return CommandAPICommand("set") .withPermission(PolyconomyPerm.COMMAND_POLYCONOMY_CURRENCY_SET.toString()) - .withArguments( - CustomArguments.currencyArgument(plugin, "currency") - ) .withSubcommands( CommandAPICommand("startingBalance") - .withArguments(DoubleArgument("newValue")) + .withArguments( + CustomArguments.currencyArgument(plugin, "currency"), + DoubleArgument("newValue")) .executes(CommandExecutor { sender, args -> val currency = args.get("currency") as Currency val newValue = args.get("newValue") as Double throw CommandAPI.failWithString("Not yet implemented!") }), CommandAPICommand("symbol") - .withArguments(StringArgument("newValue")) + .withArguments( + CustomArguments.currencyArgument(plugin, "currency"), + StringArgument("newValue")) .executes(CommandExecutor { sender, args -> val currency = args.get("currency") as Currency val newValue = args.get("newValue") as String throw CommandAPI.failWithString("Not yet implemented!") }), CommandAPICommand("amountFormat") - .withArguments(StringArgument("newValue")) + .withArguments(CustomArguments.currencyArgument(plugin, "currency"), + StringArgument("newValue")) .executes(CommandExecutor { sender, args -> val currency = args.get("currency") as Currency val newValue = args.get("newValue") as String @@ -66,17 +68,19 @@ object CurrencySubcommand : InternalCmd { throw CommandAPI.failWithString("Not yet implemented!") }), CommandAPICommand("conversionRate") - .withArguments(DoubleArgument("newValue")) + .withArguments(CustomArguments.currencyArgument(plugin, "currency"), + DoubleArgument("newValue")) .executes(CommandExecutor { sender, args -> val currency = args.get("currency") as Currency val newValue = args.get("newValue") as Double throw CommandAPI.failWithString("Not yet implemented!") }), CommandAPICommand("locale") - .withArguments(CustomArguments.localeArgument("locale")) .withSubcommands( CommandAPICommand("register") .withArguments( + CustomArguments.currencyArgument(plugin, "currency"), + CustomArguments.localeArgument("locale"), StringArgument("dispNameSingular"), StringArgument("dispNamePlural"), StringArgument("dispDecimal"), @@ -87,6 +91,8 @@ object CurrencySubcommand : InternalCmd { }), CommandAPICommand("set") .withArguments( + CustomArguments.currencyArgument(plugin, "currency"), + CustomArguments.localeArgument("locale"), StringArgument("dispNameSingular"), StringArgument("dispNamePlural"), StringArgument("dispDecimal"), @@ -96,6 +102,10 @@ object CurrencySubcommand : InternalCmd { throw CommandAPI.failWithString("Not yet implemented!") }), CommandAPICommand("unregister") + .withArguments( + CustomArguments.currencyArgument(plugin, "currency"), + CustomArguments.localeArgument("locale"), + ) .executes(CommandExecutor { sender, args -> val locale = args.get("locale") as Locale throw CommandAPI.failWithString("Not yet implemented!") @@ -123,7 +133,7 @@ object CurrencySubcommand : InternalCmd { ) .executes(CommandExecutor { sender, args -> val name = args.get("name") as String - val startingBalance = args.get("startingBalance") as String + val startingBalance = args.get("startingBalance") as Double val symbol = args.get("symbol") as String val conversionRate = args.get("conversionRate") as Double val dispLocale = args.get("dispLocale") as Locale