yay
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.smithy.celestianeconomy.command;
|
||||
|
||||
import com.smithy.celestianeconomy.CelestianUtils;
|
||||
import com.smithy.celestianeconomy.config.CelestianEconomyConfig;
|
||||
import com.smithy.celestianeconomy.sql.DatabaseManager;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class DepositCommand {
|
||||
public static LiteralArgumentBuilder<CommandSourceStack> buildCommand(){
|
||||
return Commands.literal(CelestianEconomyConfig.getInstance().depositCommandName)
|
||||
.executes(DepositCommand::depositCommand);
|
||||
}
|
||||
|
||||
public static int depositCommand(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
|
||||
ServerPlayer player = ctx.getSource().getPlayerOrException();
|
||||
DatabaseManager dm = CelestianUtils.getDatabaseManager();
|
||||
int currencyCount = 0;
|
||||
for (int i = CelestianEconomyConfig.getCurrencyValues().length - 1; i >= 0; i--) {
|
||||
for (int j = 0; j < player.getInventory().getContainerSize(); j++) {
|
||||
if (player.getInventory().getItem(j).getItem().equals(CelestianEconomyConfig.getCurrency(i))) {
|
||||
currencyCount += player.getInventory().getItem(j).getCount() * CelestianEconomyConfig.getCurrencyValues()[i];
|
||||
player.getInventory().setItem(j, new ItemStack(Items.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dm.changeBalance(player.getStringUUID(), currencyCount)) {
|
||||
String output = "Added $" + currencyCount + " to your account";
|
||||
ctx.getSource().sendSuccess(() -> Component.literal(output), false);
|
||||
} else {
|
||||
CelestianUtils.dropItem(currencyCount, player);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user