390 Zeilen
16 KiB
Java
390 Zeilen
16 KiB
Java
/*
|
|
This file is a part of the SteamWar software.
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package de.steamwar.fightsystem;
|
|
|
|
import de.steamwar.fightsystem.utils.Region;
|
|
import de.steamwar.fightsystem.winconditions.Winconditions;
|
|
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.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;
|
|
import java.util.stream.Collectors;
|
|
|
|
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 SpectatorDuration;
|
|
|
|
// entern parameter
|
|
public static final List<Integer> EnterStages;
|
|
|
|
//arena parameter
|
|
public static final Region BluePasteRegion;
|
|
public static final Region RedPasteRegion;
|
|
public static final Region BlueExtendRegion;
|
|
public static final Region RedExtendRegion;
|
|
public static final Region ArenaRegion;
|
|
|
|
public static final Location TeamBlueSpawn;
|
|
public static final Location TeamRedSpawn;
|
|
public static final Location SpecSpawn;
|
|
|
|
private static final int BlueToRedX;
|
|
private static final int BlueToRedY;
|
|
public static final int BlueToRedZ;
|
|
|
|
public static final int PreperationArea;
|
|
public static final int WaterDepth;
|
|
public static final boolean GroundWalkable;
|
|
|
|
//schematic parameter
|
|
public static final boolean RanksEnabled;
|
|
public static final boolean OnlyPublicSchematics;
|
|
public static final boolean IgnorePublicOnly;
|
|
public static final de.steamwar.sql.SchematicType SchematicType;
|
|
public static final boolean RedRotate;
|
|
public static final boolean BlueRotate;
|
|
public static final boolean PasteAligned;
|
|
public static final boolean ReplaceObsidianBedrock;
|
|
public static final boolean ReplaceWithBlockupdates;
|
|
|
|
//team parameter
|
|
public static final String TeamRedName;
|
|
public static final String TeamBlueName;
|
|
public static final String TeamRedColor;
|
|
public static final String TeamBlueColor;
|
|
public static final String GameName;
|
|
public static final String TeamChatDetection;
|
|
public static final UUID BlueLeader;
|
|
public static final UUID RedLeader;
|
|
public static final boolean Ranked;
|
|
|
|
//Active win conditions
|
|
public static final Set<Winconditions> ActiveWinconditions;
|
|
|
|
//win condition parameters
|
|
public static final int TimeoutTime;
|
|
public static final double PercentWin;
|
|
public static final List<String> IgnoredBlocks;
|
|
|
|
//default kits
|
|
public static final String MemberDefault;
|
|
public static final String LeaderDefault;
|
|
public static final boolean PersonalKits;
|
|
public static final List<String> ForbiddenItems;
|
|
public static final String KitFile;
|
|
|
|
//tech hider parameter
|
|
public static final boolean TechhiderActive;
|
|
public static final Set<String> HiddenBlocks;
|
|
public static final Set<String> HiddenBlockEntities;
|
|
public static final String ObfuscateWith;
|
|
|
|
//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;
|
|
public static final boolean SpectateSystem;
|
|
|
|
//check parameter
|
|
public static final int CheckSchemID;
|
|
public static final int PrepareSchemID;
|
|
|
|
public static final ArenaMode mode;
|
|
|
|
//live recorder parameter
|
|
public static final String spectateIP = "127.0.0.1";
|
|
public static final int spectatePort = 2222;
|
|
|
|
static{
|
|
if(!new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) {
|
|
IFightSystem.getPlugin().saveDefaultConfig();
|
|
Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!");
|
|
Bukkit.shutdown();
|
|
}
|
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")));
|
|
|
|
File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), config.getString("Arenaconfig", "config.yml"));
|
|
if(!worldConfigFile.exists()) {
|
|
Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!");
|
|
Bukkit.shutdown();
|
|
}
|
|
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 underBorder = worldconfig.getInt("UnderBorder");
|
|
int blueCornerX = worldconfig.getInt("BlueCorner.x");
|
|
int blueCornerY = worldconfig.getInt("BlueCorner.y");
|
|
int blueCornerZ = worldconfig.getInt("BlueCorner.z");
|
|
BlueToRedX = worldconfig.getInt("BlueToRed.x");
|
|
BlueToRedY = worldconfig.getInt("BlueToRed.y");
|
|
BlueToRedZ = worldconfig.getInt("BlueToRed.z");
|
|
double teamBlueSpawnOffsetX = worldconfig.getDouble("SpawnOffset.x");
|
|
double teamBlueSpawnOffsetY = worldconfig.getDouble("SpawnOffset.y");
|
|
double teamBlueSpawnOffsetZ = worldconfig.getDouble("SpawnOffset.z");
|
|
|
|
WaterDepth = config.getInt("Arena.WaterDepth");
|
|
int schemsizeX = config.getInt("Arena.Schemsize.x");
|
|
int schemsizeY = config.getInt("Arena.Schemsize.y");
|
|
int schemsizeZ = config.getInt("Arena.Schemsize.z");
|
|
int schem2BorderX = config.getInt("Arena.Schem2Border.x");
|
|
int schem2BorderZ = config.getInt("Arena.Schem2Border.z");
|
|
PreperationArea = config.getInt("Arena.BorderFromSchematic");
|
|
GroundWalkable = config.getBoolean("Arena.GroundWalkable");
|
|
|
|
RanksEnabled = config.getBoolean("Schematic.RanksEnabled");
|
|
SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType"));
|
|
IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly");
|
|
boolean rotate = config.getBoolean("Schematic.Rotate");
|
|
PasteAligned = config.getBoolean("Schematic.PasteAligned");
|
|
ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock");
|
|
ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates");
|
|
|
|
GameName = config.getString("Output.GameName");
|
|
TeamChatDetection = config.getString("Output.TeamChatDetection");
|
|
|
|
ActiveWinconditions = Collections.unmodifiableSet(config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet()));
|
|
|
|
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
|
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
|
IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks"));
|
|
|
|
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
|
|
|
|
KitFile = config.getString("Kits.File");
|
|
MemberDefault = config.getString("Kits.MemberDefault");
|
|
LeaderDefault = config.getString("Kits.LeaderDefault");
|
|
PersonalKits = config.getBoolean("Kits.PersonalKits");
|
|
ForbiddenItems = Collections.unmodifiableList(config.getStringList("Kits.ForbiddenItems"));
|
|
|
|
HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks")));
|
|
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities")));
|
|
ObfuscateWith = config.getString("Techhider.ObfuscateWith");
|
|
TechhiderActive = config.getBoolean("Techhider.Active");
|
|
|
|
if(schemsizeX < 0){
|
|
schemsizeX = -schemsizeX;
|
|
blueCornerX = blueCornerX - schemsizeX;
|
|
}
|
|
if(schemsizeY < 0){
|
|
schemsizeY = -schemsizeY;
|
|
blueCornerY = blueCornerY - schemsizeY;
|
|
}
|
|
if(schemsizeZ < 0){
|
|
schemsizeZ = -schemsizeZ;
|
|
blueCornerZ = blueCornerZ - schemsizeZ;
|
|
}
|
|
|
|
|
|
int teamRedCornerX = BlueToRedX + blueCornerX;
|
|
int teamRedCornerY = BlueToRedY + blueCornerY;
|
|
int teamRedCornerZ = BlueToRedZ + blueCornerZ;
|
|
|
|
int teamBluePasteX = blueCornerX + schemsizeX / 2;
|
|
int teamBluePasteZ = blueCornerZ + schemsizeZ / 2;
|
|
int teamRedPasteX = teamBluePasteX + BlueToRedX;
|
|
int teamRedPasteZ = teamBluePasteZ + BlueToRedZ;
|
|
|
|
World world = Bukkit.getWorlds().get(0);
|
|
|
|
TeamBlueSpawn = new Location(world,
|
|
teamBluePasteX + 0.5 + teamBlueSpawnOffsetX,
|
|
blueCornerY + 0.5 + teamBlueSpawnOffsetY,
|
|
teamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ);
|
|
|
|
TeamRedSpawn = new Location(world,
|
|
teamRedPasteX + 0.5 - teamBlueSpawnOffsetX,
|
|
teamRedCornerY + 0.5 + teamBlueSpawnOffsetY,
|
|
teamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ);
|
|
|
|
SpecSpawn = new Location(world,
|
|
teamBluePasteX + BlueToRedX /2.0,
|
|
blueCornerY + BlueToRedY /2.0 + schemsizeY/2.0,
|
|
teamBluePasteZ + BlueToRedZ /2.0);
|
|
|
|
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)));
|
|
|
|
TeamBlueSpawn.setYaw((float) yaw + 180);
|
|
TeamBlueSpawn.setPitch((float) pitch);
|
|
|
|
TeamRedSpawn.setYaw((float) yaw);
|
|
TeamRedSpawn.setPitch((float) pitch * -1);
|
|
|
|
|
|
boolean teamRedRotate;
|
|
boolean teamBlueRotate;
|
|
int arenaMinX;
|
|
int arenaMaxX;
|
|
int arenaMinZ;
|
|
int arenaMaxZ;
|
|
if(BlueToRedX > 0){
|
|
arenaMinX = blueCornerX - schem2BorderX;
|
|
arenaMaxX = teamRedCornerX + schemsizeX + schem2BorderX;
|
|
teamRedRotate = true;
|
|
teamBlueRotate = false;
|
|
}else{
|
|
arenaMinX = teamRedCornerX - schem2BorderX;
|
|
arenaMaxX = blueCornerX + schemsizeX + schem2BorderX;
|
|
teamRedRotate = false;
|
|
teamBlueRotate = true;
|
|
}
|
|
if(BlueToRedZ > 0){
|
|
arenaMinZ = blueCornerZ - schem2BorderZ;
|
|
arenaMaxZ = teamRedCornerZ + schemsizeZ + schem2BorderZ;
|
|
teamRedRotate = true;
|
|
teamBlueRotate = false;
|
|
}else{
|
|
arenaMinZ = teamRedCornerZ - schem2BorderZ;
|
|
arenaMaxZ = blueCornerZ + schemsizeZ + schem2BorderZ;
|
|
if(BlueToRedZ != 0){
|
|
teamRedRotate = false;
|
|
teamBlueRotate = true;
|
|
}
|
|
}
|
|
if(!rotate){
|
|
teamRedRotate = false;
|
|
teamBlueRotate = false;
|
|
}
|
|
RedRotate = teamRedRotate;
|
|
BlueRotate = teamBlueRotate;
|
|
|
|
int arenaYSize = blueCornerY - underBorder + schemsizeY + PreperationArea;
|
|
|
|
RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ);
|
|
BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ);
|
|
|
|
RedExtendRegion = new Region(teamRedCornerX, underBorder, teamRedCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea);
|
|
BlueExtendRegion = new Region(blueCornerX, underBorder, blueCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea);
|
|
ArenaRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, arenaYSize, arenaMaxZ - arenaMinZ);
|
|
|
|
EventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
|
|
if(EventKampfID >= 1){
|
|
EventFight eventFight = EventFight.get(EventKampfID);
|
|
if(eventFight == null){
|
|
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight");
|
|
Bukkit.shutdown();
|
|
}
|
|
|
|
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");
|
|
Bukkit.shutdown();
|
|
}
|
|
|
|
assert team1 != null;
|
|
assert team2 != null;
|
|
TeamBlueName = team1.getTeamKuerzel();
|
|
TeamRedName = team2.getTeamKuerzel();
|
|
TeamBlueColor = "§" + team1.getTeamColor();
|
|
TeamRedColor = "§" + team2.getTeamColor();
|
|
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();
|
|
}
|
|
SpectateSystem = event.spectateSystem();
|
|
}else{
|
|
//No event
|
|
TeamRedColor = config.getString("Output.TeamRedPrefix");
|
|
TeamBlueColor = config.getString("Output.TeamBluePrefix");
|
|
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;
|
|
SpectateSystem = false;
|
|
}
|
|
|
|
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"));
|
|
PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0"));
|
|
Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false"));
|
|
|
|
if(Ranked){
|
|
mode = ArenaMode.RANKED;
|
|
}else if(CheckSchemID != 0){
|
|
mode = ArenaMode.CHECK;
|
|
}else if(PrepareSchemID != 0){
|
|
mode = ArenaMode.PREPARE;
|
|
}else if(EventKampfID >= 1){
|
|
mode = ArenaMode.EVENT;
|
|
}else if(EventKampfID == -1){
|
|
mode = ArenaMode.TEST;
|
|
}else{
|
|
mode = ArenaMode.NORMAL;
|
|
}
|
|
}
|
|
|
|
public static boolean test(){
|
|
return ArenaMode.Test.contains(mode);
|
|
}
|
|
public static boolean recording(){
|
|
return mode == ArenaMode.EVENT;
|
|
}
|
|
}
|