return null;
}
public static void save(Warzone warzone) {
YamlConfiguration warzoneYmlConfig = new YamlConfiguration();
ConfigurationSection warzoneRootSection = warzoneYmlConfig.createSection("set");
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); // create folder
ConfigurationSection warzoneSection = warzoneRootSection.createSection("warzone." + warzone.getName());
// Warzone settings
if (!warzone.getWarzoneConfig().isEmpty()) {
ConfigurationSection warzoneConfigSection = warzoneSection.createSection("config");
warzone.getWarzoneConfig().saveTo(warzoneConfigSection);
}
ConfigurationSection warzoneInfoSection = warzoneSection.createSection("info");
// authors
warzoneInfoSection.set("authors", warzone.getAuthors());
// teleport
ConfigurationSection teleSection = warzoneInfoSection.createSection("teleport");
teleSection.set("x", warzone.getTeleport().getBlockX());
teleSection.set("y", warzone.getTeleport().getBlockY());
teleSection.set("z", warzone.getTeleport().getBlockZ());
teleSection.set("yaw", toIntYaw(warzone.getTeleport().getYaw()));
// world
warzoneInfoSection.set("world", warzone.getWorld().getName());
// lobby
if (warzone.getLobby() != null) {
String lobbyOrientation = "";
if (Direction.SOUTH() == warzone.getLobby().getWall()) {
lobbyOrientation = "south";
} else if (Direction.EAST() == warzone.getLobby().getWall()) {
lobbyOrientation = "east";
} else if (Direction.NORTH() == warzone.getLobby().getWall()) {
lobbyOrientation = "north";
} else if (Direction.WEST() == warzone.getLobby().getWall()) {
lobbyOrientation = "west";
}
ConfigurationSection lobbySection = warzoneInfoSection.createSection("lobby");
lobbySection.set("orientation", lobbyOrientation);
lobbySection.set("world", warzone.getLobby().getVolume().getWorld().getName());
lobbySection.set("materials.floor", warzone.getLobbyMaterials().getFloorBlock());
lobbySection.set("materials.outline", warzone.getLobbyMaterials().getOutlineBlock());
lobbySection.set("materials.gate", warzone.getLobbyMaterials().getGateBlock());
lobbySection.set("materials.light", warzone.getLobbyMaterials().getLightBlock());
}
// materials
if (warzone.getLobby() != null) {
warzoneInfoSection.set("materials.main", warzone.getWarzoneMaterials().getMainBlock());
warzoneInfoSection.set("materials.stand", warzone.getWarzoneMaterials().getStandBlock());
warzoneInfoSection.set("materials.light", warzone.getWarzoneMaterials().getLightBlock());
}
// rallyPoint
if (warzone.getRallyPoint() != null) {
ConfigurationSection rpSection = warzoneInfoSection.createSection("rallypoint");
rpSection.set("x", warzone.getRallyPoint().getBlockX());
rpSection.set("y", warzone.getRallyPoint().getBlockY());
rpSection.set("z", warzone.getRallyPoint().getBlockZ());
rpSection.set("yaw", toIntYaw(warzone.getRallyPoint().getYaw()));
}
// monuments
if (warzone.getMonuments().size() > 0) {
ConfigurationSection monumentsSection = warzoneInfoSection.createSection("monument");
List<String> monumentNames = new ArrayList<String>();
for (Monument monument : warzone.getMonuments()) {
monumentNames.add(monument.getName());
}
monumentsSection.set("names", monumentNames);
for (Monument monument : warzone.getMonuments()) {
ConfigurationSection monumentSection = monumentsSection.createSection(monument.getName());
monumentSection.set("x", monument.getLocation().getBlockX());
monumentSection.set("y", monument.getLocation().getBlockY());
monumentSection.set("z", monument.getLocation().getBlockZ());
monumentSection.set("yaw", toIntYaw(monument.getLocation().getYaw()));
}
}
// bombs
if (warzone.getBombs().size() > 0) {
ConfigurationSection bombsSection = warzoneInfoSection.createSection("bomb");
List<String> bombNames = new ArrayList<String>();
for (Bomb bomb : warzone.getBombs()) {
bombNames.add(bomb.getName());
}
bombsSection.set("names", bombNames);
for (Bomb bomb : warzone.getBombs()) {
ConfigurationSection bombSection = bombsSection.createSection(bomb.getName());
bombSection.set("x", bomb.getLocation().getBlockX());
bombSection.set("y", bomb.getLocation().getBlockY());
bombSection.set("z", bomb.getLocation().getBlockZ());
bombSection.set("yaw", toIntYaw(bomb.getLocation().getYaw()));
}
}
// cakes
if (warzone.getCakes().size() > 0) {
ConfigurationSection cakesSection = warzoneInfoSection.createSection("cake");
List<String> cakeNames = new ArrayList<String>();
for (Cake cake : warzone.getCakes()) {
cakeNames.add(cake.getName());
}
cakesSection.set("names", cakeNames);
for (Cake cake : warzone.getCakes()) {
ConfigurationSection cakeSection = cakesSection.createSection(cake.getName());
cakeSection.set("x", cake.getLocation().getBlockX());
cakeSection.set("y", cake.getLocation().getBlockY());
cakeSection.set("z", cake.getLocation().getBlockZ());
cakeSection.set("yaw", toIntYaw(cake.getLocation().getYaw()));
}
}
ConfigurationSection teamsSection = warzoneRootSection.createSection("team");
// teams
List<Team> teams = warzone.getTeams();
List<String> teamNames = new ArrayList<String>();
for (Team team : teams) {
teamNames.add(team.getName());
}
if (teamNames.size() > 0) {
teamsSection.set("names", teamNames);
}
// Team default settings
if (!warzone.getTeamDefaultConfig().isEmpty()) {
ConfigurationSection teamConfigSection = teamsSection.createSection("default.config");
warzone.getTeamDefaultConfig().saveTo(teamConfigSection);
}
// defaultLoadouts
if (warzone.getDefaultInventories().hasLoadouts()) {
ConfigurationSection loadoutsSection = teamsSection.createSection("default.loadout");
LoadoutYmlMapper.fromLoadoutsToConfig(warzone.getDefaultInventories().getNewLoadouts(), loadoutsSection);
}
// defaultReward
if (warzone.getDefaultInventories().hasReward()) {
ConfigurationSection rewardsSection = teamsSection.createSection("default.reward");
LoadoutYmlMapper.fromLoadoutToConfig("default", warzone.getDefaultInventories().getReward(), rewardsSection);
}
for (Team team : teams) {
if (!team.getTeamConfig().isEmpty()) {
// team specific config
ConfigurationSection teamConfigSection = teamsSection.createSection(team.getName() + ".config");
team.getTeamConfig().saveTo(teamConfigSection);
}
if (team.getInventories().hasLoadouts()) {
// team specific loadouts
ConfigurationSection loadoutsSection = teamsSection.createSection(team.getName() + ".loadout");
LoadoutYmlMapper.fromLoadoutsToConfig(team.getInventories().getNewLoadouts(), loadoutsSection);
}
if (team.getInventories().hasReward()) {
// team specific reward
ConfigurationSection rewardsSection = teamsSection.createSection(team.getName() + ".reward");
LoadoutYmlMapper.fromLoadoutToConfig("default", team.getInventories().getReward(), rewardsSection);
}
ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info");
List<Map<String, Object>> spawnSerilization = new ArrayList<Map<String, Object>>();
for (Location spawn : team.getTeamSpawns()) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("x", spawn.getBlockX());
map.put("y", spawn.getBlockY());
map.put("z", spawn.getBlockZ());
map.put("yaw", toIntYaw(spawn.getYaw()));
spawnSerilization.add(map);
}
teamInfoSection.set("spawns", spawnSerilization);
if (team.getTeamFlag() != null) {
ConfigurationSection flagSection = teamInfoSection.createSection("flag");
Location teamFlag = team.getTeamFlag();
flagSection.set("x", teamFlag.getBlockX());
flagSection.set("y", teamFlag.getBlockY());
flagSection.set("z", teamFlag.getBlockZ());
flagSection.set("yaw", toIntYaw(teamFlag.getYaw()));
}
}
Connection connection = null;
try {
connection = ZoneVolumeMapper.getZoneConnection(warzone.getVolume(), warzone.getName(), warzone.getWorld());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
}
// monument blocks
for (Monument monument : warzone.getMonuments()) {
try {
ZoneVolumeMapper.saveStructure(monument.getVolume(), connection);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// bomb blocks
for (Bomb bomb : warzone.getBombs()) {
try {
ZoneVolumeMapper.saveStructure(bomb.getVolume(), connection);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// cake blocks
for (Cake cake : warzone.getCakes()) {
try {
ZoneVolumeMapper.saveStructure(cake.getVolume(), connection);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// team spawn & flag blocks
for (Team team : teams) {
for (Volume volume : team.getSpawnVolumes().values()) {
try {
ZoneVolumeMapper.saveStructure(volume, connection);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
if (team.getFlagVolume() != null) {
try {
ZoneVolumeMapper.saveStructure(team.getFlagVolume(), connection);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
}
if (warzone.getLobby() != null) {
try {
ZoneVolumeMapper.saveStructure(warzone.getLobby().getVolume(), connection);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
try {
connection.close();
} catch (SQLException ignored) {
}
// Save to disk
try {
File warzoneConfigFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".yml");
warzoneYmlConfig.save(warzoneConfigFile);
} catch (IOException e) {
War.war.log("Failed to save warzone-" + warzone.getName() + ".yml", Level.WARNING);
e.printStackTrace();
}
}