Search in sources :

Example 11 with Player

use of net.kodehawa.mantarobot.data.entities.Player in project MantaroBot by Mantaro.

the class MoneyCmds method daily.

@Command
public static void daily(CommandRegistry cr) {
    RateLimiter rateLimiter = new RateLimiter(TimeUnit.HOURS, 24);
    Random r = new Random();
    cr.register("daily", new SimpleCommand(Category.CURRENCY) {

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            String id = event.getAuthor().getId();
            long money = 150L;
            User mentionedUser = null;
            try {
                mentionedUser = event.getMessage().getMentionedUsers().get(0);
            } catch (IndexOutOfBoundsException ignored) {
            }
            Player player;
            if (!rateLimiter.process(id)) {
                event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Halt! You can only do this once every 24 hours.\n**You'll be able to use this command again in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(id)) + ".**").queue();
                return;
            }
            if (mentionedUser != null && !mentionedUser.getId().equals(event.getAuthor().getId())) {
                money = money + r.nextInt(2);
                player = MantaroData.db().getPlayer(event.getGuild().getMember(mentionedUser));
                if (player.getInventory().containsItem(Items.COMPANION))
                    money = Math.round(money + (money * 0.10));
                if (mentionedUser.getId().equals(player.getData().getMarriedWith()) && player.getData().getMarriedSince() != null && Long.parseLong(player.getData().anniversary()) - player.getData().getMarriedSince() > TimeUnit.DAYS.toMillis(1)) {
                    money = money + r.nextInt(20);
                    if (player.getInventory().containsItem(Items.RING_2)) {
                        money = money + r.nextInt(10);
                    }
                }
                player.addMoney(money);
                player.save();
                event.getChannel().sendMessage(EmoteReference.CORRECT + "I gave your **$" + money + "** daily credits to " + mentionedUser.getName()).queue();
                return;
            }
            player = MantaroData.db().getPlayer(event.getMember());
            player.addMoney(money);
            player.save();
            event.getChannel().sendMessage(EmoteReference.CORRECT + "You got **$" + money + "** daily credits.").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Daily command").setDescription("**Gives you $150 credits per day (or between 150 and 180 if you transfer it to another person)**.").build();
        }
    });
}
Also used : Player(net.kodehawa.mantarobot.data.entities.Player) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Aggregations

Player (net.kodehawa.mantarobot.data.entities.Player)11 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)9 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)8 Command (net.kodehawa.mantarobot.modules.Command)8 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)8 User (net.dv8tion.jda.core.entities.User)5 RateLimiter (net.kodehawa.mantarobot.commands.currency.RateLimiter)5 Item (net.kodehawa.mantarobot.commands.currency.item.Item)3 ItemStack (net.kodehawa.mantarobot.commands.currency.item.ItemStack)3 DBUser (net.kodehawa.mantarobot.data.entities.DBUser)3 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 Member (net.dv8tion.jda.core.entities.Member)2 TextChannelGround (net.kodehawa.mantarobot.commands.currency.TextChannelGround)2 MantaroData (net.kodehawa.mantarobot.data.MantaroData)2 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)2 Module (net.kodehawa.mantarobot.modules.Module)2 Category (net.kodehawa.mantarobot.modules.commands.base.Category)2 PostLoadEvent (net.kodehawa.mantarobot.modules.events.PostLoadEvent)2 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)2 StringUtils (br.com.brjdevs.java.utils.texts.StringUtils)1