/* * This file is a part of the SteamWar software. * * Copyright (C) 2024 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 . */ package de.steamwar.tntleague.config import de.steamwar.tntleague.plugin import de.steamwar.tntleague.util.Area import de.steamwar.tntleague.util.translate import org.bukkit.Location import org.bukkit.Material import org.bukkit.configuration.ConfigurationSection import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.entity.Villager import org.bukkit.entity.WanderingTrader import java.io.File val world by lazy { plugin.server.worlds.first()!! } private val targetedBlocksRed by lazy { TNTLeagueWorldConfig.redTeam.target.blocks.count { block -> block.type == TNTLeagueWorldConfig.targetMaterial } } private val targetedBlocksBlue by lazy { TNTLeagueWorldConfig.blueTeam.target.blocks.count { block -> block.type == TNTLeagueWorldConfig.targetMaterial } } private val targetedBlocksAll: Int get() = if (targetedBlocksBlue == targetedBlocksRed) targetedBlocksBlue else error("Targeted blocks are not equal") val targetedBlocks: Int get() = if (TNTLeagueWorldConfig.target != -1) TNTLeagueWorldConfig.target else targetedBlocksAll object TNTLeagueWorldConfig { private val config: YamlConfiguration by lazy { YamlConfiguration.loadConfiguration( File( plugin.server.worlds.first().worldFolder, "tntleague.yml" ) ) } val blueTeam: TeamConfig = TeamConfig.fromConfig(config.getConfigurationSection("blueTeam")!!) val redTeam: TeamConfig = TeamConfig.fromConfig(config.getConfigurationSection("redTeam")!!) val lobby: Location = config.getLocation("lobby", blueTeam.spawnLocation.clone().add(redTeam.spawnLocation).multiply(0.5))!! val targetMaterial: Material = Material.matchMaterial(config.getString("targetMaterial", "IRON_BLOCK")!!)!! val minHeight: Int = config.getInt("minHeight", 0) val target: Int = config.getInt("target", -1) @JvmRecord data class TeamConfig( val spawnLocation: Location, val dealerSpawn: Location, val itemSpawn: Location, val target: Area ) { companion object { fun fromConfig(config: ConfigurationSection): TeamConfig { val spawnLocation = config.getLocation("spawn")!! val dealerSpawn = config.getLocation("dealerSpawn")!! val itemSpawn = config.getLocation("itemSpawn")!! val targetPos1 = config.getLocation("targetMin")!! val targetPos2 = config.getLocation("targetMax")!! spawnDealer(dealerSpawn) return TeamConfig(spawnLocation, dealerSpawn, itemSpawn, Area(targetPos1, targetPos2)) } private fun spawnDealer(loc: Location) = world.spawn(loc, WanderingTrader::class.java) .apply { customName(translate("dealer")) isCustomNameVisible = false isInvulnerable = true isSilent = true isCollidable = false isAware = false setAI(false) } } } }