/* * 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 org.bukkit.Material import org.bukkit.configuration.ConfigurationSection import org.bukkit.configuration.file.FileConfiguration import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.BookMeta import org.bukkit.inventory.meta.Damageable import org.bukkit.inventory.meta.ItemMeta import java.util.UUID data class TNTLeagueConfig( val startDelay: Int = 10, val gameTime: Int = 60 * 20, val prices: Map, val blueLeader: UUID? = System.getProperty("blueLeader")?.let { UUID.fromString(it) }, val redLeader: UUID? = System.getProperty("redLeader")?.let { UUID.fromString(it) }, ) { companion object { val config: TNTLeagueConfig by lazy { loadConfig(plugin.config) } private fun loadConfig(config: FileConfiguration): TNTLeagueConfig { return TNTLeagueConfig(config.getInt("startDelay"), config.getInt("gameTime"), loadPrices(config.getConfigurationSection("prices")!!)) } private fun loadPrices(config: ConfigurationSection): Map { return config.getKeys(false).associateWith { Price( config.getInt("$it.amount"), config.getInt("$it.price"), config.getString("$it.category")?.let { s -> categoryFromString[s] } ?: ItemCategory.REDSTONE, config.getInt("$it.pinned", -1), config.getStringList("$it.extras").map { s -> extrasFromString[s]!! }.toSet() ) }.mapKeys { Material.getMaterial(it.key) ?: Material.BARRIER } } } data class Price( val amount: Int, val price: Int, val category: ItemCategory, val pinned: Int, val extras: Set ) enum class ItemCategory { REDSTONE, BLOCKS, TOOLS, ANGLES; } enum class ItemExtra(val func: (item: ItemMeta) -> ItemMeta) { ONESHOT({ if (it is Damageable) { it.damage = 384 } it }), FLAME({ it.addEnchant(Enchantment.FLAME, 1, false) it }), UNBREAKING({ it.addEnchant(Enchantment.UNBREAKING, 1, false) it }) } } val categoryFromString = TNTLeagueConfig.ItemCategory.entries.associateBy { it.name.lowercase() } val extrasFromString = TNTLeagueConfig.ItemExtra.entries.associateBy { it.name.lowercase() }