From f05208f1a0c36174b189e0a6b9fd47cf4621cf83 Mon Sep 17 00:00:00 2001 From: Kalle Struik Date: Fri, 29 Oct 2021 19:36:46 +0200 Subject: [PATCH] Basic arena loading --- .idea/modules/DArena.main.iml | 1 + build.gradle.kts | 4 ++-- .../nl/kallestruik/darena/arenas/Arena.kt | 9 +++++--- .../darena/arenas/world/ArenaWorld.kt | 14 ++++++------ .../darena/managers/ArenaManager.kt | 22 ++++++++++++++++++- src/main/resources/template/arena.yml | 4 ++++ 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/.idea/modules/DArena.main.iml b/.idea/modules/DArena.main.iml index c462275..f5de878 100644 --- a/.idea/modules/DArena.main.iml +++ b/.idea/modules/DArena.main.iml @@ -4,6 +4,7 @@ + PAPER ADVENTURE diff --git a/build.gradle.kts b/build.gradle.kts index 9dff59e..97049d4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.5.10" + kotlin("jvm") version "1.5.31" id("com.github.johnrengelman.shadow") version "7.1.0" } @@ -19,7 +19,7 @@ repositories { dependencies { implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT") compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT") - compileOnly(kotlin("stdlib")) + compileOnly(kotlin("stdlib-jdk8")) } tasks.compileJava { diff --git a/src/main/kotlin/nl/kallestruik/darena/arenas/Arena.kt b/src/main/kotlin/nl/kallestruik/darena/arenas/Arena.kt index 5ce3580..235c634 100644 --- a/src/main/kotlin/nl/kallestruik/darena/arenas/Arena.kt +++ b/src/main/kotlin/nl/kallestruik/darena/arenas/Arena.kt @@ -2,14 +2,16 @@ package nl.kallestruik.darena.arenas import nl.kallestruik.darena.arenas.world.ArenaWorld import nl.kallestruik.darena.util.ArenaUtil +import org.bukkit.plugin.java.JavaPlugin import org.bukkit.potion.PotionEffect import org.bukkit.potion.PotionEffectType class Arena( private val config: ArenaConfig, - private val world: ArenaWorld, private val arenaUtil: ArenaUtil, -) { + private val plugin: JavaPlugin, + private val world: ArenaWorld = ArenaWorld(config.name, plugin), + ) { private lateinit var session: ArenaSession // Simple stuff done: 0.001474s // createArena start: 0.0001026s @@ -23,6 +25,7 @@ class Arena( // Fully done: 0.0982557 fun start() { + //TODO: Redo everything in here. // Create a new session session = ArenaSession() // Add all participants and spectators @@ -32,7 +35,7 @@ class Arena( world.reset() // Place all spectators in the arena session.spectators.forEach { - config.spectatorSpawn.spawn(world, it) +// config.spectatorSpawn.spawn(world, it) } // Randomize spawns diff --git a/src/main/kotlin/nl/kallestruik/darena/arenas/world/ArenaWorld.kt b/src/main/kotlin/nl/kallestruik/darena/arenas/world/ArenaWorld.kt index b314fe8..e5a25a1 100644 --- a/src/main/kotlin/nl/kallestruik/darena/arenas/world/ArenaWorld.kt +++ b/src/main/kotlin/nl/kallestruik/darena/arenas/world/ArenaWorld.kt @@ -11,15 +11,15 @@ import java.nio.file.Path class ArenaWorld( - val config: ArenaWorldConfig, + val name: String, val plugin: JavaPlugin ) { var world: World init { load() - world = Bukkit.createWorld(ArenaWorldCreator(config.name)) - ?: throw ArenaWorldCreationException("Exception while creating bukkit world for arena \"${config.name}\".") + world = Bukkit.createWorld(ArenaWorldCreator(name)) + ?: throw ArenaWorldCreationException("Exception while creating bukkit world for arena \"$name\".") } @Throws(ArenaWorldLoadException::class) fun reset() { @@ -30,7 +30,7 @@ class ArenaWorld( @Throws(ArenaWorldSaveException::class) fun save() { 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 -> walk.sorted(Comparator.reverseOrder()).forEach { path -> Files.delete(path) @@ -48,14 +48,14 @@ class ArenaWorld( } } } 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) private fun load() { 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 -> walk.sorted(Comparator.reverseOrder()).forEach { path -> Files.delete(path) @@ -73,7 +73,7 @@ class ArenaWorld( } } } 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) } } } \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/darena/managers/ArenaManager.kt b/src/main/kotlin/nl/kallestruik/darena/managers/ArenaManager.kt index c5a59ea..266efad 100644 --- a/src/main/kotlin/nl/kallestruik/darena/managers/ArenaManager.kt +++ b/src/main/kotlin/nl/kallestruik/darena/managers/ArenaManager.kt @@ -1,7 +1,27 @@ package nl.kallestruik.darena.managers 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 = ArrayList() + + fun loadArenas(arenaFolder: File) { + Files.walk(arenaFolder.toPath()).use { walk -> + walk.forEach { path -> + arenas.add(Arena( + ArenaConfig.load(path.toFile()), + arenaUtil, + plugin + )) + } + } + } } \ No newline at end of file diff --git a/src/main/resources/template/arena.yml b/src/main/resources/template/arena.yml index a6b66ae..cf0cd7a 100644 --- a/src/main/resources/template/arena.yml +++ b/src/main/resources/template/arena.yml @@ -43,6 +43,10 @@ # weapon: # material: iron_axe # amount: 1 +# enchantments: +# name: sharpness +# level: 5 +# unbreakable: true # food: # material: cooked_beef # amount: 10