use of com.ebicep.warlords.game.state.PreLobbyState 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.state.PreLobbyState in project Warlords by ebicep.
the class WarlordsEvents method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player player = e.getPlayer();
Action action = e.getAction();
Location location = player.getLocation();
WarlordsPlayer wp = Warlords.getPlayer(player);
if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
ItemStack itemHeld = player.getItemInHand();
if (wp != null && wp.isAlive() && !wp.getGame().isFrozen()) {
if (player.getInventory().getHeldItemSlot() == 7 && itemHeld.getType() == Material.GOLD_BARDING && player.getVehicle() == null && wp.getHorseCooldown() <= 0) {
if (!Utils.isMountableZone(location) || Utils.blocksInFrontOfLocation(location)) {
player.sendMessage(ChatColor.RED + "You can't mount here!");
} else {
double distance = player.getLocation().getY() - player.getWorld().getHighestBlockYAt(player.getLocation());
if (distance > 2) {
player.sendMessage(ChatColor.RED + "You can't mount in the air!");
} else if (wp.getCarriedFlag() != null) {
player.sendMessage(ChatColor.RED + "You can't mount while holding the flag!");
} else {
player.playSound(player.getLocation(), "mountup", 1, 1);
wp.getHorse().spawn();
wp.setHorseCooldown(wp.getHorse().getCooldown());
}
}
} else if (itemHeld.getType() == Material.BONE) {
player.getInventory().remove(UndyingArmy.BONE);
wp.addDamageInstance(Warlords.getPlayer(player), "", 100000, 100000, -1, 100, false);
} else if (itemHeld.getType() == Material.BANNER) {
if (wp.getFlagCooldown() > 0) {
player.sendMessage("§cYou cannot drop the flag yet, please wait 5 seconds!");
} else if (wp.getCooldownManager().hasCooldown(TimeWarp.class)) {
player.sendMessage(ChatColor.RED + "You cannot drop the flag with a Time Warp active!");
} else {
FlagHolder.dropFlagForPlayer(wp);
wp.setFlagCooldown(5);
}
} else if (itemHeld.getType() == Material.COMPASS) {
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 2);
wp.toggleTeamFlagCompass();
} else if (player.getInventory().getHeldItemSlot() == 0 || !Warlords.getPlayerSettings(wp.getUuid()).getHotKeyMode()) {
wp.getSpec().onRightClick(wp, player);
}
} else {
PreLobbyState state = Warlords.getGameManager().getPlayerGame(player.getUniqueId()).flatMap(g -> g.getState(PreLobbyState.class)).orElse(null);
if (state != null) {
state.interactEvent(player, player.getInventory().getHeldItemSlot());
} else if (itemHeld.getType() == Material.NETHER_STAR) {
// menu
openMainMenu(player);
} else if (itemHeld.getType() == Material.EMERALD) {
// wl command
Bukkit.getServer().dispatchCommand(player, "wl");
} else if (itemHeld.getType() == Material.BLAZE_POWDER) {
openMapsMenu(player);
} else if (itemHeld.getType() == Material.WOOL) {
if (itemHeld.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Team Builder")) {
Warlords.partyManager.getPartyFromAny(player.getUniqueId()).ifPresent(party -> {
List<RegularGamesMenu.RegularGamePlayer> playerList = party.getRegularGamesMenu().getRegularGamePlayers();
if (!playerList.isEmpty()) {
party.getRegularGamesMenu().openMenuForPlayer(player);
new BukkitRunnable() {
@Override
public void run() {
if (player.getOpenInventory().getTopInventory().getName().equals("Team Builder")) {
party.getRegularGamesMenu().openMenuForPlayer(player);
} else {
this.cancel();
}
}
}.runTaskTimer(Warlords.getInstance(), 20, 10);
}
});
}
}
}
} else if (action == Action.LEFT_CLICK_BLOCK || action == Action.LEFT_CLICK_AIR) {
if (action == Action.LEFT_CLICK_AIR) {
}
}
}
Aggregations