Add a bunch of config stuff.
parent
34399377a1
commit
cf745b35b9
|
@ -18,8 +18,8 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT")
|
||||
compileOnly("com.destroystokyo.paper:paper:1.16.5-R0.1-SNAPSHOT")
|
||||
compileOnly(kotlin("stdlib-jdk8"))
|
||||
compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT")
|
||||
compileOnly(kotlin("stdlib"))
|
||||
}
|
||||
|
||||
tasks.compileJava {
|
||||
|
|
|
@ -11,7 +11,6 @@ class DArena: JavaPlugin() {
|
|||
private lateinit var pointsManager: PointsManager
|
||||
private lateinit var teamManager: TeamManager
|
||||
|
||||
|
||||
// TODO:
|
||||
// Thinking:
|
||||
// - Datastructures for arenas
|
||||
|
@ -35,10 +34,8 @@ class DArena: JavaPlugin() {
|
|||
teamManager = TeamManager(File(dataFolder, "teams.yml"))
|
||||
teamManager.load()
|
||||
pointsManager = PointsManager(teamManager, File(dataFolder, "points.yml"))
|
||||
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@ package nl.kallestruik.darena.arenas
|
|||
|
||||
import nl.kallestruik.darena.arenas.world.ArenaWorld
|
||||
import nl.kallestruik.darena.util.ArenaUtil
|
||||
import org.bukkit.potion.PotionEffect
|
||||
import org.bukkit.potion.PotionEffectType
|
||||
|
||||
class Arena(
|
||||
private val config: ArenaConfig,
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package nl.kallestruik.darena.arenas
|
||||
|
||||
import nl.kallestruik.darena.types.arena.ArenaLoadout
|
||||
import nl.kallestruik.darena.types.arena.ArenaSpawn
|
||||
import nl.kallestruik.darena.util.ConfigHelper
|
||||
import java.io.File
|
||||
|
||||
data class ArenaConfig(
|
||||
var name: String = "[Missing name]",
|
||||
var spawns: List<ArenaSpawn> = emptyList(),
|
||||
var spectatorSpawn: ArenaSpawn = ArenaSpawn("default", 0.0, 100.0, 0.0, 0.0F, 0.0F),
|
||||
var spectatorSpawn: ArenaSpawn = ArenaSpawn("default", 0.0, 100.0, 0.0, 0.0F, 0.0F, "default"),
|
||||
var loadouts: List<ArenaLoadout> = emptyList(),
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
@ -23,6 +26,9 @@ data class ArenaConfig(
|
|||
if (config.contains("spectatorSpawn"))
|
||||
arenaConfig.spectatorSpawn = ArenaSpawn.load(config.getConfigurationSection("spectatorSpawn")!!)
|
||||
|
||||
if (config.contains("loadouts"))
|
||||
arenaConfig.loadouts = ArenaLoadout.loadList(config.getConfigurationSection("loadouts")!!)
|
||||
|
||||
return arenaConfig
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package nl.kallestruik.darena.arenas
|
||||
|
||||
import nl.kallestruik.darena.types.arena.ArenaSpawn
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
data class ArenaSession(
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package nl.kallestruik.darena.exceptions
|
||||
|
||||
class MaterialNotFoundException(
|
||||
message: String? = null,
|
||||
cause: Throwable? = null
|
||||
): Exception(message, cause)
|
|
@ -0,0 +1,31 @@
|
|||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import javax.naming.ConfigurationException
|
||||
|
||||
data class ArenaCheckpoint(
|
||||
val label: String,
|
||||
val lower: ArenaLocation,
|
||||
val upper: ArenaLocation,
|
||||
val spawn: String,
|
||||
) {
|
||||
companion object {
|
||||
fun loadList(section: ConfigurationSection): List<ArenaCheckpoint> {
|
||||
val list = mutableListOf<ArenaCheckpoint>()
|
||||
for (key in section.getKeys(false)) {
|
||||
list.add(load(section.getConfigurationSection(key)!!))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
fun load(section: ConfigurationSection): ArenaCheckpoint {
|
||||
return ArenaCheckpoint(
|
||||
section.name,
|
||||
ArenaLocation.load(section.getConfigurationSection("lower")!!),
|
||||
ArenaLocation.load(section.getConfigurationSection("upper")!!),
|
||||
section.getString("spawn") ?: throw ConfigurationException("Could not find required field spawn in '${section.currentPath}'")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import org.bukkit.configuration.InvalidConfigurationException
|
||||
|
||||
data class ArenaEnchantment(
|
||||
val name: String,
|
||||
val level: Int,
|
||||
) {
|
||||
companion object {
|
||||
fun loadList(section: ConfigurationSection): List<ArenaEnchantment> {
|
||||
val list = mutableListOf<ArenaEnchantment>()
|
||||
for (key in section.getKeys(false)) {
|
||||
list.add(load(section.getConfigurationSection(key)!!))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
fun load(section: ConfigurationSection): ArenaEnchantment {
|
||||
return ArenaEnchantment(
|
||||
section.getString("name") ?: throw InvalidConfigurationException("Could not find required field name in section '${section.currentPath}'"),
|
||||
section.getInt("level", 1)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
import nl.kallestruik.darena.util.ConfigHelper
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
|
||||
data class ArenaItem(
|
||||
val material: Material = Material.AIR,
|
||||
val amount: Int = 1,
|
||||
val enchantments: List<ArenaEnchantment> = listOf(),
|
||||
val unbreakable: Boolean = false,
|
||||
) {
|
||||
companion object {
|
||||
fun loadList(section: ConfigurationSection): List<ArenaItem> {
|
||||
val list = mutableListOf<ArenaItem>()
|
||||
for (key in section.getKeys(false)) {
|
||||
list.add(load(section.getConfigurationSection(key)!!))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
fun load(section: ConfigurationSection): ArenaItem {
|
||||
val enchantments = section.getConfigurationSection("enchantments")?.let {
|
||||
ArenaEnchantment.loadList(it)
|
||||
} ?: listOf()
|
||||
|
||||
return ArenaItem(
|
||||
ConfigHelper.matchMaterial(section.getString("material")!!),
|
||||
section.getInt("amount", 1),
|
||||
enchantments,
|
||||
section.getBoolean("unbreakable", false)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
|
||||
data class ArenaLoadout(
|
||||
val name: String,
|
||||
val hotbar: List<ArenaItem>,
|
||||
val armor: List<ArenaItem>,
|
||||
val offhand: ArenaItem,
|
||||
) {
|
||||
companion object {
|
||||
fun loadList(section: ConfigurationSection): List<ArenaLoadout> {
|
||||
val list = mutableListOf<ArenaLoadout>()
|
||||
for (key in section.getKeys(false)) {
|
||||
list.add(load(section.getConfigurationSection(key)!!))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
fun load(section: ConfigurationSection): ArenaLoadout {
|
||||
val hotbar = section.getConfigurationSection("hotbar")?.let {
|
||||
ArenaItem.loadList(it)
|
||||
}?: listOf()
|
||||
|
||||
val armor = section.getConfigurationSection("armor")?.let {
|
||||
ArenaItem.loadList(it)
|
||||
}?: listOf()
|
||||
|
||||
val offhand = section.getConfigurationSection("offhand")?.let {
|
||||
ArenaItem.load(it)
|
||||
}?: ArenaItem()
|
||||
|
||||
return ArenaLoadout(
|
||||
section.name,
|
||||
hotbar,
|
||||
armor,
|
||||
offhand,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
|
||||
data class ArenaLocation(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val z: Int
|
||||
) {
|
||||
companion object {
|
||||
|
||||
fun load(section: ConfigurationSection): ArenaLocation {
|
||||
return ArenaLocation(
|
||||
section.getInt("x", 0),
|
||||
section.getInt("y", 0),
|
||||
section.getInt("z", 0),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
data class ArenaPoints(
|
||||
val kill: Int,
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
package nl.kallestruik.darena.arenas
|
||||
package nl.kallestruik.darena.types.arena
|
||||
|
||||
import nl.kallestruik.darena.arenas.world.ArenaWorld
|
||||
import org.bukkit.Location
|
||||
|
@ -12,6 +12,7 @@ data class ArenaSpawn(
|
|||
val z: Double,
|
||||
val yaw: Float,
|
||||
val pitch: Float,
|
||||
val loadout: String
|
||||
) {
|
||||
fun spawn(world: ArenaWorld, player: Player) {
|
||||
player.teleport(Location(world.world, x, y, z, yaw, pitch))
|
||||
|
@ -35,7 +36,8 @@ data class ArenaSpawn(
|
|||
section.getDouble("y"),
|
||||
section.getDouble("z"),
|
||||
section.getDouble("yaw").toFloat(),
|
||||
section.getDouble("pitch").toFloat()
|
||||
section.getDouble("pitch").toFloat(),
|
||||
section.getString("loadout")!!
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package nl.kallestruik.darena.util
|
||||
|
||||
import nl.kallestruik.darena.exceptions.MaterialNotFoundException
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import java.io.*
|
||||
|
||||
|
@ -34,4 +36,9 @@ object ConfigHelper {
|
|||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(MaterialNotFoundException::class)
|
||||
fun matchMaterial(material: String): Material {
|
||||
return Material.matchMaterial(material) ?: throw MaterialNotFoundException("There is not material with the name '$material'")
|
||||
}
|
||||
}
|
|
@ -8,27 +8,57 @@
|
|||
# z: 0
|
||||
# yaw: 0
|
||||
# pitch: 0
|
||||
# loadout: "default"
|
||||
# label2:
|
||||
# x: 10
|
||||
# y: 100
|
||||
# z: 0
|
||||
# yaw: 0
|
||||
# pitch: 0
|
||||
# loadout: "default"
|
||||
# label3:
|
||||
# x: 10
|
||||
# y: 100
|
||||
# z: 10
|
||||
# yaw: 0
|
||||
# pitch: 0
|
||||
# loadout: "default"
|
||||
# label4:
|
||||
# x: 0
|
||||
# y: 100
|
||||
# z: 10
|
||||
# yaw: 0
|
||||
# pitch: 0
|
||||
# loadout: "default"
|
||||
# loadouts:
|
||||
# default:
|
||||
# hotbar:
|
||||
# weapon:
|
||||
# material: iron_axe
|
||||
# amount: 1
|
||||
# food:
|
||||
# material: cooked_beef
|
||||
# amount: 10
|
||||
# armor:
|
||||
# helmet:
|
||||
# material: golden_helmet
|
||||
# amount: 1
|
||||
# elytra:
|
||||
# material: elytra
|
||||
# amount: 1
|
||||
# leggings:
|
||||
# material: iron_leggings
|
||||
# amount: 1
|
||||
# boots:
|
||||
# material: diamond_boots
|
||||
# amount: 1
|
||||
# offhand:
|
||||
# material: shield
|
||||
# amount: 1
|
||||
#specatorSpawn:
|
||||
# x: 0
|
||||
# y: 150
|
||||
# z: 0
|
||||
# yaw: 0
|
||||
# pitch: 0
|
||||
# loadout: "none"
|
Loading…
Reference in New Issue