package me.yaruma.fightsystem; import de.warking.hunjy.CoinSystem.CoinSystem; import me.yaruma.fightsystem.commands.AkCommand; import me.yaruma.fightsystem.fight.*; import me.yaruma.fightsystem.kit.KitManager; import me.yaruma.fightsystem.listener.*; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.WorldEdit; import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.FinishNoPlayersOnline; import me.yaruma.fightsystem.utils.countdown.FinishPreRunning; import me.yaruma.fightsystem.utils.countdown.FinishSpectateOver; import me.yaruma.fightsystem.utils.scoreboard.Scoreboard; import me.yaruma.fightsystem.winconditions.*; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; public class FightSystem extends JavaPlugin { public static final String PREFIX = "§6Arena§8» "; public static final String NOPERM = PREFIX + "§cDu darfst das nicht!"; private static FightSystem plugin; private Scoreboard scoreboard; private WaterRemover waterRemover; private FightState fightState; public int fightTime = 0; public boolean entern = false; private final File kits = new File("plugins/" + this.getName(), "kits.data"); private final FileConfiguration getKitData = YamlConfiguration.loadConfiguration(kits); public void saveKitData() { try { getKitData.save(kits); } catch (Exception ignored) { } } public FileConfiguration getKitData() { return getKitData; } public void onEnable() { plugin = this; Config.load(); this.scoreboard = new Scoreboard(plugin); this.waterRemover = new WaterRemover(); loadConfig(); KitManager.loadAllKits(); init(); fightState = FightState.SETUP; Countdown countdown = new Countdown(Config.SetupDuration, new FinishNoPlayersOnline()); countdown.startTimer(getPlugin()); } public void onDisable() { } private void init() { PluginManager pm = Bukkit.getPluginManager(); pm.registerEvents(new PlayerJoinListener(), plugin); pm.registerEvents(new PlayerQuitListener(), plugin); pm.registerEvents(new PlayerDeathListener(), plugin); pm.registerEvents(new PlayerInteractListener(), plugin); pm.registerEvents(new PlayerChatListener(), plugin); pm.registerEvents(new BlockPlaceListener(), plugin); pm.registerEvents(new BlockBreakListener(), plugin); pm.registerEvents(new PlayerMoveListener(), plugin); pm.registerEvents(new EntityDamageByEntityListener(), plugin); pm.registerEvents(new FoodLevelChangeListener(), plugin); pm.registerEvents(new PlayerRespawnListener(), plugin); pm.registerEvents(new EntityDamageListener(), plugin); pm.registerEvents(new EntityExplodeListener(), plugin); //WinConditions if(Config.AllDead) pm.registerEvents(new WinconditionAllDead(), plugin); if(Config.CaptainDead) pm.registerEvents(new WinconditionCaptainDead(), plugin); if(Config.PercentSystem) pm.registerEvents(new WinconditionPercentSystem(), plugin); getCommand("ak").setExecutor(new AkCommand()); } private void loadConfig() { if(!new File("plugins/" + this.getName() + "/kits.data").exists()) { saveKitData(); System.out.println(PREFIX + "kits.data erstellt und geladen!"); Bukkit.shutdown(); } } public static FightSystem getPlugin() { return plugin; } public FightState getCurrentFightState() { return fightState; } public FightState getFightState() { return fightState; } public Scoreboard getScoreboard() { return scoreboard; } public WaterRemover getWaterRemover() { return waterRemover; } public void setPreRunningState() { if(this.fightState != FightState.SETUP) return; this.fightState = FightState.PRE_RUNNING; Countdown.cancelAllTimers(); Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning()); countdown.startTimer(this); for(FightPlayer allFightPlayers : Fight.getBlueTeam().getPlayers()) { allFightPlayers.getPlayer().getInventory().clear(); allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer()); } for(FightPlayer allFightPlayers : Fight.getRedTeam().getPlayers()) { allFightPlayers.getPlayer().getInventory().clear(); allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer()); } teleportAllToFightSpawn(); WorldEdit.replace(Fight.getBlueTeam().getLeader().getPlayer(), Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueCornerX + Config.SchemsizeX, Config.TeamBlueCornerY + Config.SchemsizeY, Config.TeamBlueCornerZ + Config.SchemsizeZ); WorldEdit.replace(Fight.getRedTeam().getLeader().getPlayer(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedCornerX + Config.SchemsizeX, Config.TeamRedCornerY + Config.SchemsizeY, Config.TeamRedCornerZ + Config.SchemsizeZ); Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"); } private void setAllPlayersGM(GameMode gm) { for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){ fightPlayer.getPlayer().setGameMode(gm); } for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){ fightPlayer.getPlayer().setGameMode(gm); } } public void setRunningState() { if(this.fightState != FightState.PRE_RUNNING) return; this.fightState = FightState.RUNNING; Countdown.cancelAllTimers(); getWaterRemover().start(); setAllPlayersGM(GameMode.SURVIVAL); WinconditionTimeout.timeout(); WinconditionEntern.entern(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } public void setSpectateState(FightTeam winFightTeam) { if(this.fightState != FightState.RUNNING) return; this.fightState = FightState.SPECTATE; Countdown.cancelAllTimers(); setAllPlayersGM(GameMode.SPECTATOR); Bukkit.broadcastMessage(" "); if(winFightTeam != null) { Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getName() + " §ahat gewonnen!"); teleportAllToFightSpawn(); for(FightPlayer fightPlayer : winFightTeam.getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyWin); } for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyLose); } } else { Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); for(FightPlayer fightPlayer : Fight.getBlueTeam().getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyDraw); } for(FightPlayer fightPlayer : Fight.getRedTeam().getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(Config.MoneyDraw); } } Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver()); countdown.startTimer(FightSystem.getPlugin()); } public int getFightTime() { return fightTime; } public double getDamageRed() { double damageRed = 0D; return damageRed; } public double getGetDamageBlue() { double getDamageBlue = 0D; return getDamageBlue; } public boolean isEntern() { return entern; } private void teleportAllToFightSpawn() { Fight.getBlueTeam().teleportToSpawn(); Fight.getRedTeam().teleportToSpawn(); for(Player player : Bukkit.getServer().getOnlinePlayers()) { FightTeam fightTeam = Fight.getPlayerTeam(player); if(fightTeam == null) player.teleport(Config.SpecSpawn); } } }