From b7c90ae5c80804d5479cbdd3a443e54726066586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl=20=28xHyroM=29?= Date: Sun, 25 Feb 2024 18:00:28 +0100 Subject: [PATCH] fix: don't register balance commands as main currency command --- .../lighteco/bukkit/commands/BalanceCommand.java | 2 +- .../bukkit/manager/BukkitCommandManager.java | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java index 3c9e295..1324094 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/commands/BalanceCommand.java @@ -34,7 +34,7 @@ public class BalanceCommand implements Command { }; } - private void handleBalance(CommandSender originalSender, CommandArguments args, Currency currency) { + public void handleBalance(CommandSender originalSender, CommandArguments args, Currency currency) { BukkitCommandSender sender = new BukkitCommandSender(originalSender, this.manager.audienceFactory); OfflinePlayer target = (OfflinePlayer) args.get("target"); diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java index 53d1260..9f10eb9 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java @@ -57,21 +57,17 @@ public class BukkitCommandManager extends AbstractCommandManager { private void registerCommands(@NonNull String name, @NonNull Currency currency) { String permissionBase = "lighteco.currency." + currency.getIdentifier() + ".command."; - // Balance - for (CommandAPICommand cmd : new BalanceCommand( - this, - name, - currency, - permissionBase - ).multipleBuild()) { - cmd.register(); - } + BalanceCommand balanceCommand = new BalanceCommand(this, "balance", currency, permissionBase); CommandAPICommand cmd = new CommandAPICommand(name) .withSubcommand(new SetCommand(this, currency, permissionBase).build()) .withSubcommand(new GiveCommand(this, currency, permissionBase).build()) .withSubcommand(new TakeCommand(this, currency, permissionBase).build()) - .withSubcommands(new BalanceCommand(this, "balance", currency, permissionBase).multipleBuild()); + .withSubcommands(balanceCommand.multipleBuild()) + // We want balance to be the default command + .executesPlayer((sender, args) -> { + balanceCommand.handleBalance(sender, args, currency); + }); if (currency.isPayable()) cmd = cmd.withSubcommand(new PayCommand(this, currency, permissionBase).build());