package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.Config; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import java.util.List; public class Fight { private Fight(){} public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedPrefix, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader); public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); private static int schemRank; public static void init(){ IFight.init(redTeam, blueTeam); } public static FightTeam getPlayerTeam(Player player) { if(redTeam.isPlayerInTeam(player)) return redTeam; if(blueTeam.isPlayerInTeam(player)) return blueTeam; return null; } public static FightTeam getOpposite(FightTeam fightTeam) { if(fightTeam == null){ throw new IllegalArgumentException(); } if(fightTeam == redTeam) return blueTeam; else return redTeam; } public static FightTeam getInvitedTeam(Player player){ if(redTeam.getInvited().contains(player)) return redTeam; else if(blueTeam.getInvited().contains(player)) return blueTeam; return null; } public static FightPlayer getFightPlayer(Player player) { if(redTeam.isPlayerInTeam(player)) return redTeam.getFightPlayer(player); if(blueTeam.isPlayerInTeam(player)) return blueTeam.getFightPlayer(player); return null; } public static FightTeam getRedTeam() { return redTeam; } public static FightTeam getBlueTeam() { return blueTeam; } public static void playSound(Sound sound, float volume, float pitch) { //volume: max. 100, pitch: max. 2 Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } public static void setLevel(int level) { Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level)); } public static FightTeam getTeamByName(String name) { if(redTeam.getName().equalsIgnoreCase(name)) return redTeam; if(blueTeam.getName().equalsIgnoreCase(name)) return blueTeam; return null; } public static void replaceSync() { Fight.getRedTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT); Fight.getBlueTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT); Fight.getRedTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK); Fight.getBlueTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK); } public static void setPlayerGamemode(Player player, GameMode gameMode) { player.setGameMode(gameMode); if(gameMode == GameMode.SPECTATOR) { for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { currentPlayer.hidePlayer(player); player.hidePlayer(currentPlayer); } } } if(gameMode == GameMode.SURVIVAL) { for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { currentPlayer.showPlayer(player); player.showPlayer(currentPlayer); } } } } public static int getMaxRank(){ /* MaxRank of 0 is Pubonly*/ return schemRank; } public static void calcAvailibleSchemTypes() { if(Config.OnlyPublicSchematics){ schemRank = 0; return; } if(Config.IgnorePublicOnly || Config.event()){ schemRank = 1000; return; } if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null || blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){ schemRank = 1000; return; } if(Config.RanksEnabled) schemRank = Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader())); else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() || Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty()) schemRank = 0; else schemRank = 1; } private static int schemRank(FightPlayer fightPlayer){ int rank = 1; List schematics = Schematic.getSchemsOfType(fightPlayer.getPlayer().getUniqueId(), Config.SchematicType); for(Schematic schem : schematics){ if(schem.getRank() > rank) rank = schem.getRank(); } return rank; } }