package de.steamwar.fightsystem; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.utils.FightScoreboard; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.utils.WaterRemover; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.util.List; public class FightSystem extends JavaPlugin { public static final String PREFIX = "§eArena§8» "; private static FightSystem plugin; private static FightState fightState = FightState.SETUP; private static int fightTime = 0; @Override public void onLoad() { setPlugin(this); IFightSystem.init(this, PREFIX); } @Override public void onEnable() { Fight.init(); KitManager.loadAllKits(); new EntityDamageListener(); new EntityExplodeListener(); new FoodLevelChangeListener(); new PistonListener(); new PlayerChatListener(); new PlayerDeathListener(); new HotbarGUIListener(); new PlayerMoveListener(); new PlayerConnectionListener(); new PlayerRespawnListener(); new PlayerTeleportListener(); new ProjectileLaunchListener(); if(!Config.test()){ new BlockListener(); TechHider.init(); } FightScoreboard.init(); getCommand("leave").setExecutor(new LeaveCommand()); getCommand("kit").setExecutor(new KitCommand()); getCommand("remove").setExecutor(new RemoveCommand()); getCommand("accept").setExecutor(new AcceptCommand()); getCommand("decline").setExecutor(new DeclineCommand()); getCommand("invite").setExecutor(new InviteCommand()); getCommand("ready").setExecutor(new ReadyCommand()); getCommand("ak").setExecutor(new AkCommand()); getCommand("leader").setExecutor(new LeaderCommand()); getCommand("lockschem").setExecutor(new LockschemCommand()); if(Config.event()) { new EventJoinListener(); getCommand("invite").setExecutor(new EventDummyCommand()); getCommand("ready").setExecutor(new EventDummyCommand()); getCommand("ak").setExecutor(new EventDummyCommand()); getCommand("leader").setExecutor(new EventDummyCommand()); new EventStartCountdown(); }else if(Config.test()){ new TestListener(); Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0); Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0); new NoPlayersOnlineCountdown(); }else{ new NormalJoinListener(); new InventoryListener(); new NoPlayersOnlineCountdown(); } } public static void setPreRunningState() { if(fightState != FightState.SETUP) return; setFightState(FightState.PRE_RUNNING); Countdown.cancelAllTimers(); loadKits(Fight.getBlueTeam()); loadKits(Fight.getRedTeam()); setAllPlayersGM(GameMode.SURVIVAL); Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"); new PreRunningCountdown(); Fight.replaceSync(); new WinconditionAllDead(); new WinconditionCaptainDead(); new WinconditionWaterTechKO(); new WinconditionPercentSystem(); new WinconditionRelativePercent(); new WinconditionPoints(); if(Config.event()){ new EventTeamOffWincondition(); } } public static void setRunningState() { if(fightState != FightState.PRE_RUNNING) return; setFightState(FightState.RUNNING); Countdown.cancelAllTimers(); setAllPlayersGM(GameMode.SURVIVAL); new WinconditionTimeout(); new WinconditionHeartRatioTimeout(); new WinconditionEntern(); new WinconditionTechKO(); WaterRemover.init(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } public static void setSpectateState(FightTeam winFightTeam) { if(fightState != FightState.RUNNING && fightState != FightState.PRE_RUNNING) return; setFightState(FightState.SPECTATE); Countdown.cancelAllTimers(); setAllPlayersGM(GameMode.SPECTATOR); Fight.getBlueTeam().teleportToSpawn(); Fight.getRedTeam().teleportToSpawn(); Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().clear()); Bukkit.broadcastMessage(" "); if(winFightTeam != null) { Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); } else { Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); } if(Config.event()){ if(winFightTeam == null) getEventFight().setErgebnis(0); else if(winFightTeam.isBlue()) getEventFight().setErgebnis(1); else getEventFight().setErgebnis(2); } if(!Config.test()) new SpectateOverCountdown(); } public static void setFightTime(int fightTime) { FightSystem.fightTime = fightTime; } public static void setEntern(boolean entern) { final List> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer()); final List> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer()); IFightSystem.setEntern(entern); for(FightPlayer player : Fight.getBlueTeam().getPlayers()){ TechHider.reloadChunks(player.getPlayer(), chunksBlue); } for(FightPlayer player : Fight.getRedTeam().getPlayers()){ TechHider.reloadChunks(player.getPlayer(), chunksRed); } } private static void loadKits(FightTeam team){ for(FightPlayer allFightPlayers : team.getPlayers()) { if(allFightPlayers.getPlayer() == null) continue; allFightPlayers.getPlayer().getInventory().clear(); if(allFightPlayers.getKit() == null) continue; allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer()); } } private static void setAllPlayersGM(GameMode gm) { for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){ fightPlayer.getPlayer().setGameMode(gm); } for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){ fightPlayer.getPlayer().setGameMode(gm); } } private static void setFightState(FightState state){ fightState = state; BasicListener.fightStateChange(state); } public static void setEventLeiter(Player el){ IFightSystem.setEventLeiter(el); } public static Player getEventLeiter(){ return IFightSystem.getEventLeiter(); } public static EventFight getEventFight(){ return IFightSystem.getEventFight(); } private static void setPlugin(FightSystem pl){ plugin = pl; } public static FightSystem getPlugin() { return plugin; } public static FightState getFightState() { return fightState; } public static int getFightTime() { return fightTime; } public static boolean isEntern() { return IFightSystem.isEntern(); } public static void shutdown(String reason){ IFightSystem.shutdown(reason); } }