Basic arena loading
parent
63f40bef55
commit
f05208f1a0
|
@ -4,6 +4,7 @@
|
|||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Arena> = ArrayList()
|
||||
|
||||
fun loadArenas(arenaFolder: File) {
|
||||
Files.walk(arenaFolder.toPath()).use { walk ->
|
||||
walk.forEach { path ->
|
||||
arenas.add(Arena(
|
||||
ArenaConfig.load(path.toFile()),
|
||||
arenaUtil,
|
||||
plugin
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,10 @@
|
|||
# weapon:
|
||||
# material: iron_axe
|
||||
# amount: 1
|
||||
# enchantments:
|
||||
# name: sharpness
|
||||
# level: 5
|
||||
# unbreakable: true
|
||||
# food:
|
||||
# material: cooked_beef
|
||||
# amount: 10
|
||||
|
|
Loading…
Reference in New Issue