dešpagetizace příkozových class shop a money

dev_gioth
jakub 9 months ago
parent d881cade87
commit bd8b88cdae
  1. 72
      src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java
  2. 32
      src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.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<CommandSourceStack> createCommand() {
return Commands.literal("money")
.then(Commands.literal("send")
RequiredArgumentBuilder<CommandSourceStack, PlayerSelectorArgumentResolver> playerArgument = Commands.argument("player", ArgumentTypes.player());
RequiredArgumentBuilder<CommandSourceStack, Float> amountArgument = Commands.argument("amount", FloatArgumentType.floatArg(0.1F));
RequiredArgumentBuilder<CommandSourceStack, String> ownerArgument = Commands.argument("owner", StringArgumentType.word());
RequiredArgumentBuilder<CommandSourceStack, String> typeArgument = Commands.argument("type", StringArgumentType.word());
LiteralArgumentBuilder<CommandSourceStack> send = 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))
.then(playerArgument.then(amountArgument.executes(MoneyCommand::sendMoney)));
RequiredArgumentBuilder<CommandSourceStack, Float> selfGive = amountArgument
.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))
.executes(MoneyCommand::giveMoneySelf);
RequiredArgumentBuilder<CommandSourceStack, PlayerSelectorArgumentResolver> playerGive = playerArgument
.then(amountArgument.executes(MoneyCommand::giveMoneyPlayer));
RequiredArgumentBuilder<CommandSourceStack, String> giveOther = typeArgument.then(ownerArgument.then(amountArgument.executes(MoneyCommand::giveMoneyOther)));
LiteralArgumentBuilder<CommandSourceStack> give = Commands.literal("give")
.then(selfGive)
.then(playerGive)
.then(giveOther);
RequiredArgumentBuilder<CommandSourceStack, Float> removeSelf = amountArgument
.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)))))
.executes(MoneyCommand::removeMoneySelf);
RequiredArgumentBuilder<CommandSourceStack, PlayerSelectorArgumentResolver> removePlayer = playerArgument
.then(amountArgument.executes(MoneyCommand::removeMoneyPlayer));
RequiredArgumentBuilder<CommandSourceStack, String> removeOther = typeArgument
.then(ownerArgument
.then(amountArgument.executes(MoneyCommand::removeMoneyOther)));
LiteralArgumentBuilder<CommandSourceStack> remove = Commands.literal("remove")
.then(removeSelf)
.then(removePlayer)
.then(removeOther);
return Commands.literal("money")
.then(send)
.then(give)
.then(remove)
.executes(MoneyCommand::getBalance);
}

@ -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<CommandSourceStack> createCommand() {
FloatArgumentType floatArgType = FloatArgumentType.floatArg(0.1F);
LiteralArgumentBuilder<CommandSourceStack> buy = Commands.literal("buy")
.then(Commands.argument("buy_price", floatArgType).executes(ShopCommand::createShop));
LiteralArgumentBuilder<CommandSourceStack> 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);

Loading…
Cancel
Save