package nautilus.game.arcade; import java.io.File; import java.util.ArrayList; import java.util.HashSet; import nautilus.game.arcade.addons.*; import nautilus.game.arcade.command.*; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameServerConfig; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.managers.*; import nautilus.game.arcade.shop.ArcadeShop; import nautilus.game.arcade.world.FireworkHandler; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.ServerListPingEvent; import mineplex.minecraft.game.classcombat.Class.ClassManager; import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager; import mineplex.minecraft.game.classcombat.Skill.SkillFactory; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; import mineplex.minecraft.game.classcombat.item.ItemFactory; import mineplex.minecraft.game.classcombat.item.event.ItemTriggerEvent; import mineplex.minecraft.game.classcombat.shop.ClassCombatShop; import mineplex.minecraft.game.classcombat.shop.ClassShopManager; import mineplex.minecraft.game.core.IRelation; import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; import mineplex.core.MiniPlugin; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.account.CoreClientManager; import mineplex.core.antihack.AntiHack; import mineplex.core.antistack.AntiStack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blood.Blood; import mineplex.core.chat.Chat; import mineplex.core.common.Rank; import mineplex.core.common.util.*; import mineplex.core.creature.Creature; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.movement.Movement; import mineplex.core.packethandler.PacketHandler; import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.explosion.Explosion; import mineplex.core.portal.Portal; import mineplex.core.projectile.ProjectileManager; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; public class ArcadeManager extends MiniPlugin implements IRelation { //Modules private AntiStack _antistack; private BlockRestore _blockRestore; private Blood _blood; private Chat _chat; private CoreClientManager _clientManager; private DisguiseManager _disguiseManager; private DonationManager _donationManager; private ConditionManager _conditionManager; private Creature _creature; private DamageManager _damageManager; private Explosion _explosionManager; private Fire _fire; private FireworkHandler _firework; private ProjectileManager _projectileManager; private Portal _portal; private ArcadeShop _arcadeShop; //Managers private GameFactory _gameFactory; private GameCreationManager _gameCreationManager; private GameGemManager _gameGemManager; private GameManager _gameManager; private GameLobbyManager _gameLobbyManager; private GameStatsManager _gameStatsManager; private GameWorldManager _gameWorldManager; private StatsManager _statsManager; private ClassManager _classManager; private SkillFactory _skillFactory; private ClassShopManager _classShopManager; private ClassCombatShop _classShop; private EloManager _eloManager; private MiscManager _miscManager; //Observers private HashSet _specList = new HashSet(); //Server Games private GameServerConfig _serverConfig; //Games private Game _game; public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig, CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack, Portal portal, PacketHandler packetHandler, String webAddress) { super("Game Manager", plugin); _serverConfig = serverConfig; if (serverConfig.Tournament) { AntiHack.Instance.SetEnabled(false); } //Modules _antistack = antistack; _blockRestore = new BlockRestore(plugin); _blood = blood; _explosionManager = new Explosion(plugin, _blockRestore); _explosionManager.SetDebris(false); if (serverConfig.GameList.contains(GameType.ChampionsDominate) || serverConfig.GameList.contains(GameType.ChampionsTDM) || serverConfig.GameList.contains(GameType.ChampionsMOBA)) { _conditionManager = new SkillConditionManager(plugin); } else { _conditionManager = new ConditionManager(plugin); } _clientManager = clientManager; _chat = new Chat(plugin, _clientManager, serverStatusManager.getCurrentServerName()); _creature = creature; _damageManager = damageManager; _damageManager.UseSimpleWeaponDamage = true; _disguiseManager = disguiseManager; _donationManager = donationManager; _firework = new FireworkHandler(); _fire = new Fire(plugin, _conditionManager, damageManager); _projectileManager = new ProjectileManager(plugin); if (serverConfig.GameList.contains(GameType.ChampionsDominate) || serverConfig.GameList.contains(GameType.ChampionsTDM) || serverConfig.GameList.contains(GameType.ChampionsMOBA)) { Energy energy = new Energy(plugin); _skillFactory = new SkillFactory(plugin, damageManager, this, _damageManager.GetCombatManager(), _conditionManager, _projectileManager, _blockRestore, _fire, new Movement(plugin), teleport, energy, webAddress); _classManager = new ClassManager(plugin, clientManager, donationManager, _skillFactory, webAddress); _classShopManager = new ClassShopManager(_plugin, _classManager, _skillFactory, new ItemFactory(_plugin, _blockRestore, _classManager, _conditionManager, damageManager, energy, _fire, _projectileManager, webAddress)); _classShop = new ClassCombatShop(_classShopManager, clientManager, donationManager, webAddress); _eloManager = new EloManager(_plugin); } //_statsManager = new StatsManager(plugin); _portal = portal; //Shop _arcadeShop = new ArcadeShop(this, clientManager, donationManager); //Game Factory _gameFactory = new GameFactory(this); //Managers new GameChatManager(this); _gameCreationManager = new GameCreationManager(this); _gameGemManager = new GameGemManager(this); _gameManager = new GameManager(this); _gameLobbyManager = new GameLobbyManager(this, packetHandler); new GameFlagManager(this); new GamePlayerManager(this); _gameStatsManager = new GameStatsManager(this); _gameWorldManager = new GameWorldManager(this); _miscManager = new MiscManager(this); new IdleManager(this); //Game Addons new CompassAddon(plugin, this); new SoupAddon(plugin, this); new TeamArmorAddon(plugin, this); } @Override public void AddCommands() { AddCommand(new GameCommand(this)); AddCommand(new ParseCommand(this)); AddCommand(new WriteCommand(this)); } public GameServerConfig GetServerConfig() { return _serverConfig; } public ArrayList GetGameList() { return GetServerConfig().GameList; } public AntiStack GetAntiStack() { return _antistack; } public Blood GetBlood() { return _blood; } public Chat GetChat() { return _chat; } public BlockRestore GetBlockRestore() { return _blockRestore; } public CoreClientManager GetClients() { return _clientManager; } public ConditionManager GetCondition() { return _conditionManager; } public Creature GetCreature() { return _creature; } public DisguiseManager GetDisguise() { return _disguiseManager; } public DamageManager GetDamage() { return _damageManager; } public DonationManager GetDonation() { return _donationManager; } public EloManager getEloManager() { return _eloManager; } public Explosion GetExplosion() { return _explosionManager; } public Fire GetFire() { return _fire; } public FireworkHandler GetFirework() { return _firework; } public ProjectileManager GetProjectile() { return _projectileManager; } public Portal GetPortal() { return _portal; } public GameLobbyManager GetLobby() { return _gameLobbyManager; } public ArcadeShop GetShop() { return _arcadeShop; } public GameStatsManager GetStats() { return _gameStatsManager; } public GameCreationManager GetGameCreationManager() { return _gameCreationManager; } public GameFactory GetGameFactory() { return _gameFactory; } public GameManager GetGameManager() { return _gameManager; } public GameGemManager GetGameGemManager() { return _gameGemManager; } public GameWorldManager GetGameWorldManager() { return _gameWorldManager; } public StatsManager GetStatsManager() { return _statsManager; } public ChatColor GetColor(Player player) { if (_game == null) return ChatColor.GRAY; GameTeam team = _game.GetTeam(player); if (team == null) return ChatColor.GRAY; return team.GetColor(); } @Override public boolean CanHurt(String a, String b) { return CanHurt(UtilPlayer.searchExact(a), UtilPlayer.searchExact(b)); } public boolean CanHurt(Player pA, Player pB) { if (pA == null || pB == null) return false; if (!_game.Damage) return false; if (!_game.DamagePvP) return false; //Self Damage if (pA.equals(pB)) return _game.DamageSelf; GameTeam tA = _game.GetTeam(pA); if (tA == null) return false; GameTeam tB = _game.GetTeam(pB); if (tB == null) return false; if (tA.equals(tB) && !_game.DamageTeamSelf) return false; if (!tA.equals(tB) && !_game.DamageTeamOther) return false; return true; } @Override public boolean IsSafe(Player player) { if (_game == null) return true; if (_game.IsPlaying(player)) return false; return true; } @EventHandler public void MessageMOTD(ServerListPingEvent event) { if (this.IsTournamentServer()) { event.setMotd(ChatColor.RED + "Twitch.tv "+ ChatColor.YELLOW + "Charity Event"); return; } String extrainformation = "|" + _serverConfig.ServerType + "|" + (_game == null ? "Unknown" : _game.GetName()) + "|" + ((_game == null || _game.WorldData == null) ? "Unknown" : _game.WorldData.MapName); if (_game == null || _game.GetState() == GameState.Recruit) { if (_game != null && _game.GetType() == GameType.UHC) { event.setMotd(ChatColor.RED + "UHC - Season 5"); return; } if (_game != null && _game.GetCountdown() != -1) { event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds" + extrainformation); } else { event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation); } } else { event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation); } } @EventHandler public void MessageJoin(PlayerJoinEvent event) { if (_game == null || _game.AnnounceJoinQuit) event.setJoinMessage(F.sys("Join", event.getPlayer().getName())); else event.setJoinMessage(null); } @EventHandler public void MessageQuit(PlayerQuitEvent event) { if (_game == null || _game.AnnounceJoinQuit) event.setQuitMessage(F.sys("Quit", GetColor(event.getPlayer()) + event.getPlayer().getName())); else event.setQuitMessage(null); } public Game GetGame() { return _game; } public void SetGame(Game game) { _game = game; } public int GetPlayerMin() { return GetServerConfig().MinPlayers; } public int GetPlayerFull() { return GetServerConfig().MaxPlayers; } public void HubClock(Player player) { if (_game != null && !_game.GiveClock) return; player.getInventory().setItem(8, ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte)0, 1, (short)0, C.cGreen + "Return to Hub", new String[] {"", ChatColor.RESET + "Click while holding this", ChatColor.RESET + "to return to the Hub."})); } @EventHandler public void Login(PlayerLoginEvent event) { // Reserved Slot Check if (Bukkit.getOnlinePlayers().length >= Bukkit.getServer().getMaxPlayers()) { if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.ULTRA, false) || _donationManager.Get(event.getPlayer().getName()).OwnsUnknownPackage(_serverConfig.ServerType + " ULTRA")) { event.allow(); event.setResult(PlayerLoginEvent.Result.ALLOWED); return; } event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Full > Purchase Ultra at www.mineplex.com/shop"); } } public boolean IsAlive(Player player) { if (_game == null) return false; return _game.IsAlive(player); } public void Clear(Player player) { player.setGameMode(GameMode.SURVIVAL); player.setAllowFlight(false); UtilInv.Clear(player); ((CraftEntity)player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0)); player.setSprinting(false); player.setFoodLevel(20); player.setSaturation(3f); player.setExhaustion(0f); player.setMaxHealth(20); player.setHealth(player.getMaxHealth()); player.setFireTicks(0); player.setFallDistance(0); player.setLevel(0); player.setExp(0f); ((CraftPlayer)player).getHandle().spectating = false; ((CraftPlayer)player).getHandle().k = true; // Arrows go bye bye. ((CraftPlayer)player).getHandle().p(0); GetCondition().EndCondition(player, ConditionType.CLOAK, null); HubClock(player); GetDisguise().undisguise(player); } public ArrayList LoadFiles(String gameName) { File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "maps" + File.separatorChar + gameName); if (!folder.exists()) folder.mkdirs(); ArrayList maps = new ArrayList(); System.out.println("Searching Maps in: " + folder); for (File file : folder.listFiles()) { if (!file.isFile()) continue; String name = file.getName(); if (name.length() < 5) continue; name = name.substring(name.length()-4, name.length()); if (file.getName().equals(".zip")) continue; maps.add(file.getName().substring(0, file.getName().length()-4)); } for (String map : maps) System.out.println("Found Map: " + map); return maps; } public ClassManager getClassManager() { return _classManager; } public ClassCombatShop getClassShop() { return _classShop; } public void openClassShop(Player player) { _classShop.attemptShopOpen(player); } @EventHandler public void BlockBurn(BlockBurnEvent event) { if (_game == null) event.setCancelled(true); } @EventHandler public void BlockSpread(BlockSpreadEvent event) { if (_game == null) event.setCancelled(true); } @EventHandler public void BlockFade(BlockFadeEvent event) { if (_game == null) event.setCancelled(true); } @EventHandler public void BlockDecay(LeavesDecayEvent event) { if (_game == null) event.setCancelled(true); } @EventHandler public void MobSpawn(CreatureSpawnEvent event) { if (_game == null) event.setCancelled(true); } @EventHandler public void SkillTrigger(SkillTriggerEvent event) { if (_game == null || !_game.IsLive()) { event.SetCancelled(true); } } @EventHandler public void ItemTrigger(ItemTriggerEvent event) { if (_game == null || !_game.IsLive()) { event.SetCancelled(true); } } @EventHandler public void Observer(PlayerCommandPreprocessEvent event) { if (event.getMessage().equalsIgnoreCase("/spec")) { event.setCancelled(true); if (_game != null && _game.InProgress()) { UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot toggle Spectator during games.")); return; } if (!_specList.remove(event.getPlayer())) { _specList.add(event.getPlayer()); UtilPlayer.message(event.getPlayer(), F.main("Game", "You are now a Spectator!")); } else { UtilPlayer.message(event.getPlayer(), F.main("Game", "You are no longer a Spectator!")); } //Clean if (_game != null) { //Remove Data _game.RemoveTeamPreference(event.getPlayer()); _game.GetPlayerKits().remove(event.getPlayer()); _game.GetPlayerGems().remove(event.getPlayer()); //Leave Team GameTeam team = _game.GetTeam(event.getPlayer()); if (team != null) { team.RemovePlayer(event.getPlayer()); } } } } @EventHandler public void ObserverQuit(PlayerQuitEvent event) { _specList.remove(event.getPlayer()); } public boolean IsObserver(Player player) { return _specList.contains(player); } public boolean IsTournamentServer() { return _serverConfig.Tournament; } }