package de.steamwar.fightsystem; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.Vector; import java.io.File; import java.util.*; import java.util.logging.Level; public class Config { private Config(){} //Fight sequence public static final int NoPlayerOnlineDuration; public static final int PreSchemPasteDuration; public static final int SetupDuration; public static final int PreFightDuration; public static final int EnterPhaseBegin; public static final int SpectatorDuration; public static final boolean Entern; //arena parameter public static final int SchemsizeX; public static final int SchemsizeY; public static final int SchemsizeZ; public static final int TeamBlueCornerX; public static final int TeamBlueCornerY; public static final int TeamBlueCornerZ; private static final int TeamBluePasteX; private static final int TeamBluePasteZ; public static final Location TeamBlueSpawn; public static final int TeamRedCornerX; public static final int TeamRedCornerY; public static final int TeamRedCornerZ; private static final int TeamRedPasteX; private static final int TeamRedPasteZ; public static final Location TeamRedSpawn; private static final int TeamBluetoReddistanceX; private static final int TeamBluetoReddistanceY; public static final int TeamBluetoReddistanceZ; public static final Location SpecSpawn; public static final int underArenaBorder; public static final int BorderFromSchematic; public static final int upperArenaBorder; public static final boolean AlignWater; public static final int WaterDepth; private static final int Schem2BorderX; private static final int Schem2BorderZ; public static final int ArenaMinX; public static final int ArenaMinZ; public static final int ArenaMaxX; public static final int ArenaMaxZ; public static final boolean GroundWalkable; //schematic parameter public static final boolean OnlyPublicSchematics; public static final boolean IgnorePublicOnly; public static final de.steamwar.sql.SchematicType SchematicType; public static final boolean TeamRedRotate; public static final boolean TeamBlueRotate; public static final boolean ReplaceObsidian; public static final boolean ReplaceBedrock; public static final boolean ReplaceWithBlockupdates; //team parameter public static final String TeamRedName; public static final String TeamBlueName; public static final String TeamRedPrefix; public static final String TeamBluePrefix; public static final String GameName; public static final String TeamChatDetection; public static final UUID BlueLeader; public static final UUID RedLeader; //Active win conditions public static final boolean Timeout; public static final boolean HeartRatioTimeout; public static final boolean AllDead; public static final boolean CaptainDead; public static final boolean PercentSystem; public static final boolean RelativePercent; public static final boolean Points; public static final boolean TechKO; public static final boolean WaterTechKO; public static final boolean PumpkinTechKO; //win condition parameters public static final int TimeoutTime; public static final double PercentWin; public static final List IgnoredBlocks; //default kits public static final String MemberDefault; public static final String LeaderDefault; public static final boolean PersonalKits; public static final List ForbiddenItems; //tech hider parameter public static final boolean TechhiderActive; public static final Set HiddenBlocks; public static final Set HiddenBlockTags; public static final Set HiddenBlockEntities; public static final int ObfuscateWith; public static final String ObfuscateWithTag; //event parameter private static final int EventKampfID; public static final int EventTeamBlueID; public static final int EventTeamRedID; public static final boolean BothTeamsPublic; public static final int MaximumTeamMembers; //check parameter public static final int CheckSchemID; static{ File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!"); IFightSystem.shutdown(null); } if(!new File(IFightSystem.getPlugin().getDataFolder(), "config.yml").exists()) { IFightSystem.getPlugin().saveDefaultConfig(); Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); IFightSystem.shutdown(null); } FileConfiguration config = IFightSystem.getPlugin().getConfig(); FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); NoPlayerOnlineDuration = config.getInt("Times.NoPlayersOnlineDuration"); PreSchemPasteDuration = config.getInt("Times.PreSchemPasteDuration"); SetupDuration = config.getInt("Times.SetupDuration"); PreFightDuration = config.getInt("Times.PreFightDuration"); SpectatorDuration = config.getInt("Times.SpectatorDuration"); int schemsizeX = worldconfig.getInt("Arena.Schemsize.x"); int schemsizeY = worldconfig.getInt("Arena.Schemsize.y"); int schemsizeZ = worldconfig.getInt("Arena.Schemsize.z"); int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x"); int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y"); int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z"); TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x"); TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y"); TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z"); Schem2BorderX = worldconfig.getInt("Arena.Schem2Border.x"); Schem2BorderZ = worldconfig.getInt("Arena.Schem2Border.z"); underArenaBorder = worldconfig.getInt("Arena.underArenaBorder"); BorderFromSchematic = worldconfig.getInt("Arena.BorderFromSchematic"); AlignWater = worldconfig.getBoolean("Arena.AlignWater"); WaterDepth = worldconfig.getInt("Arena.WaterDepth"); GroundWalkable = config.getBoolean("Arena.GroundWalkable"); double teamBlueSpawnOffsetX = worldconfig.getDouble("Arena.SpawnOffset.x"); double teamBlueSpawnOffsetY = worldconfig.getDouble("Arena.SpawnOffset.y"); double teamBlueSpawnOffsetZ = worldconfig.getDouble("Arena.SpawnOffset.z"); SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly"); boolean rotate = config.getBoolean("Schematic.Rotate"); ReplaceObsidian = config.getBoolean("Schematic.ReplaceObsidian"); ReplaceBedrock = config.getBoolean("Schematic.ReplaceBedrock"); ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates"); TeamRedPrefix = config.getString("Output.TeamRedPrefix"); TeamBluePrefix = config.getString("Output.TeamBluePrefix"); GameName = config.getString("Output.GameName"); TeamChatDetection = config.getString("Output.TeamChatDetection"); Timeout = config.getBoolean("WinConditions.Timeout"); HeartRatioTimeout = config.getBoolean("WinConditions.HeartRatioTimeout"); AllDead = config.getBoolean("WinConditions.AllDead"); CaptainDead = config.getBoolean("WinConditions.CaptainDead"); PercentSystem = config.getBoolean("WinConditions.PercentSystem"); RelativePercent = config.getBoolean("WinConditions.RelativePercent"); Points = config.getBoolean("WinConditions.Points"); Entern = config.getBoolean("WinConditions.Entern"); TechKO = config.getBoolean("WinConditions.TechKO"); WaterTechKO = config.getBoolean("WinConditions.WaterTechKO"); PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO"); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin"); PercentWin = config.getDouble("WinConditionParams.PercentWin"); IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks")); MemberDefault = config.getString("Kits.MemberDefault"); LeaderDefault = config.getString("Kits.LeaderDefault"); PersonalKits = config.getBoolean("Kits.PersonalKits"); ForbiddenItems = config.getStringList("Kits.ForbiddenItems"); ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks"); Set blocks = new HashSet<>(); Set blockTags = new HashSet<>(); for(String key : techhiderConfig.getKeys(false)){ blockTags.add(key); if(techhiderConfig.isInt(key)) blocks.add(techhiderConfig.getInt(key)); else{ List minmax = techhiderConfig.getIntegerList(key); // Entry 0: Minimum, Entry 1: Maximum for(int i = minmax.get(0); i <= minmax.get(1); i++) blocks.add(i); } } HiddenBlocks = Collections.unmodifiableSet(blocks); HiddenBlockTags = Collections.unmodifiableSet(blockTags); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); ObfuscateWith = config.getInt("Techhider.ObfuscateWith"); ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag"); TechhiderActive = config.getBoolean("Techhider.Active"); if(schemsizeX < 0){ SchemsizeX = -schemsizeX; TeamBlueCornerX = teamBlueCornerX - SchemsizeX; }else{ SchemsizeX = schemsizeX; TeamBlueCornerX = teamBlueCornerX; } if(schemsizeY < 0){ SchemsizeY = -schemsizeY; TeamBlueCornerY = teamBlueCornerY - SchemsizeY; }else{ SchemsizeY = schemsizeY; TeamBlueCornerY = teamBlueCornerY; } if(schemsizeZ < 0){ SchemsizeZ = -schemsizeZ; TeamBlueCornerZ = teamBlueCornerZ - SchemsizeZ; }else{ SchemsizeZ = schemsizeZ; TeamBlueCornerZ = teamBlueCornerZ; } upperArenaBorder = TeamBlueCornerY + SchemsizeY + BorderFromSchematic; TeamRedCornerX = TeamBluetoReddistanceX + TeamBlueCornerX; TeamRedCornerY = TeamBluetoReddistanceY + TeamBlueCornerY; TeamRedCornerZ = TeamBluetoReddistanceZ + TeamBlueCornerZ; TeamBluePasteX = TeamBlueCornerX + SchemsizeX / 2; TeamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2; TeamRedPasteX = TeamBluePasteX + TeamBluetoReddistanceX; TeamRedPasteZ = TeamBluePasteZ + TeamBluetoReddistanceZ; World world = Bukkit.getWorlds().get(0); //double yaw = Math.toDegrees(Math.atan2(TeamBluetoReddistanceZ, TeamBluetoReddistanceX) + Math.PI / 2); //double pitch = Math.toDegrees(Math.atan2(Math.sqrt(TeamBluetoReddistanceZ * TeamBluetoReddistanceZ + TeamBluetoReddistanceX * TeamBluetoReddistanceX), TeamBluetoReddistanceY)); //double yawInverted = yaw + 180; //double pitchInverted = ((90 - pitch) * 180) / 180; TeamBlueSpawn = new Location(world, TeamBluePasteX + 0.5 + teamBlueSpawnOffsetX, TeamBlueCornerY + 0.5 + teamBlueSpawnOffsetY, TeamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ); TeamRedSpawn = new Location(world, TeamRedPasteX + 0.5 - teamBlueSpawnOffsetX, TeamRedCornerY + 0.5 + teamBlueSpawnOffsetY, TeamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ); Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector()); double pitch = Math.toDegrees(v1.angle(v1.clone().setY(0))); double yaw = Math.toDegrees(v1.clone().setY(0).angle(new Vector(0, 0, 1))); double pitchInverted = pitch * -1; double yawInverted = yaw + 180; TeamBlueSpawn.setYaw((float) yaw); TeamBlueSpawn.setPitch((float) pitch); TeamRedSpawn.setYaw((float) yawInverted); TeamRedSpawn.setPitch((float) pitchInverted); SpecSpawn = new Location(world, TeamBluePasteX + TeamBluetoReddistanceX/2.0, TeamBlueCornerY + TeamBluetoReddistanceY/2.0 + SchemsizeY/2.0, TeamBluePasteZ + TeamBluetoReddistanceZ/2.0); boolean teamRedRotate; boolean teamBlueRotate; if(TeamBluetoReddistanceX > 0){ ArenaMinX = TeamBlueCornerX - Schem2BorderX; ArenaMaxX = TeamRedCornerX + SchemsizeX + Schem2BorderX; teamRedRotate = true; teamBlueRotate = false; }else{ ArenaMinX = TeamRedCornerX - Schem2BorderX; ArenaMaxX = TeamBlueCornerX + SchemsizeX + Schem2BorderX; teamRedRotate = false; teamBlueRotate = true; } if(TeamBluetoReddistanceZ > 0){ ArenaMinZ = TeamBlueCornerZ - Schem2BorderZ; ArenaMaxZ = TeamRedCornerZ + SchemsizeZ + Schem2BorderZ; teamRedRotate = true; teamBlueRotate = false; }else{ ArenaMinZ = TeamRedCornerZ - Schem2BorderZ; ArenaMaxZ = TeamBlueCornerZ + SchemsizeZ + Schem2BorderZ; if(TeamBluetoReddistanceZ != 0){ teamRedRotate = false; teamBlueRotate = true; } } if(!rotate){ teamRedRotate = false; teamBlueRotate = false; } TeamRedRotate = teamRedRotate; TeamBlueRotate = teamBlueRotate; EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(event()){ EventFight eventFight = EventFight.get(EventKampfID); if(eventFight == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight"); IFightSystem.shutdown(null); } assert eventFight != null; Team team1 = Team.get(eventFight.getTeamBlue()); Team team2 = Team.get(eventFight.getTeamRed()); if(team1 == null || team2 == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team"); IFightSystem.shutdown(null); } assert team1 != null; assert team2 != null; TeamBlueName = team1.getTeamKuerzel(); TeamRedName = team2.getTeamKuerzel(); EventTeamBlueID = team1.getTeamId(); EventTeamRedID = team2.getTeamId(); BothTeamsPublic = EventTeamRedID == 0 && EventTeamBlueID == 0; IFightSystem.setEventFight(eventFight); Event event = Event.get(eventFight.getEventID()); if(BothTeamsPublic) { OnlyPublicSchematics = true; MaximumTeamMembers = Integer.MAX_VALUE; }else{ OnlyPublicSchematics = event.publicSchemsOnly(); MaximumTeamMembers = event.getMaximumTeamMembers(); } }else{ //No event TeamRedName = config.getString("Output.TeamRedName"); TeamBlueName = config.getString("Output.TeamBlueName"); OnlyPublicSchematics = config.getBoolean("Schematic.OnlyPublicSchematics"); EventTeamBlueID = 0; EventTeamRedID = 0; BothTeamsPublic = true; MaximumTeamMembers = Integer.MAX_VALUE; } String blueLeader = System.getProperty("blueLeader", null); String redLeader = System.getProperty("redLeader", null); if(blueLeader != null) BlueLeader = UUID.fromString(blueLeader); else BlueLeader = null; if(redLeader != null) RedLeader = UUID.fromString(redLeader); else RedLeader = null; CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); } public static boolean event(){ return EventKampfID >= 1; } public static boolean test(){ return EventKampfID == -1; } public static boolean check(){ return CheckSchemID != 0; } }