package org.royaldev.thehumanity.commands.impl;
import org.jetbrains.annotations.NotNull;
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.game.TheHumanityGame.GameEndCause;
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 java.util.List;
@Command(
name = "stopgame",
description = "Stops the game you're in, if you're an operator or the host in its channel.",
aliases = {"stop"}
)
public class StopGameCommand extends BaseCommand {
private final TheHumanity humanity;
public StopGameCommand(final TheHumanity instance) {
this.humanity = instance;
}
@Override
public void run(@NotNull ActorEvent<User> event, @NotNull CallInfo callInfo, @NotNull List<String> arguments) {
if (!(event instanceof ChannelMessageEvent)) return;
final User u = event.getActor();
final ChannelMessageEvent e = (ChannelMessageEvent) event;
final TheHumanityGame g = this.humanity.getGameRegistrar().find(e.getChannel());
if (g == null) {
u.sendNotice("No game in this channel!");
return;
}
final TheHumanityPlayer p = g.getPlayer(u);
if (!g.getHost().equals(p) && !this.humanity.hasChannelMode(g.getChannel(), u, 'o')) {
u.sendNotice("You're not an op or the host!");
return;
}
g.stop(GameEndCause.STOPPED_BY_COMMAND);
}
}