Add map-specific spawn locations for items and players
This commit is contained in:
parent
29b7b43a54
commit
b81e6913fc
11 changed files with 121 additions and 75 deletions
|
@ -4,14 +4,14 @@ import de.moritzruth.spigot_ttt.game.AbortCommand
|
|||
import de.moritzruth.spigot_ttt.game.InfoCommand
|
||||
import de.moritzruth.spigot_ttt.game.ReviveCommand
|
||||
import de.moritzruth.spigot_ttt.game.StartCommand
|
||||
import de.moritzruth.spigot_ttt.game.items.AddItemSpawnCommand
|
||||
import de.moritzruth.spigot_ttt.game.worlds.AddSpawnLocationCommand
|
||||
import de.moritzruth.spigot_ttt.game.worlds.VotingCommand
|
||||
|
||||
object CommandManager {
|
||||
fun initializeCommands() {
|
||||
StartCommand()
|
||||
AbortCommand()
|
||||
AddItemSpawnCommand()
|
||||
AddSpawnLocationCommand()
|
||||
ReviveCommand()
|
||||
ResourcepackCommand()
|
||||
ReloadTTTConfigCommand()
|
||||
|
|
|
@ -16,11 +16,7 @@ import de.moritzruth.spigot_ttt.game.worlds.TTTWorld
|
|||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.call
|
||||
import de.moritzruth.spigot_ttt.utils.heartsToHealth
|
||||
import de.moritzruth.spigot_ttt.utils.teleportToWorldSpawn
|
||||
import org.bukkit.GameRule
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.SoundCategory
|
||||
import org.bukkit.*
|
||||
import org.bukkit.block.Block
|
||||
import kotlin.random.Random
|
||||
|
||||
|
@ -124,6 +120,7 @@ object GameManager {
|
|||
|
||||
PlayerManager.createTTTPlayers()
|
||||
phase = GamePhase.PREPARING
|
||||
PlayerManager.teleportPlayersToSpawnLocations()
|
||||
|
||||
world.run {
|
||||
setStorm(Random.nextInt(4) == 1)
|
||||
|
@ -133,7 +130,6 @@ object GameManager {
|
|||
}
|
||||
|
||||
PlayerManager.tttPlayers.forEach {
|
||||
it.player.teleportToWorldSpawn()
|
||||
it.addDefaultClassItems()
|
||||
it.player.health = heartsToHealth(10.0)
|
||||
}
|
||||
|
@ -160,8 +156,8 @@ object GameManager {
|
|||
|
||||
if (it.role.group.canUseTeamChat) {
|
||||
it.player.sendMessage(
|
||||
"${TTTPlugin.prefix}Schreibe '$TEAM_CHAT_PREFIX' vor deine Nachrichten, um den Team-Chat" +
|
||||
"zu verwenden.")
|
||||
"${TTTPlugin.prefix}${ChatColor.GOLD}Schreibe einen Punkt vor deine Nachrichten, um den " +
|
||||
"Team-Chat zu verwenden.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
package de.moritzruth.spigot_ttt.game.items
|
||||
|
||||
import de.moritzruth.spigot_ttt.COMMAND_RESPONSE_PREFIX
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.EmptyTabCompleter
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class AddItemSpawnCommand: CommandExecutor {
|
||||
init {
|
||||
plugin.getCommand("additemspawn")?.let {
|
||||
it.setExecutor(this)
|
||||
it.tabCompleter = EmptyTabCompleter
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (sender !is Player) {
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Dieser Befehl kann nur von Spielern verwendet werden.")
|
||||
return true
|
||||
}
|
||||
|
||||
ItemSpawner.addItemSpawnLocation(sender.location)
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.GREEN}Ein Waffenspawn wurde an deiner Position hinzugefügt.")
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -1,29 +1,9 @@
|
|||
package de.moritzruth.spigot_ttt.game.items
|
||||
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.utils.ConfigurationFile
|
||||
import de.moritzruth.spigot_ttt.utils.roundToCenter
|
||||
import org.bukkit.Location
|
||||
import java.util.*
|
||||
|
||||
object ItemSpawner {
|
||||
private const val CONFIG_PATH = "spawn-locations"
|
||||
|
||||
private val spawnLocationsConfig = ConfigurationFile("spawnLocations")
|
||||
|
||||
private fun getSpawnLocations(): Set<Location> {
|
||||
return spawnLocationsConfig.getStringList(CONFIG_PATH).map {
|
||||
val (x, y, z) = it.split(":").map(String::toDouble)
|
||||
Location(GameManager.world, x, y, z)
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
private fun setSpawnLocations(spawnLocations: Set<Location>) {
|
||||
spawnLocationsConfig.set(CONFIG_PATH, spawnLocations.map {
|
||||
"${it.x}:${it.y}:${it.z}"
|
||||
})
|
||||
}
|
||||
|
||||
fun spawnWeapons() {
|
||||
val spawningItems = mutableListOf<TTTItem<*>>()
|
||||
for (tttItem in ItemManager.ITEMS) {
|
||||
|
@ -32,7 +12,7 @@ object ItemSpawner {
|
|||
}
|
||||
|
||||
var itemsIterator = spawningItems.shuffled().iterator()
|
||||
for (location in getSpawnLocations()) {
|
||||
for (location in GameManager.tttWorld!!.spawnLocations.getItemSpawnLocations()) {
|
||||
if (!itemsIterator.hasNext()) {
|
||||
itemsIterator = spawningItems.shuffled().iterator()
|
||||
}
|
||||
|
@ -40,12 +20,4 @@ object ItemSpawner {
|
|||
ItemManager.dropItem(location, itemsIterator.next())
|
||||
}
|
||||
}
|
||||
|
||||
fun addItemSpawnLocation(location: Location) {
|
||||
val spawnLocations = getSpawnLocations().toMutableSet()
|
||||
|
||||
spawnLocations.add(location.roundToCenter())
|
||||
setSpawnLocations(spawnLocations)
|
||||
spawnLocationsConfig.save()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,16 @@ object PlayerManager {
|
|||
playersWithoutRole.forEach { tttPlayers.add(TTTPlayer(it, Role.INNOCENT, classesIterator.next())) }
|
||||
}
|
||||
|
||||
fun teleportPlayersToSpawnLocations() {
|
||||
fun createIterator() = GameManager.tttWorld!!.spawnLocations.getPlayerSpawnLocations().shuffled().iterator()
|
||||
var spawnLocationsIterator = createIterator()
|
||||
|
||||
for (tttPlayer in tttPlayers) {
|
||||
if (!spawnLocationsIterator.hasNext()) spawnLocationsIterator = createIterator()
|
||||
tttPlayer.player.teleport(spawnLocationsIterator.next())
|
||||
}
|
||||
}
|
||||
|
||||
class NotEnoughPlayersException(
|
||||
val actual: Int,
|
||||
val required: Int
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package de.moritzruth.spigot_ttt.game.worlds
|
||||
|
||||
import de.moritzruth.spigot_ttt.COMMAND_RESPONSE_PREFIX
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.createTabCompleter
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class AddSpawnLocationCommand: CommandExecutor {
|
||||
init {
|
||||
plugin.getCommand("addspawnlocation")?.let {
|
||||
it.setExecutor(this)
|
||||
it.tabCompleter = createTabCompleter { _, index -> when(index) {
|
||||
0 -> listOf("item", "player")
|
||||
else -> null
|
||||
} }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (sender !is Player) {
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Dieser Befehl kann nur von Spielern verwendet werden.")
|
||||
} else if (args.count() == 0) {
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Falsche Verwendung.")
|
||||
} else {
|
||||
val tttWorld = GameManager.tttWorld
|
||||
if (tttWorld == null) {
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Du befindest dich nicht in einer TTT-Welt.")
|
||||
} else {
|
||||
when(args[0].toLowerCase()) {
|
||||
"item" -> tttWorld.spawnLocations.addItemSpawnLocation(sender.location)
|
||||
"player" -> tttWorld.spawnLocations.addPlayerSpawnLocation(sender.location)
|
||||
}
|
||||
|
||||
sender.sendMessage("$COMMAND_RESPONSE_PREFIX${ChatColor.GREEN}Ein Spawnpunkt wurde an deiner " +
|
||||
"Position hinzugefügt.")
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package de.moritzruth.spigot_ttt.game.worlds
|
||||
|
||||
import de.moritzruth.spigot_ttt.utils.getSpawnLocations
|
||||
import de.moritzruth.spigot_ttt.utils.roundToCenter
|
||||
import de.moritzruth.spigot_ttt.utils.setSpawnLocations
|
||||
import org.bukkit.Location
|
||||
|
||||
class SpawnLocationsManager(private val tttWorld: TTTWorld) {
|
||||
fun getItemSpawnLocations() = tttWorld.config.getSpawnLocations("spawn-locations.items", tttWorld.world!!, false)
|
||||
private fun setItemSpawnLocations(spawnLocations: Set<Location>) =
|
||||
tttWorld.config.setSpawnLocations("spawn-locations.items", spawnLocations, false)
|
||||
|
||||
fun getPlayerSpawnLocations() = tttWorld.config.getSpawnLocations("spawn-locations.players", tttWorld.world!!, true)
|
||||
private fun setPlayerSpawnLocations(spawnLocations: Set<Location>) =
|
||||
tttWorld.config.setSpawnLocations("spawn-locations.players", spawnLocations, true)
|
||||
|
||||
fun addItemSpawnLocation(location: Location) {
|
||||
val spawnLocations = getItemSpawnLocations().toMutableSet()
|
||||
spawnLocations.add(location.roundToCenter())
|
||||
setItemSpawnLocations(spawnLocations)
|
||||
tttWorld.config.save()
|
||||
}
|
||||
|
||||
fun addPlayerSpawnLocation(location: Location) {
|
||||
val spawnLocations = getPlayerSpawnLocations().toMutableSet()
|
||||
spawnLocations.add(location.roundToCenter())
|
||||
setPlayerSpawnLocations(spawnLocations)
|
||||
tttWorld.config.save()
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ class TTTWorld(private val sourceWorldDir: File) {
|
|||
private val actualWorldName = "${WORLD_PREFIX}${name}"
|
||||
private val worldDir = plugin.server.worldContainer.resolve("./$actualWorldName")
|
||||
var world: World? = plugin.server.getWorld(actualWorldName); private set
|
||||
val spawnLocations = SpawnLocationsManager(this)
|
||||
|
||||
init {
|
||||
if (world != null) unloadWorld()
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package de.moritzruth.spigot_ttt.utils
|
||||
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.World
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
|
||||
fun ConfigurationSection.getSpawnLocations(path: String, world: World, withDirection: Boolean): Set<Location> =
|
||||
getStringList(path).map {
|
||||
val parts = it.split(":")
|
||||
val (x, y, z) = parts.map(String::toDouble)
|
||||
val yaw = if (withDirection) parts[3].toFloat() else 0F
|
||||
val pitch = if (withDirection) parts[4].toFloat() else 0F
|
||||
|
||||
Location(world, x, y, z, yaw, pitch)
|
||||
}.toSet()
|
||||
|
||||
fun ConfigurationSection.setSpawnLocations(path: String, locations: Iterable<Location>, withDirection: Boolean) =
|
||||
set(path, locations.map { location ->
|
||||
"${location.x}:${location.y}:${location.z}"
|
||||
.let { if (withDirection) "${it}:${location.yaw}:${location.pitch}" else it }
|
||||
})
|
|
@ -6,5 +6,6 @@ fun Location.roundToCenter() =
|
|||
Location(world,
|
||||
roundToHalf(x),
|
||||
roundToHalf(y),
|
||||
roundToHalf(z)
|
||||
roundToHalf(z),
|
||||
yaw, pitch
|
||||
)
|
||||
|
|
|
@ -22,10 +22,10 @@ commands:
|
|||
permission: ttt.abort
|
||||
description: Go back to the lobby world and abort the TTT game, if it is running
|
||||
|
||||
additemspawn:
|
||||
usage: /additemspawn
|
||||
permission: ttt.additemspawn
|
||||
description: Add an item spawn
|
||||
addspawnlocation:
|
||||
usage: /addspawnlocation <'item'|'player'>
|
||||
permission: ttt.addspawnlocation
|
||||
description: Add an item or player spawn
|
||||
|
||||
revive:
|
||||
usage: /revive [player] ['here']
|
||||
|
|
Reference in a new issue