Search in sources :

Example 1 with Item

use of gartham.c10ver.economy.items.Item in project c10ver by Gartham.

the class AddCommand method exec.

@Override
public void exec(CommandInvocation inv) {
    var ecouser = trade.getManager().getClover().getEconomy().getUser(inv.event.getAuthor().getId());
    UserEntry<?> e;
    ENTRY_FINDER: {
        try {
            int x = Integer.parseInt(inv.args[0]) - 1;
            if (ecouser.getInventory().getEntryCount() < x) {
                e = ecouser.getInventory().get(x);
                break ENTRY_FINDER;
            } else {
                trade.getInitialChannel().sendMessage(inv.event.getAuthor().getAsMention() + ", you only have `" + ecouser.getInventory().getEntryCount() + "` items! Please use a number between `1` and `" + ecouser.getInventory().getEntryCount() + "` or use the item's ID.").queue();
                return;
            }
        } catch (NumberFormatException e1) {
        }
        if ((e = ecouser.getInventory().get(inv.args[0])) == null)
            if ((e = ecouser.getInventory().get(inv.args[0].toLowerCase(Locale.ENGLISH))) == null) {
                inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + ", you don't have any items with that ID.").queue();
                return;
            }
    }
    BigInteger amt;
    final UserEntry<?>.UserItemStack i;
    if (inv.args.length == 0) {
        // +loot-crate
        amt = BigInteger.ONE;
        i = e.get(0);
    } else if (inv.args.length == 1) {
        if (e.getStacks().size() == 1) {
            amt = BigInteger.ONE;
            i = e.get(0);
        } else {
            inv.event.getChannel().sendMessage("You need to specify which of that item you want to add. (There are different types of `" + e.getName() + "` items.)");
            return;
        }
    } else if (// +item 7
    inv.args.length == 2)
        if (e.getStacks().size() == 1) {
            // +pizza 3
            try {
                amt = new BigInteger(inv.args[1]);
            } catch (NumberFormatException e2) {
                // If item does not have more stacks.
                int amount = (int) (Math.random() * 10) + 1;
                inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " please provide an amount: `" + Utilities.strip(inv.cmdName + inv.args[0] + ' ' + amount) + "` for `" + amount + "` items.").queue();
                return;
            }
            if (amt.compareTo(BigInteger.ONE) < 0) {
                // If amt < 1
                inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " you can't add less than 1 items to a trade...").queue();
                return;
            }
            i = e.get(0);
        } else {
            // +loot-crate 2
            int x;
            try {
                x = Integer.parseInt(inv.args[1]);
            } catch (NumberFormatException e2) {
                inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " please specify which type of that item you want to trade. For example, `+" + e.getType() + " 1` to add some of the first type of that item, or: `+" + e.getType() + " 2` to add some of the second.").queue();
                return;
            }
            if (x > e.getStacks().size()) {
                inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " that's not a valid index! You only have `" + e.getStacks().size() + "` different types of that item.").queue();
                return;
            }
            if (x < 1) {
                inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " that's not a valid index! Indices must be greater than 0.");
                return;
            }
            i = e.get(x - 1);
            amt = BigInteger.ONE;
        }
    else if (inv.args.length == 3) {
        // + item 3 9
        // For two numbers, the index is always first.
        int x;
        try {
            x = Integer.parseInt(inv.args[1]);
        } catch (NumberFormatException e1) {
            inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " the index has to be a number.").queue();
            return;
        }
        if (x > e.getStacks().size()) {
            inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " that's not a valid index! You only have `" + e.getStacks().size() + "` different types of that item.").queue();
            return;
        }
        if (x < 1) {
            inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " that's not a valid index! Indices must be greater than 0.").queue();
            return;
        }
        i = e.get(x - 1);
        try {
            amt = new BigInteger(inv.args[2]);
        } catch (NumberFormatException e2) {
            // If item does not have more stacks.
            int amount = (int) (Math.random() * 10) + 1;
            inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " please provide an amount: `" + Utilities.strip(inv.cmdName + inv.args[0] + ' ' + amount) + "` for `" + amount + "` items.").queue();
            return;
        }
        if (amt.compareTo(BigInteger.ONE) < 0) {
            // If amt < 1
            inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " you can't add less than 1 items to a trade...").queue();
            return;
        }
    } else {
        inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " too many arguments. Please provide only an amount and an index.").queue();
        return;
    }
    BigInteger total = amt;
    var person = trade.isRecipient(inv.event.getAuthor()) ? trade.getRecip() : trade.getRequester();
    if (person.getItems().get((Item) i.getItem()) != null)
        total = amt.add(person.getItems().get((Item) i.getItem()).getCount());
    if (total.compareTo(i.count()) > 0) {
        inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " you don't have enough items to add that many to the trade.").queue();
        return;
    }
    trade.getRequester().setFinished(false);
    trade.getRecip().setFinished(false);
    person.getItems().add((Item) i.getItem(), amt);
    inv.event.getChannel().sendMessage(inv.event.getAuthor().getAsMention() + " added `" + amt + "` of that item to the trade! Here's what you've listed so far: ").setEmbeds(person.getTrade(new EmbedBuilder()).build()).queue();
}
Also used : Item(gartham.c10ver.economy.items.Item) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) BigInteger(java.math.BigInteger) UserEntry(gartham.c10ver.economy.items.UserInventory.UserEntry)

Aggregations

Item (gartham.c10ver.economy.items.Item)1 UserEntry (gartham.c10ver.economy.items.UserInventory.UserEntry)1 BigInteger (java.math.BigInteger)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1