SteamWar/FightSystem
Archiviert
13
1
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
FightSystem/FightSystem_API/src/de/steamwar/fightsystem/Config.java

380 Zeilen
16 KiB
Java

2019-11-16 08:37:33 +01:00
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;
2019-11-16 08:37:33 +01:00
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.*;
2019-11-16 08:37:33 +01:00
import java.util.logging.Level;
public class Config {
private Config(){}
//Fight sequence
2019-11-16 08:37:33 +01:00
public static final int NoPlayerOnlineDuration;
public static final int PreSchemPasteDuration;
2019-11-16 08:37:33 +01:00
public static final int SetupDuration;
public static final int PreFightDuration;
public static final int EnterPhaseBegin;
2019-11-16 08:37:33 +01:00
public static final int SpectatorDuration;
public static final boolean Entern;
2019-11-16 08:37:33 +01:00
//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;
2019-11-16 08:37:33 +01:00
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;
2019-11-16 08:37:33 +01:00
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;
2019-11-16 08:37:33 +01:00
//schematic parameter
public static final boolean OnlyPublicSchematics;
public static final boolean IgnorePublicOnly;
2019-11-16 08:37:33 +01:00
public static final de.steamwar.sql.SchematicType SchematicType;
public static final boolean TeamRedRotate;
public static final boolean TeamBlueRotate;
2019-12-06 22:51:26 +01:00
public static final boolean ReplaceObsidian;
public static final boolean ReplaceBedrock;
public static final boolean ReplaceWithBlockupdates;
2019-11-16 08:37:33 +01:00
//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;
2019-11-16 08:37:33 +01:00
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;
2019-11-16 08:37:33 +01:00
public static final boolean TechKO;
public static final boolean WaterTechKO;
public static final boolean PumpkinTechKO;
2019-11-16 08:37:33 +01:00
//win condition parameters
public static final int TimeoutTime;
public static final double PercentWin;
public static final List<String> IgnoredBlocks;
2019-11-16 08:37:33 +01:00
//default kits
public static final String MemberDefault;
public static final String LeaderDefault;
public static final boolean PersonalKits;
public static final List<String> ForbiddenItems;
2019-11-16 08:37:33 +01:00
//tech hider parameter
public static final boolean TechhiderActive;
public static final Set<Integer> HiddenBlocks;
public static final Set<String> HiddenBlockTags;
public static final Set<String> HiddenBlockEntities;
public static final int ObfuscateWith;
public static final String ObfuscateWithTag;
2019-11-16 08:37:33 +01:00
//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;
2019-11-16 08:37:33 +01:00
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");
2019-11-16 08:37:33 +01:00
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");
2019-11-16 08:37:33 +01:00
SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType"));
IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly");
2019-11-16 08:37:33 +01:00
boolean rotate = config.getBoolean("Schematic.Rotate");
2019-12-06 22:51:26 +01:00
ReplaceObsidian = config.getBoolean("Schematic.ReplaceObsidian");
ReplaceBedrock = config.getBoolean("Schematic.ReplaceBedrock");
ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates");
2019-11-16 08:37:33 +01:00
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");
2019-11-16 08:37:33 +01:00
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");
2019-11-16 08:37:33 +01:00
Entern = config.getBoolean("WinConditions.Entern");
TechKO = config.getBoolean("WinConditions.TechKO");
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO");
2019-11-16 08:37:33 +01:00
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin");
PercentWin = config.getDouble("WinConditionParams.PercentWin");
IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks"));
2019-11-16 08:37:33 +01:00
MemberDefault = config.getString("Kits.MemberDefault");
LeaderDefault = config.getString("Kits.LeaderDefault");
PersonalKits = config.getBoolean("Kits.PersonalKits");
ForbiddenItems = config.getStringList("Kits.ForbiddenItems");
2019-11-16 08:37:33 +01:00
ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks");
Set<Integer> blocks = new HashSet<>();
Set<String> blockTags = new HashSet<>();
for(String key : techhiderConfig.getKeys(false)){
blockTags.add(key);
if(techhiderConfig.isInt(key))
blocks.add(techhiderConfig.getInt(key));
else{
List<Integer> 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");
2019-11-16 08:37:33 +01:00
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;
2019-11-16 08:37:33 +01:00
World world = Bukkit.getWorlds().get(0);
2020-05-22 17:40:15 +02:00
double yaw = Math.toDegrees(Math.atan2(TeamBluetoReddistanceZ, TeamBluetoReddistanceX));
double pitch = Math.toDegrees(Math.atan2(Math.sqrt(TeamBluetoReddistanceZ * TeamBluetoReddistanceZ + TeamBluetoReddistanceX * TeamBluetoReddistanceX), TeamBluetoReddistanceY) + Math.PI);
double yawInverted = Math.toDegrees(((yaw + 90 + 180) * Math.PI) / 180);
double pitchInverted = Math.toDegrees(((90 - pitch) * Math.PI) / 180);
2020-05-22 17:16:19 +02:00
TeamBlueSpawn = new Location(world,
TeamBluePasteX + 0.5 + teamBlueSpawnOffsetX,
TeamBlueCornerY + 0.5 + teamBlueSpawnOffsetY,
TeamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ);
2020-05-22 17:16:19 +02:00
TeamBlueSpawn.setYaw((float)yaw);
TeamBlueSpawn.setPitch((float)pitch);
TeamRedSpawn = new Location(world,
TeamRedPasteX + 0.5 - teamBlueSpawnOffsetX,
TeamRedCornerY + 0.5 + teamBlueSpawnOffsetY,
TeamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ);
2020-05-22 17:16:19 +02:00
TeamRedSpawn.setYaw((float)yawInverted);
TeamRedSpawn.setPitch((float)pitchInverted);
2019-11-16 08:37:33 +01:00
SpecSpawn = new Location(world,
TeamBluePasteX + TeamBluetoReddistanceX/2.0,
2019-11-16 08:37:33 +01:00
TeamBlueCornerY + TeamBluetoReddistanceY/2.0 + SchemsizeY/2.0,
TeamBluePasteZ + TeamBluetoReddistanceZ/2.0);
2019-11-16 08:37:33 +01:00
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());
2019-11-18 18:52:12 +01:00
if(BothTeamsPublic) {
2019-11-16 08:37:33 +01:00
OnlyPublicSchematics = true;
2019-11-18 18:52:12 +01:00
MaximumTeamMembers = Integer.MAX_VALUE;
}else{
2019-11-16 08:37:33 +01:00
OnlyPublicSchematics = event.publicSchemsOnly();
2019-11-18 18:52:12 +01:00
MaximumTeamMembers = event.getMaximumTeamMembers();
}
2019-11-16 08:37:33 +01:00
}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"));
2019-11-16 08:37:33 +01:00
}
public static boolean event(){
return EventKampfID >= 1;
}
public static boolean test(){
return EventKampfID == -1;
}
public static boolean check(){
return CheckSchemID != 0;
}
2019-11-16 08:37:33 +01:00
}