diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java index 1af3e0b..a938632 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java @@ -1,8 +1,10 @@ package xyz.soukup.ecoCraftCore.commands; +import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.papermc.paper.command.brigadier.CommandSourceStack; @@ -16,36 +18,56 @@ import xyz.soukup.ecoCraftCore.objects.Transaction; import xyz.soukup.ecoCraftCore.utilities.Messages; import xyz.soukup.ecoCraftCore.utilities.PHHM; +@SuppressWarnings("UnstableApiUsage") public class MoneyCommand { public static LiteralArgumentBuilder createCommand() { + + RequiredArgumentBuilder playerArgument = Commands.argument("player", ArgumentTypes.player()); + RequiredArgumentBuilder amountArgument = Commands.argument("amount", FloatArgumentType.floatArg(0.1F)); + RequiredArgumentBuilder ownerArgument = Commands.argument("owner", StringArgumentType.word()); + RequiredArgumentBuilder typeArgument = Commands.argument("type", StringArgumentType.word()); + + + LiteralArgumentBuilder send = Commands.literal("send") + .requires(source -> source.getSender() instanceof Player) + .then(playerArgument.then(amountArgument.executes(MoneyCommand::sendMoney))); + + + RequiredArgumentBuilder selfGive = amountArgument + .requires(source -> source.getSender() instanceof Player) + .executes(MoneyCommand::giveMoneySelf); + + RequiredArgumentBuilder playerGive = playerArgument + .then(amountArgument.executes(MoneyCommand::giveMoneyPlayer)); + + RequiredArgumentBuilder giveOther = typeArgument.then(ownerArgument.then(amountArgument.executes(MoneyCommand::giveMoneyOther))); + + LiteralArgumentBuilder give = Commands.literal("give") + .then(selfGive) + .then(playerGive) + .then(giveOther); + + + RequiredArgumentBuilder removeSelf = amountArgument + .requires(source -> source.getSender() instanceof Player) + .executes(MoneyCommand::removeMoneySelf); + + RequiredArgumentBuilder removePlayer = playerArgument + .then(amountArgument.executes(MoneyCommand::removeMoneyPlayer)); + + RequiredArgumentBuilder removeOther = typeArgument + .then(ownerArgument + .then(amountArgument.executes(MoneyCommand::removeMoneyOther))); + + LiteralArgumentBuilder remove = Commands.literal("remove") + .then(removeSelf) + .then(removePlayer) + .then(removeOther); + return Commands.literal("money") - .then(Commands.literal("send") - .requires(source -> source.getSender() instanceof Player) - .then(Commands.argument("player", ArgumentTypes.player()) - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .executes(MoneyCommand::sendMoney)))) - .then(Commands.literal("give") - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .requires(source -> source.getSender() instanceof Player) - .executes(MoneyCommand::giveMoneySelf)) - .then(Commands.argument("player", ArgumentTypes.player()) - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .executes(MoneyCommand::giveMoneyPlayer))) - .then(Commands.argument("type", StringArgumentType.word()) - .then(Commands.argument("owner", StringArgumentType.word()) - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .executes(MoneyCommand::giveMoneyOther))))) - .then(Commands.literal("remove") - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .requires(source -> source.getSender() instanceof Player) - .executes(MoneyCommand::removeMoneySelf)) - .then(Commands.argument("player", ArgumentTypes.player()) - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .executes(MoneyCommand::removeMoneyPlayer))) - .then(Commands.argument("type", StringArgumentType.word()) - .then(Commands.argument("owner", StringArgumentType.word()) - .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) - .executes(MoneyCommand::removeMoneyOther))))) + .then(send) + .then(give) + .then(remove) .executes(MoneyCommand::getBalance); } diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java index 4772b64..d2f5997 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java @@ -16,22 +16,24 @@ import xyz.soukup.ecoCraftCore.utilities.InventoryUtils; import xyz.soukup.ecoCraftCore.utilities.Messages; import xyz.soukup.ecoCraftCore.utilities.PDC; +@SuppressWarnings("UnstableApiUsage") public class ShopCommand { public static LiteralArgumentBuilder createCommand() { + + FloatArgumentType floatArgType = FloatArgumentType.floatArg(0.1F); + + + LiteralArgumentBuilder buy = Commands.literal("buy") + .then(Commands.argument("buy_price", floatArgType).executes(ShopCommand::createShop)); + + LiteralArgumentBuilder sell = Commands.literal("sell") + .then(Commands.argument("sell_price", floatArgType).executes(ShopCommand::createShop)); + return Commands.literal("shop") .then(Commands.argument("amount", IntegerArgumentType.integer(1)) - .then(Commands.literal("buy") - .then(Commands.argument("buy_price", FloatArgumentType.floatArg(0.1F)) - .executes(ShopCommand::createShop) - .then(Commands.literal("sell") - .then(Commands.argument("sell_price", FloatArgumentType.floatArg(0.1F)) - .executes(ShopCommand::createShop))))) - .then(Commands.literal("sell") - .then(Commands.argument("sell_price", FloatArgumentType.floatArg(0.1F)) - .executes(ShopCommand::createShop) - .then(Commands.literal("buy") - .then(Commands.argument("buy_price", FloatArgumentType.floatArg(0.1F)) - .executes(ShopCommand::createShop)))))); + .then(buy.then(sell)) + .then(sell.then(buy))); + } @@ -51,14 +53,14 @@ public class ShopCommand { try { buyPrice = ctx.getArgument("buy_price", Float.class); } catch (IllegalArgumentException e) { - buyPrice = 0F; + buyPrice = (Float) 0F; } Float sellPrice; try { sellPrice = ctx.getArgument("sell_price", Float.class); }catch (IllegalArgumentException e){ - sellPrice = 0F; + sellPrice = (Float) 0F; } @@ -85,7 +87,7 @@ public class ShopCommand { virtualChest.databaseSave(); - PDC.set(chest, "virtual", virtualChest.getId()); + PDC.set(chest, "virtual", Integer.valueOf(virtualChest.getId())); int freeSpace = InventoryUtils.getSpaceLeft(chest.getInventory(), item); int stock = InventoryUtils.getCount(chest.getInventory(), item);