Search in sources :

Example 1 with GameLobby

use of net.kodehawa.mantarobot.commands.game.core.GameLobby in project MantaroBot by Mantaro.

the class GameCmds method startGame.

private static void startGame(Game game, GuildMessageReceivedEvent event) {
    if (GameLobby.LOBBYS.containsKey(event.getChannel())) {
        event.getChannel().sendMessage(EmoteReference.ERROR + "Cannot start a new game when there is a game currently running.").queue();
        return;
    }
    LinkedList<Game> list = new LinkedList<>();
    list.add(game);
    HashMap<Member, Player> map = new HashMap<>();
    map.put(event.getMember(), MantaroData.db().getPlayer(event.getMember()));
    if (!event.getMessage().getMentionedRoles().isEmpty()) {
        StringBuilder b = new StringBuilder();
        event.getMessage().getMentionedRoles().forEach(role -> event.getGuild().getMembersWithRoles(role).forEach(user -> {
            if (!user.getUser().getId().equals(event.getJDA().getSelfUser().getId()))
                map.put(user, MantaroData.db().getPlayer(user));
            b.append(user.getEffectiveName()).append(" ");
        }));
        event.getChannel().sendMessage(EmoteReference.MEGA + "Started a MP game with all users with the specfied role: " + b.toString()).queue();
    }
    if (!event.getMessage().getMentionedUsers().isEmpty()) {
        StringBuilder builder = new StringBuilder();
        event.getMessage().getMentionedUsers().forEach(user -> {
            if (!user.getId().equals(event.getJDA().getSelfUser().getId()))
                map.put(event.getGuild().getMember(user), MantaroData.db().getPlayer(event.getGuild().getMember(user)));
            builder.append(user.getName()).append(" ");
        });
        event.getChannel().sendMessage(EmoteReference.MEGA + "Started a MP game with users: " + builder.toString()).queue();
    }
    GameLobby lobby = new GameLobby(event, map, list);
    lobby.startFirstGame();
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) GameLobby(net.kodehawa.mantarobot.commands.game.core.GameLobby) Member(net.dv8tion.jda.core.entities.Member) ImageGuess(net.kodehawa.mantarobot.commands.game.ImageGuess) Game(net.kodehawa.mantarobot.commands.game.core.Game) Module(net.kodehawa.mantarobot.modules.Module) HashMap(java.util.HashMap) Category(net.kodehawa.mantarobot.modules.commands.base.Category) Trivia(net.kodehawa.mantarobot.commands.game.Trivia) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Pokemon(net.kodehawa.mantarobot.commands.game.Pokemon) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) LinkedList(java.util.LinkedList) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Player(net.kodehawa.mantarobot.data.entities.Player) Player(net.kodehawa.mantarobot.data.entities.Player) Game(net.kodehawa.mantarobot.commands.game.core.Game) GameLobby(net.kodehawa.mantarobot.commands.game.core.GameLobby) HashMap(java.util.HashMap) Member(net.dv8tion.jda.core.entities.Member) LinkedList(java.util.LinkedList)

Aggregations

HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Member (net.dv8tion.jda.core.entities.Member)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 ImageGuess (net.kodehawa.mantarobot.commands.game.ImageGuess)1 Pokemon (net.kodehawa.mantarobot.commands.game.Pokemon)1 Trivia (net.kodehawa.mantarobot.commands.game.Trivia)1 Game (net.kodehawa.mantarobot.commands.game.core.Game)1 GameLobby (net.kodehawa.mantarobot.commands.game.core.GameLobby)1 MantaroData (net.kodehawa.mantarobot.data.MantaroData)1 Player (net.kodehawa.mantarobot.data.entities.Player)1 Command (net.kodehawa.mantarobot.modules.Command)1 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)1 Module (net.kodehawa.mantarobot.modules.Module)1 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)1 Category (net.kodehawa.mantarobot.modules.commands.base.Category)1 PostLoadEvent (net.kodehawa.mantarobot.modules.events.PostLoadEvent)1 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)1