Basic arena loading

master
kalle 2021-10-29 19:36:46 +02:00
parent 63f40bef55
commit f05208f1a0
6 changed files with 41 additions and 13 deletions

View File

@ -4,6 +4,7 @@
<facet type="minecraft" name="Minecraft"> <facet type="minecraft" name="Minecraft">
<configuration> <configuration>
<autoDetectTypes> <autoDetectTypes>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType> <platformType>ADVENTURE</platformType>
</autoDetectTypes> </autoDetectTypes>
</configuration> </configuration>

View File

@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("jvm") version "1.5.10" kotlin("jvm") version "1.5.31"
id("com.github.johnrengelman.shadow") version "7.1.0" id("com.github.johnrengelman.shadow") version "7.1.0"
} }
@ -19,7 +19,7 @@ repositories {
dependencies { dependencies {
implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT") implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT")
compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT") compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT")
compileOnly(kotlin("stdlib")) compileOnly(kotlin("stdlib-jdk8"))
} }
tasks.compileJava { tasks.compileJava {

View File

@ -2,13 +2,15 @@ package nl.kallestruik.darena.arenas
import nl.kallestruik.darena.arenas.world.ArenaWorld import nl.kallestruik.darena.arenas.world.ArenaWorld
import nl.kallestruik.darena.util.ArenaUtil import nl.kallestruik.darena.util.ArenaUtil
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.potion.PotionEffect import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType import org.bukkit.potion.PotionEffectType
class Arena( class Arena(
private val config: ArenaConfig, private val config: ArenaConfig,
private val world: ArenaWorld,
private val arenaUtil: ArenaUtil, private val arenaUtil: ArenaUtil,
private val plugin: JavaPlugin,
private val world: ArenaWorld = ArenaWorld(config.name, plugin),
) { ) {
private lateinit var session: ArenaSession private lateinit var session: ArenaSession
// Simple stuff done: 0.001474s // Simple stuff done: 0.001474s
@ -23,6 +25,7 @@ class Arena(
// Fully done: 0.0982557 // Fully done: 0.0982557
fun start() { fun start() {
//TODO: Redo everything in here.
// Create a new session // Create a new session
session = ArenaSession() session = ArenaSession()
// Add all participants and spectators // Add all participants and spectators
@ -32,7 +35,7 @@ class Arena(
world.reset() world.reset()
// Place all spectators in the arena // Place all spectators in the arena
session.spectators.forEach { session.spectators.forEach {
config.spectatorSpawn.spawn(world, it) // config.spectatorSpawn.spawn(world, it)
} }
// Randomize spawns // Randomize spawns

View File

@ -11,15 +11,15 @@ import java.nio.file.Path
class ArenaWorld( class ArenaWorld(
val config: ArenaWorldConfig, val name: String,
val plugin: JavaPlugin val plugin: JavaPlugin
) { ) {
var world: World var world: World
init { init {
load() load()
world = Bukkit.createWorld(ArenaWorldCreator(config.name)) world = Bukkit.createWorld(ArenaWorldCreator(name))
?: throw ArenaWorldCreationException("Exception while creating bukkit world for arena \"${config.name}\".") ?: throw ArenaWorldCreationException("Exception while creating bukkit world for arena \"$name\".")
} }
@Throws(ArenaWorldLoadException::class) @Throws(ArenaWorldLoadException::class)
fun reset() { fun reset() {
@ -30,7 +30,7 @@ class ArenaWorld(
@Throws(ArenaWorldSaveException::class) @Throws(ArenaWorldSaveException::class)
fun save() { fun save() {
try { try {
val savePath = Path.of(plugin.dataFolder.path, "worlds", config.name) val savePath = Path.of(plugin.dataFolder.path, "worlds", name)
Files.walk(savePath).use { walk -> Files.walk(savePath).use { walk ->
walk.sorted(Comparator.reverseOrder()).forEach { path -> walk.sorted(Comparator.reverseOrder()).forEach { path ->
Files.delete(path) Files.delete(path)
@ -48,14 +48,14 @@ class ArenaWorld(
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
throw ArenaWorldSaveException("There was an issue saving the world for arena \"${config.name}\" to a safe location!", e) throw ArenaWorldSaveException("There was an issue saving the world for arena \"$name\" to a safe location!", e)
} }
} }
@Throws(ArenaWorldLoadException::class) @Throws(ArenaWorldLoadException::class)
private fun load() { private fun load() {
try { try {
val loadPath = Path.of(plugin.dataFolder.path, "worlds", config.name) val loadPath = Path.of(plugin.dataFolder.path, "worlds", name)
Files.walk(world.worldFolder.toPath()).use { walk -> Files.walk(world.worldFolder.toPath()).use { walk ->
walk.sorted(Comparator.reverseOrder()).forEach { path -> walk.sorted(Comparator.reverseOrder()).forEach { path ->
Files.delete(path) Files.delete(path)
@ -73,7 +73,7 @@ class ArenaWorld(
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
throw ArenaWorldLoadException("There was an issue load the world for arena \"${config.name}\"!", e) throw ArenaWorldLoadException("There was an issue load the world for arena \"$name\"!", e)
} }
} }
} }

View File

@ -1,7 +1,27 @@
package nl.kallestruik.darena.managers package nl.kallestruik.darena.managers
import nl.kallestruik.darena.arenas.Arena import nl.kallestruik.darena.arenas.Arena
import nl.kallestruik.darena.arenas.ArenaConfig
import nl.kallestruik.darena.util.ArenaUtil
import org.bukkit.plugin.java.JavaPlugin
import java.io.File
import java.nio.file.Files
class ArenaManager { class ArenaManager(
private val arenaUtil: ArenaUtil,
private val plugin: JavaPlugin,
) {
private val arenas: MutableList<Arena> = ArrayList() private val arenas: MutableList<Arena> = ArrayList()
fun loadArenas(arenaFolder: File) {
Files.walk(arenaFolder.toPath()).use { walk ->
walk.forEach { path ->
arenas.add(Arena(
ArenaConfig.load(path.toFile()),
arenaUtil,
plugin
))
}
}
}
} }

View File

@ -43,6 +43,10 @@
# weapon: # weapon:
# material: iron_axe # material: iron_axe
# amount: 1 # amount: 1
# enchantments:
# name: sharpness
# level: 5
# unbreakable: true
# food: # food:
# material: cooked_beef # material: cooked_beef
# amount: 10 # amount: 10