package org.royaldev.thehumanity.commands.impl; import com.google.common.base.Preconditions; import org.jetbrains.annotations.NotNull; import org.kitteh.irc.client.library.util.Format; import org.kitteh.irc.client.library.element.User; import org.kitteh.irc.client.library.event.channel.ChannelMessageEvent; import org.kitteh.irc.client.library.event.helper.ActorEvent; import org.royaldev.thehumanity.TheHumanity; import org.royaldev.thehumanity.game.TheHumanityGame; import org.royaldev.thehumanity.player.TheHumanityPlayer; import xyz.cardstock.cardstock.commands.BaseCommand; import xyz.cardstock.cardstock.commands.CallInfo; import xyz.cardstock.cardstock.commands.Command; import xyz.cardstock.cardstock.configuration.Server; import java.util.List; @Command( name = "join", description = "Joins the current game.", aliases = {"joingame"} ) public class JoinGameCommand extends BaseCommand { private final TheHumanity humanity; public JoinGameCommand(final TheHumanity humanity) { this.humanity = humanity; } @Override public void run(@NotNull ActorEvent<User> event, @NotNull CallInfo callInfo, @NotNull List<String> arguments) { if (!(event instanceof ChannelMessageEvent)) return; final ChannelMessageEvent e = (ChannelMessageEvent) event; final User u = e.getActor(); final TheHumanityGame g = this.humanity.getGameRegistrar().find(e.getChannel()); if (g == null) { final Server server = this.humanity.getClientServerMap().get(event.getClient()); Preconditions.checkNotNull(server); u.sendNotice("There's no game right now. Start one with " + Format.BOLD + server.getPrefix() + "start" + Format.RESET + "."); return; } if (g.hasPlayer(u.getNick())) { u.sendNotice("You can't join a game you're already in!"); return; } final TheHumanityPlayer p = g.createPlayer(u); if (p == null) { u.sendNotice("Could not join due to an internal error."); return; } g.addPlayer(p); } }