package me.yaruma.fightsystem; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import de.diamant.hunjy.CoinSystem.CoinSystem; import me.yaruma.fightsystem.commands.AkCommand; import me.yaruma.fightsystem.fight.*; import me.yaruma.fightsystem.listener.*; import me.yaruma.fightsystem.manager.FileManager; import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.FinishNoPlayersOnline; import me.yaruma.fightsystem.utils.countdown.FinishSetupOver; import me.yaruma.fightsystem.utils.countdown.FinishSpectateOver; import me.yaruma.fightsystem.utils.scoreboard.Scoreboard; import me.yaruma.fightsystem.winconditions.WinconditionAllDead; import me.yaruma.fightsystem.winconditions.WinconditionCaptainDead; import me.yaruma.fightsystem.winconditions.WinconditionPercentSystem; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.World; import java.io.File; public class FightSystem extends JavaPlugin { public static String PREFIX = "[FightSystem] "; public static String NOPERM = PREFIX + "§4Du darfst das nicht!"; private static FightSystem plugin; private FileManager fileManager; private FightManager fightManager; private Scoreboard scoreboard; private FightState fightState; public Location Team1SpawnLoc = null; public Location Team2SpawnLoc = null; public Location SpecSpawnLoc = null; public Location Team1PasteLoc = null; public Location Team2PasteLoc = null; public int ArenaMinX; public int ArenaMaxX; public int ArenaMinZ; public int ArenaMaxZ; public int schemsizeX; public int schemsizeY; public int schemsizeZ; public int team1cornerX; public int team1cornerY; public int team1cornerZ; public int team2cornerX; public int team2cornerY; public int team2cornerZ; public int fightTime = 0; public double damageRed = 0D; public double getDamageBlue = 0D; public boolean entern = false; public void onEnable() { plugin = this; this.fileManager = new FileManager(plugin); this.fightManager = new FightManager(); this.scoreboard = new Scoreboard(plugin); //Load config schemsizeX = fileManager.getIntegerFromConfig("Arena.Schemsize.x"); schemsizeY = fileManager.getIntegerFromConfig("Arena.Schemsize.y"); schemsizeZ = fileManager.getIntegerFromConfig("Arena.Schemsize.z"); team1cornerX = fileManager.getIntegerFromConfig("Arena.Team1corner.x"); team1cornerY = fileManager.getIntegerFromConfig("Arena.Team1corner.y"); team1cornerZ = fileManager.getIntegerFromConfig("Arena.Team1corner.z"); int team1toTeam2distanceX = fileManager.getIntegerFromConfig("Arena.Team1toTeam2distance.x"); int team1toTeam2distanceY = fileManager.getIntegerFromConfig("Arena.Team1toTeam2distance.y"); int team1toTeam2distanceZ = fileManager.getIntegerFromConfig("Arena.Team1toTeam2distance.z"); int schem2BorderX = fileManager.getIntegerFromConfig("Arena.Schem2Border.x"); int schem2BorderZ = fileManager.getIntegerFromConfig("Arena.Schem2Border.z"); World world = Bukkit.getWorld(fileManager.getStringFromConfig("Arena.WorldName")); //Rotate team1corner to edge (min. x, min. y, min. z) if(schemsizeX < 0){ schemsizeX = -schemsizeX; team1cornerX -= 2*schemsizeX; } if(schemsizeY < 0){ schemsizeY = -schemsizeY; team1cornerY -= 2*schemsizeY; } if(schemsizeZ < 0){ schemsizeZ = -schemsizeZ; team1cornerZ -= 2*schemsizeZ; } //Compute various positions team2cornerX = team1toTeam2distanceX + team1cornerX; team2cornerY = team1toTeam2distanceY + team1cornerY; team2cornerZ = team1toTeam2distanceZ + team1cornerZ; int Team1centerX = team1cornerX + schemsizeX/2; int Team1centerY = team1cornerY; int Team1centerZ = team1cornerZ + schemsizeZ/2; int Team2centerX = Team1centerX + team1toTeam2distanceX; int Team2centerY = Team1centerY + team1toTeam2distanceY; int Team2centerZ = Team1centerZ + team1toTeam2distanceZ; Team1SpawnLoc = new Location(world, Team1centerX, Team1centerY + schemsizeY, Team1centerZ); Team2SpawnLoc = new Location(world, Team1centerX, Team1centerY + schemsizeY, Team1centerZ); SpecSpawnLoc = new Location(world, Team1centerX + team1toTeam2distanceX/2, Team1centerY + team1toTeam2distanceY/2 + schemsizeY/2, Team1centerZ + team1toTeam2distanceZ/2); Team1PasteLoc = new Location(world, Team1centerX, Team1centerY, Team1centerZ); Team2PasteLoc = new Location(world, Team2centerX, Team2centerY, Team2centerZ); if(team1toTeam2distanceX > 0){ ArenaMinX = team1cornerX - schem2BorderX; ArenaMaxX = team1cornerX + team1toTeam2distanceX + schemsizeX + schem2BorderX; }else{ ArenaMinX = team1cornerX + team1toTeam2distanceX - schem2BorderX; ArenaMaxX = team1cornerX + schemsizeX + schem2BorderX; } if(team1toTeam2distanceZ > 0){ ArenaMinZ = team1cornerZ - schem2BorderZ; ArenaMaxZ = team1cornerZ + team1toTeam2distanceZ + schemsizeZ + schem2BorderZ; }else{ ArenaMinZ = team1cornerZ + team1toTeam2distanceZ - schem2BorderZ; ArenaMaxZ = team1cornerZ + schemsizeZ + schem2BorderZ; } loadConfig(); init(); fightState = FightState.SETUP; int setupDuration = fileManager.getIntegerFromConfig("Times.NoPlayersOnlineDuration"); Countdown countdown = new Countdown(setupDuration, new FinishNoPlayersOnline()); countdown.startTimer(getPlugin()); System.out.println(PREFIX + "§aPlugin gestartet!"); } public void onDisable() { System.out.println(PREFIX + "§cPlugin deaktiviert!"); } 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); //WinConditions if(fileManager.getBooleanFromConfig("WinConditions.AllDead")) pm.registerEvents(new WinconditionAllDead(), plugin); if(fileManager.getBooleanFromConfig("WinConditions.CaptainDead")) pm.registerEvents(new WinconditionCaptainDead(), plugin); if(fileManager.getBooleanFromConfig("WinConditions.AllDead")) pm.registerEvents(new WinconditionAllDead(), plugin); if(fileManager.getBooleanFromConfig("WinConditions.PercentWin")) pm.registerEvents(new WinconditionPercentSystem(), plugin); getCommand("ak").setExecutor(new AkCommand()); } private void loadConfig() { if(!new File("plugins/" + this.getName() + "/config.yml").exists()) { saveDefaultConfig(); System.out.println(PREFIX + "config.yml erstellt und geladen!"); Bukkit.shutdown(); } } public static FightSystem getPlugin() { return plugin; } public FightState getCurrentFightState() { return fightState; } public FileManager getFileManager() { return this.fileManager; } public FightManager getFightManager() { return this.fightManager; } public FightState getFightState() { return fightState; } public Scoreboard getScoreboard() { return scoreboard; } public void setSetupState() { if(this.fightState == null) { this.fightState = FightState.SETUP; } } public void setPreRunningState() { if(this.fightState == FightState.SETUP) { this.fightState = FightState.PRE_RUNNING; } } public void setRunningState() { if(this.fightState == FightState.PRE_RUNNING) { this.fightState = FightState.RUNNING; } } public void setSpectateState(FightTeam winFightTeam) { if(this.fightState == FightState.RUNNING) { this.fightState = FightState.SPECTATE; Bukkit.broadcastMessage(" "); if(winFightTeam != null) { Bukkit.broadcastMessage(PREFIX + "§aDas Team von §6" + winFightTeam.getLeader().getPlayer().getName() + " §ahat gewonnen!"); plugin.getFightManager().teleportAllToFightSpawn(); for(FightPlayer fightPlayer : winFightTeam.getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(getMoneyToPay("Money.Win")); } for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(getMoneyToPay("Money.Lose")); } } else { //Keine Message! Wird in FinishTimeOver gesendet! for(FightPlayer fightPlayer : winFightTeam.getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(getMoneyToPay("Money.Undecided")); } for(FightPlayer fightPlayer : Fight.getOpposite(winFightTeam).getPlayers()) { CoinSystem.getCoinsManager(fightPlayer.getPlayer()).addCoins(getMoneyToPay("Money.Undecided")); } } Countdown cancelAllCountdowns = new Countdown(); cancelAllCountdowns.cancelAllTimers(FightSystem.getPlugin()); Countdown countdown = new Countdown(20*60, new FinishSpectateOver()); countdown.startTimer(FightSystem.getPlugin()); } } public int getMoneyToPay(String moneyPath) { return fileManager.getIntegerFromConfig(moneyPath); } public static WorldEditPlugin getWorldEditPlugin() { return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); } public Location getTeam1SpawnLoc() { return Team1SpawnLoc; } public Location getTeam2SpawnLoc() { return Team2SpawnLoc; } public Location getSpecSpawnLoc() { return SpecSpawnLoc; } public Location getTeam1PasteLoc() { return Team1PasteLoc; } public Location getTeam2PasteLoc() { return Team2PasteLoc; } public int getArenaMinX() { return ArenaMinX; } public int getArenaMaxX() { return ArenaMaxX; } public int getArenaMinZ() { return ArenaMinZ; } public int getArenaMaxZ() { return ArenaMaxZ; } public int getSchemsizeX() { return schemsizeX; } public int getSchemsizeY() { return schemsizeY; } public int getSchemsizeZ() { return schemsizeZ; } public int getTeam1cornerX() { return team1cornerX; } public int getTeam1cornerY() { return team1cornerY; } public int getTeam1cornerZ() { return team1cornerZ; } public int getTeam2cornerX() { return team2cornerX; } public int getTeam2cornerY() { return team2cornerY; } public int getTeam2cornerZ() { return team2cornerZ; } public int getFightTime() { return fightTime; } public double getDamageRed() { return damageRed; } public double getGetDamageBlue() { return getDamageBlue; } public boolean isEntern() { return entern; } }