public List<Session> getTop() { List<Session> map = new ArrayList<Session>(); for (Session session : HyperPVP.getGameSessions().values()) { map.add(session); } Comparator<Session> comparator = new Comparator<Session>() { public int compare(Session c1, Session c2) { if (c1.getKills() < c2.getKills()) { return 1; } if (c1.getKills() > c2.getKills()) { return -1; } return -1; } }; Collections.sort(map, comparator); return map; }
public List<Session> getTeamMembers(ChatColor color) { List<Session> sessions = new ArrayList<Session>(); for (Session session : HyperPVP.getGameSessions().values()) { if (session.getTeam() != null && session.getTeam().getColor() == color) { sessions.add(session); } } return sessions; }
@SuppressWarnings("deprecation") public void leaveGame(Player player, boolean normalLeave) { player.setGameMode(GameMode.CREATIVE); // player.setAllowFlight(true); player.setHealth(20.0); player.setFoodLevel(20); player.setLevel(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } // Session session = HyperPVP.getSession(player); // session.setInterruptThread(true); if (normalLeave) { player.sendMessage(ChatColor.AQUA + "You are now spectating!"); HyperPVP.setListName(ChatColor.AQUA, player); player.getInventory().clear(); player.updateInventory(); } CycleUtil.addSpectator(player, normalLeave); HyperPVP.getGameSessions().remove(player.getName()); CycleUtil.hidePlayerWhereAppropriate(player, false); player.getInventory().setHelmet(null); player.getInventory().setBoots(null); player.getInventory().setChestplate(null); player.getInventory().setLeggings(null); try { HyperPVP.getStorage() .executeQuery( "UPDATE servers SET team_one = '" + this.getTeamMembers(this.teams.get(0).getColor()).size() + "' WHERE bungee_name = '" + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase() + "'"); if (this.type != GameType.FFA) { HyperPVP.getStorage() .executeQuery( "UPDATE servers SET team_two = '" + this.getTeamMembers(this.teams.get(1).getColor()).size() + "' WHERE bungee_name = '" + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase() + "'"); } } catch (SQLException e) { e.printStackTrace(); } }
public Location getRandomSpawn(ChatColor color) { try { List<GameSpawns> coords = this.getTeamCoords(color); GameSpawns coordSpawn = null; if (coords.size() == 1) { coordSpawn = coords.get(0); } else { coordSpawn = coords.get(HyperPVP.getRandom().nextInt(coords.size())); } Location gameSpawn = new Location(this.world, coordSpawn.getX(), coordSpawn.getY(), coordSpawn.getZ()); return gameSpawn; } catch (Exception e) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "reload"); } return null; }
public int getCounter() { return HyperPVP.getSpectators().size(); }
public Location getRandomSpawn(Player player) { ChatColor color = HyperPVP.getSession(player).getTeam().getColor(); return this.getRandomSpawn(color); }
public String matchInfoToString(CommandSender player) { StringBuilder builder = new StringBuilder(); player.sendMessage( ChatColor.RED + "------------------ " + ChatColor.AQUA + "Match Info" + ChatColor.RED + " ------------------"); if (HyperPVP.getMap().getType() == GameType.TDM || HyperPVP.getMap().getType() == GameType.DTM || HyperPVP.getMap().getType() == GameType.DTC || HyperPVP.getMap().getType() == GameType.RTC) { player.sendMessage( ChatColor.DARK_AQUA + "Time: " + ChatColor.AQUA + HyperPVP.getTimeString()); TeamMap one = this.teams.get(0); TeamMap two = this.teams.get(1); player.sendMessage( one.getColor() + HyperPVP.capitalize( one.getColor().name().toLowerCase().replace("_", " ").replace("dark ", "")) + ChatColor.GRAY + " kills: " + ChatColor.WHITE + one.getKills() + " | " + two.getColor() + HyperPVP.capitalize( two.getColor().name().toLowerCase().replace("_", " ").replace("dark ", "")) + ChatColor.GRAY + " kills: " + ChatColor.WHITE + two.getKills() + " | " + ChatColor.AQUA + "Observers" + ChatColor.GRAY + ": " + ChatColor.WHITE + HyperPVP.getSpectators().size()); player.sendMessage(""); String goal = ""; if (HyperPVP.getMap().getType() == GameType.TDM) { goal = ChatColor.AQUA + "(Team Death Match) Get your team the most kills."; } if (HyperPVP.getMap().getType() == GameType.DTM) { goal = ChatColor.AQUA + "(Destroy The Monument) Destory all of other teams obsidian."; } if (HyperPVP.getMap().getType() == GameType.DTC) { goal = ChatColor.AQUA + "(Destroy The Core) Leak their obisdian core."; } if (HyperPVP.getMap().getType() == GameType.RTC) { goal = ChatColor.AQUA + "(Race To Core) Be the first team to destroy the core in the middle."; } player.sendMessage( ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Goal: " + ChatColor.RESET + goal); } if (HyperPVP.getMap().getType() == GameType.FFA) { player.sendMessage( ChatColor.DARK_AQUA + "Time: " + ChatColor.AQUA + HyperPVP.getTimeString()); player.sendMessage(""); player.sendMessage( ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Goal: " + ChatColor.RESET + ChatColor.AQUA + "Kill everyone, get the highest kill score."); player.sendMessage(""); List<Session> topPlayers = HyperPVP.getMap().getTop(); if (topPlayers.size() != 0) { int i = 1; for (Session set : topPlayers) { if (i > 10 && set.getKills() != 0) { continue; } player.sendMessage( i + ". " + ChatColor.GOLD + set.getPlayer().getName() + ChatColor.WHITE + " with " + set.getKills() + "!"); i++; } } } return builder.toString(); }
@SuppressWarnings("deprecation") public void joinGame(Player player, String name) { int rank = 1; try { rank = HyperPVP.getStorage() .readInt32("SELECT rank FROM users WHERE username = '******'"); } catch (SQLException e) { e.printStackTrace(); } if (this.type == GameType.FFA) { List<Session> first = this.getTeamMembers(this.teams.get(0).getColor()); if (first.size() >= this.maxPlayers && rank == 1) { System.out.println(this.maxPlayers); player.sendMessage( ChatColor.RED + "Teams full - " + ChatColor.GOLD + "hyperpvp.us/shop" + ChatColor.GREEN + " to join full teams or view other servers at " + ChatColor.GREEN + "hyperpvp.us/servers"); return; } } else { List<Session> first = this.getTeamMembers(this.teams.get(0).getColor()); List<Session> second = this.getTeamMembers(this.teams.get(1).getColor()); if ((first.size() + second.size()) >= this.maxPlayers && rank == 1) { System.out.println(this.maxPlayers); player.sendMessage( ChatColor.RED + "Teams full - " + ChatColor.GOLD + "hyperpvp.us/shop" + ChatColor.GREEN + " to join full teams or view other servers at " + ChatColor.GREEN + "hyperpvp.us/servers"); return; } } for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } if (HyperPVP.hasMatchBeenAnnounced()) { player.setGameMode(GameMode.SURVIVAL); } else { player.setGameMode(GameMode.CREATIVE); } player.getInventory().clear(); player.updateInventory(); Session session = new Session(player); HyperPVP.getSpectators().remove(player.getName()); CycleUtil.addGameSession(player, session); if (this.type == GameType.FFA) { session.setTeam(this.teams.get(0)); } else { if (name != null) { TeamMap team = this.getTeamByName(name); session.setTeam(team); } else { List<Session> first = this.getTeamMembers(this.teams.get(0).getColor()); List<Session> second = this.getTeamMembers(this.teams.get(1).getColor()); if (first.size() == second.size()) { session.setTeam(this.teams.get(0)); } else { if (first.size() > second.size()) { session.setTeam(this.teams.get(1)); } else session.setTeam(this.teams.get(0)); } } } /*if (HyperPVP.hasMatchBeenAnnounced()) { player.sendMessage(this.matchInfoToString(player)); }*/ player.sendMessage( ChatColor.GRAY + "You joined the " + session.getTeam().getColor() + HyperPVP.capitalize( session .getTeam() .getColor() .name() .toLowerCase() .replace("_", " ") .replace("dark ", "")) + " Team"); HyperPVP.setListName(session.getTeam().getColor(), player); TagAPI.refreshPlayer(player); player.setFallDistance(0F); if (HyperPVP.hasMatchBeenAnnounced()) { CycleUtil.hidePlayerWhereAppropriate(player, true); player.teleport(this.getRandomSpawn(player)); } if (!HyperPVP.hasMatchBeenAnnounced()) { player.getInventory().clear(); player.getInventory().addItem(new ItemStack(Material.COMPASS, 1)); player.updateInventory(); player.closeInventory(); } try { HyperPVP.getStorage() .executeQuery( "UPDATE servers SET team_one = '" + this.getTeamMembers(this.teams.get(0).getColor()).size() + "' WHERE bungee_name = '" + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase() + "'"); if (this.type != GameType.FFA) { HyperPVP.getStorage() .executeQuery( "UPDATE servers SET team_two = '" + this.getTeamMembers(this.teams.get(1).getColor()).size() + "' WHERE bungee_name = '" + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase() + "'"); } } catch (SQLException e) { e.printStackTrace(); } System.out.println(session.toValue()); }