use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.
the class BotManager method sendStatusMessage.
public static void sendStatusMessage(boolean onQuit) {
if (!Warlords.serverIP.equals("51.81.49.127")) {
return;
}
DateFormat dateFormat = new SimpleDateFormat("hh:mm aa");
dateFormat.setTimeZone(TimeZone.getTimeZone("EST"));
EmbedBuilder eb = new EmbedBuilder().setTitle("Server Status", null).setColor(3066993).setFooter(dateFormat.format(new Date()) + " EST");
eb.setDescription("**Players Online**: " + (onQuit ? Bukkit.getOnlinePlayers().size() - 1 : Bukkit.getOnlinePlayers().size()) + "\n");
eb.appendDescription("**Players In Game**: " + Warlords.getGameManager().getPlayerCount() + "\n");
eb.appendDescription("**Players Waiting in lobby**: " + Warlords.getGameManager().getPlayerCountInLobby() + "\n");
for (GameHolder holder : Warlords.getGameManager().getGames()) {
Game game = holder.getGame();
if (game == null) {
eb.appendDescription("**Game**: " + holder.getMap().getMapName() + " Inactive\n");
} else {
if (game.getState() instanceof PreLobbyState) {
PreLobbyState state = (PreLobbyState) game.getState();
if (!state.hasEnoughPlayers()) {
eb.appendDescription("**Game**: " + game.getMap().getMapName() + " Lobby - Waiting for players" + "\n");
} else {
eb.appendDescription("**Game**: " + game.getMap().getMapName() + " Lobby - " + state.getTimeLeftString() + " Left" + "\n");
}
} else if (game.getState() instanceof PlayingState) {
OptionalInt timeLeft = WinAfterTimeoutOption.getTimeLeft(game);
String time = Utils.formatTimeLeft(timeLeft.isPresent() ? timeLeft.getAsInt() : (System.currentTimeMillis() - game.createdAt()) / 1000);
String word = timeLeft.isPresent() ? " Left" : " Elapsed";
eb.appendDescription("**Game**: " + game.getMap().getMapName() + " - " + time + word + " - " + game.getPoints(Team.BLUE) + ":" + game.getPoints(Team.RED) + "\n");
} else {
eb.appendDescription("**Game**: Ending" + "\n");
}
}
}
StringBuilder stringBuilder = new StringBuilder("**Parties**: ");
Warlords.partyManager.getParties().forEach(party -> stringBuilder.append(party.getLeaderName()).append(" (").append(party.getPartyPlayers().size()).append("), "));
stringBuilder.setLength(stringBuilder.length() - 1);
eb.appendDescription(stringBuilder);
MessageEmbed messageEmbed = eb.build();
getTextChannelCompsByName(compGamesServerStatusChannel).ifPresent(textChannel -> {
if (compStatusMessage == null) {
textChannel.sendMessageEmbeds(messageEmbed).queue(m -> compStatusMessage = m);
} else if (textChannel.getLatestMessageId().equals(compStatusMessage.getId())) {
compStatusMessage.editMessageEmbeds(messageEmbed).queue();
} else {
compStatusMessage.delete().queue();
textChannel.sendMessageEmbeds(messageEmbed).queue(m -> compStatusMessage = m);
}
});
getTextChannelWL2ByName(wl2ServerStatusChannel).ifPresent(textChannel -> {
if (wl2StatusMessage == null) {
textChannel.sendMessageEmbeds(messageEmbed).queue(m -> wl2StatusMessage = m);
} else if (textChannel.getLatestMessageId().equals(wl2StatusMessage.getId())) {
wl2StatusMessage.editMessageEmbeds(messageEmbed).queue();
} else {
wl2StatusMessage.delete().queue();
textChannel.sendMessageEmbeds(messageEmbed).queue(m -> wl2StatusMessage = m);
}
});
}
use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.
the class GameKillCommand method doAction.
@Override
protected void doAction(CommandSender sender, Collection<GameHolder> gameInstances) {
sender.sendMessage(ChatColor.RED + "DEV:" + ChatColor.GRAY + " Requesting engine to kill games...");
if (gameInstances.isEmpty()) {
sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + "No valid targets found!");
return;
}
for (GameHolder holder : gameInstances) {
if (holder.getGame() == null) {
sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "The game is not active now");
continue;
}
holder.forceEndGame();
sender.sendMessage(ChatColor.GRAY + "- " + holder.getName() + ": " + ChatColor.RED + "Terminated");
}
}
use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.
the class GameListCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (!sender.hasPermission("warlords.game.list")) {
sender.sendMessage("§cYou do not have permission to do that.");
return true;
}
for (GameHolder holder : Warlords.getGameManager().getGames()) {
StringBuilder message = new StringBuilder();
message.append(ChatColor.GRAY).append("[").append(ChatColor.AQUA).append(holder.getName()).append(ChatColor.GRAY).append("|").append(ChatColor.AQUA).append(toTitleHumanCase(holder.getMap().name()));
Game game = holder.getGame();
if (game == null) {
message.append(']').append(ChatColor.GOLD).append(" <inactive>");
} else {
if (holder.getMap().getCategories().size() > 1) {
message.append(ChatColor.GRAY).append("/").append(ChatColor.AQUA).append(toTitleHumanCase(game.getGameMode()));
}
message.append(ChatColor.GRAY).append("] ");
// message.append('(').append(ChatColor.GOLD).append(game.getGameId()).append(ChatColor.GRAY).append(") ");
EnumSet<GameAddon> addons = game.getAddons();
if (!addons.isEmpty()) {
message.append(ChatColor.GRAY).append('(');
for (GameAddon addon : addons) {
message.append(ChatColor.GREEN).append(addon.name());
message.append(ChatColor.GRAY).append(',');
}
message.setLength(message.length() - 1);
message.append("] ");
}
message.append(ChatColor.GOLD).append(game.getState().getClass().getSimpleName()).append(ChatColor.GRAY).append(" [ ").append(ChatColor.GREEN).append(game.getPlayers().size()).append(ChatColor.GRAY).append("/").append(ChatColor.GREEN).append(game.getMinPlayers()).append(ChatColor.GRAY).append("..").append(ChatColor.GREEN).append(game.getMaxPlayers()).append(ChatColor.GRAY).append("] ");
OptionalInt timeLeft = WinAfterTimeoutOption.getTimeLeft(game);
String time = Utils.formatTimeLeft(timeLeft.isPresent() ? timeLeft.getAsInt() : (System.currentTimeMillis() - game.createdAt()) / 1000);
String word = timeLeft.isPresent() ? " Left" : " Elapsed";
message.append(time).append(word);
}
sender.sendMessage(message.toString());
}
return true;
}
use of com.ebicep.warlords.game.GameManager.GameHolder in project Warlords by ebicep.
the class SpectateCommand method openSpectateMenu.
public static void openSpectateMenu(Player player) {
Menu menu = new Menu("Current Games", 9 * 3);
int column = 0;
int row = 0;
for (GameHolder holder : Warlords.getGameManager().getGames()) {
Game game = holder.getGame();
if (game != null && game.acceptsSpectators()) {
menu.setItem(column, row, new ItemBuilder(Material.BOOK).name(ChatColor.GREEN + "Game " + game.getGameId()).lore(ChatColor.DARK_GRAY + "Map - " + ChatColor.RED + game.getMap().getMapName(), ChatColor.DARK_GRAY + "GameMode - " + ChatColor.RED + game.getGameMode(), ChatColor.DARK_GRAY + "Addons - " + ChatColor.RED + game.getAddons(), ChatColor.DARK_GRAY + "Players - " + ChatColor.RED + game.playersCount()).get(), (m, e) -> {
if (game.isClosed()) {
player.sendMessage(ChatColor.RED + "This game is no longer running");
openSpectateMenu(player);
return;
}
if (!game.acceptsSpectators()) {
player.sendMessage(ChatColor.RED + "This game does not accepts spectators");
openSpectateMenu(player);
return;
}
Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
if (currentGame.isPresent() && currentGame.get().getPlayerTeam(player.getUniqueId()) != null) {
player.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
} else if (currentGame.isPresent() && currentGame.get().equals(game)) {
player.sendMessage(ChatColor.RED + "You are already spectating this game");
} else {
if (currentGame.isPresent()) {
currentGame.get().removePlayer(player.getUniqueId());
}
game.addPlayer(player, true);
}
});
column++;
if (column > 8) {
column = 0;
row++;
}
}
}
Optional<Game> currentGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
if (currentGame.isPresent()) {
menu.setItem(4, 2, new ItemBuilder(Material.BARRIER).name(ChatColor.GREEN + "Return to the lobby").get(), (m, e) -> {
Optional<Game> currentGame1 = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
if (currentGame1.isPresent() && currentGame1.get().getPlayerTeam(player.getUniqueId()) != null) {
player.sendMessage(ChatColor.RED + "You cannot use this command inside a game!");
} else {
currentGame1.get().removePlayer(player.getUniqueId());
}
});
}
menu.openForPlayer(player);
}
use of com.ebicep.warlords.game.GameManager.GameHolder 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...");
}
Aggregations