Add TNTLeague Module

This commit is contained in:
2024-08-16 11:38:54 +02:00
parent f8f184514b
commit 66f5b6491c
24 changed files with 1446 additions and 0 deletions
@@ -0,0 +1,35 @@
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
data class TNTLeagueConfig(
val startDelay: Int = 10,
val gameTime: Int = 60 * 20,
val prices: Map<Material, Price>
) {
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<Material, Price> {
return config.getKeys(false).associateWith {
Price(
config.getInt("$it.amount"),
config.getInt("$it.price")
)
}.mapKeys { Material.getMaterial(it.key)!! }
}
}
data class Price(
val amount: Int,
val price: Int,
)
}
@@ -0,0 +1,75 @@
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)
}
}
}
}