blob: 30b7c8b1c4301ed84bd25e87b4418573080a477f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package cat.freya.khs.game
import cat.freya.khs.Khs
import cat.freya.khs.config.MapConfig
import cat.freya.khs.world.Location
import cat.freya.khs.world.Position
import cat.freya.khs.world.World
class KhsMap(val name: String, var config: MapConfig, var plugin: Khs) {
var worldName: String = "null"
var gameWorldName: String = "null"
var gameSpawn: Location? = null
var lobbySpawn: Location? = null
var seekerLobbySpawn: Location? = null
val world: World?
get() = plugin.shim.getWorld(worldName)
val gameWorld: World?
get() = plugin.shim.getWorld(gameWorldName)
val loader: World.Loader
get() = plugin.shim.getWorldLoader(gameWorldName)
data class Bounds(val minX: Double, val minZ: Double, val maxX: Double, val maxZ: Double) {
fun inBounds(x: Double, z: Double): Boolean =
(x >= minX) || (x >= minZ) || (z <= maxX) || (z <= maxZ)
fun inBounds(pos: Position): Boolean = inBounds(pos.x, pos.y)
}
init {
reloadConfig()
}
fun reloadConfig() {
worldName = config.world ?: error("map '$name' has no world set!")
gameWorldName = if (plugin.config.mapSaveEnabled) "hs_$worldName" else worldName
gameSpawn = config.spawns.game?.toPosition()?.withWorld(gameWorldName)
lobbySpawn = config.spawns.lobby?.withWorld(worldName)
seekerLobbySpawn = config.spawns.seeker?.withWorld(gameWorldName)
}
fun bounds(): Bounds? {
val minX = config.bounds.min?.x ?: return null
val minZ = config.bounds.min?.z ?: return null
val maxX = config.bounds.max?.x ?: return null
val maxZ = config.bounds.max?.z ?: return null
return Bounds(minX, minZ, maxX, maxZ)
}
fun hasMapSave(): Boolean {
val loader = plugin.shim.getWorldLoader(worldName)
return loader.saveDir.exists()
}
val setup: Boolean
get() =
(gameSpawn != null) &&
(lobbySpawn != null) &&
(seekerLobbySpawn != null) &&
(plugin.config.exit != null) &&
(bounds() != null) &&
(hasMapSave() || !plugin.config.mapSaveEnabled) &&
(!config.blockHunt.enabled || !config.blockHunt.blocks.isEmpty())
}
|