Add Some Fixes and Improvements

This commit is contained in:
2024-12-22 21:57:54 +01:00
parent 1ea6bd61f8
commit aaa808f90f
14 changed files with 242 additions and 58 deletions
@@ -23,12 +23,21 @@ 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<Material, Price>
val prices: Map<Material, Price>,
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) }
@@ -41,14 +50,48 @@ data class TNTLeagueConfig(
return config.getKeys(false).associateWith {
Price(
config.getInt("$it.amount"),
config.getInt("$it.price")
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)!! }
}.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<ItemExtra>
)
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() }
@@ -69,6 +69,7 @@ object TNTLeagueWorldConfig {
minHeight = config.getInt("minHeight", 0)
target = config.getInt("target", -1)
} catch (e: NullPointerException) {
e.printStackTrace()
Bukkit.shutdown()
}
}