package nautilus.game.arcade.managers; import java.util.ArrayList; import java.util.HashMap; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.Game.GameState; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; public class GameTournamentManager implements Listener { ArcadeManager Manager; private HashMap _tournamentTeam = new HashMap(); private HashMap _tournamentPoints = new HashMap(); public GameTournamentManager(ArcadeManager manager) { Manager = manager; Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); } @EventHandler public void TeamTournamentAutoJoin(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; Game game = Manager.GetGame(); if (game == null) return; if (game.GetState() != GameState.Recruit) return; for (Player player : UtilServer.getPlayers()) rejoinTournamentTeam(player); } public void setTournamentTeam(Player player, GameTeam team) { if (!Manager.IsTeamRejoin()) return; _tournamentTeam.put(player.getName(), team.GetName()); } public void rejoinTournamentTeam(Player player) { if (Manager.GetGame() == null) return; if (!_tournamentTeam.containsKey(player.getName())) return; GameTeam curPref = Manager.GetGame().GetTeamPreference(player); if (curPref != null) return; GameTeam curTeam = Manager.GetGame().GetTeam(player); if (curTeam != null) return; String teamName = _tournamentTeam.get(player.getName()); for (GameTeam team : Manager.GetGame().GetTeamList()) { if (team.GetName().equalsIgnoreCase(teamName)) { Manager.GetGamePlayerManager().AddTeamPreference(Manager.GetGame(), player, team); break; } } } @EventHandler public void pointsReward(GameStateChangeEvent event) { if (!Manager.IsTournamentPoints()) return; if (event.GetState() != GameState.End) return; ArrayList places = event.GetGame().GetTeamList().get(0).GetPlacements(true); for (int i=0 ; i ranks = new ArrayList(); while (ranks.size() < _tournamentPoints.size()) { int bestPoints = 0; String bestPlayer = null; for (String cur : _tournamentPoints.keySet()) { if (ranks.contains(cur)) continue; int points = _tournamentPoints.get(cur); if (points == 0) continue; if (bestPlayer == null || points < bestPoints) { bestPlayer = cur; bestPoints = points; } } if (bestPlayer == null) break; ranks.add(bestPlayer); } Bukkit.broadcastMessage(C.cBlue + C.Strike + C.Bold + "--------------------------------------------"); for (int i=0 ; i