use of com.ebicep.warlords.game.Game in project Warlords by ebicep.
the class LobbyCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
Player player = BaseCommand.requirePlayer(sender);
if (player == null) {
return true;
}
Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
if (!currentGame.isPresent()) {
player.sendMessage(ChatColor.RED + "You are not in a game");
return true;
}
Game game = currentGame.get();
Team playerTeam = game.getPlayerTeam(player.getUniqueId());
if (playerTeam != null && !currentGame.get().acceptsPeople()) {
player.sendMessage(ChatColor.RED + "The game does not allow people to leave at the moment, you can only leave public games when in the lobby.");
} else {
game.removePlayer(player.getUniqueId());
}
return true;
}
use of com.ebicep.warlords.game.Game in project Warlords by ebicep.
the class SpectateCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
Player player = BaseCommand.requirePlayerOutsideGame(sender);
if (player != null) {
if (!Warlords.getGameManager().getGames().stream().anyMatch(e -> e.getGame() != null && e.getGame().acceptsSpectators())) {
sender.sendMessage(ChatColor.RED + "There are no active games right now!");
return true;
}
Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
if (currentGame.isPresent() && currentGame.get().getPlayerTeam(player.getUniqueId()) != null) {
sender.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
return true;
}
openSpectateMenu(player);
return true;
}
return true;
}
use of com.ebicep.warlords.game.Game in project Warlords by ebicep.
the class GameTargetCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (!command.testPermissionSilent(sender)) {
sender.sendMessage("§cYou do not have permission to do that.");
return true;
}
Collection<GameManager.GameHolder> gameInstances;
if (args.length == 0) {
WarlordsPlayer wp = BaseCommand.requireWarlordsPlayer(sender);
if (wp == null) {
return true;
}
gameInstances = getGames().stream().filter(e -> e.getGame() == wp.getGame()).collect(Collectors.toList());
if (gameInstances.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Unable to find the game that your are in!");
}
} else {
Set<GameManager.GameHolder> holder = new HashSet<>();
gameInstances = holder;
List<GameManager.GameHolder> matched = new ArrayList<>();
for (String arg : args) {
matched.clear();
for (GameManager.GameHolder h : getGames()) {
Game game = h.getGame();
if ("*".equals(arg) || h.getName().equalsIgnoreCase(arg) || h.getMap().name().equalsIgnoreCase(arg) || (game != null && game.getGameMode().name().equalsIgnoreCase(arg)) || (game != null && game.getGameId().toString().equalsIgnoreCase(arg))) {
matched.add(h);
}
}
if (matched.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Unable to find: " + arg);
continue;
}
holder.addAll(matched);
}
}
this.doAction(sender, gameInstances);
return true;
}
use of com.ebicep.warlords.game.Game in project Warlords by ebicep.
the class GameTerminateCommand method doAction.
@Override
protected void doAction(CommandSender sender, Collection<GameHolder> gameInstances) {
sender.sendMessage(ChatColor.RED + "DEV:" + ChatColor.GRAY + " Requesting engine to terminate games...");
if (gameInstances.isEmpty()) {
sender.sendMessage(ChatColor.RED + "No valid targets found!");
return;
}
for (GameHolder holder : gameInstances) {
Game game = holder.getGame();
if (game == null) {
sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "The game is not active now");
continue;
}
if (holder.getGame().isFrozen()) {
holder.getGame().clearFrozenCause();
}
Optional<PlayingState> state = game.getState(PlayingState.class);
if (!state.isPresent()) {
sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "The game is not in playing state, instead it is in " + game.getState().getClass().getSimpleName());
} else {
sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "Terminating game...");
game.setNextState(new EndState(game, null));
}
}
sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + "Game has been terminated. Warping back to lobby...");
}
use of com.ebicep.warlords.game.Game in project Warlords by ebicep.
the class BaseCommand method requireGame.
@Nullable
public static Game requireGame(@Nonnull CommandSender sender, @Nullable String name) {
Player p = requirePlayer(sender, name);
if (p == null) {
return null;
}
Optional<Game> playerGame = Warlords.getGameManager().getPlayerGame(((Player) sender).getUniqueId());
if (!playerGame.isPresent()) {
sender.sendMessage(ChatColor.RED + "You are not in a game!");
return null;
}
return playerGame.get();
}
Aggregations