forked from SteamWar/SteamWar
Make TNTLeague Event System Capable
This commit is contained in:
@@ -19,6 +19,10 @@
|
||||
|
||||
package de.steamwar.tntleague.config
|
||||
|
||||
import de.steamwar.message.SubMessage
|
||||
import de.steamwar.sql.Event
|
||||
import de.steamwar.sql.EventFight
|
||||
import de.steamwar.sql.Team
|
||||
import de.steamwar.tntleague.plugin
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
@@ -36,7 +40,34 @@ data class TNTLeagueConfig(
|
||||
|
||||
val blueLeader: UUID? = System.getProperty("blueLeader")?.let { UUID.fromString(it) },
|
||||
val redLeader: UUID? = System.getProperty("redLeader")?.let { UUID.fromString(it) },
|
||||
|
||||
val eventFightId: Int? = System.getProperty("fightID")?.toInt()
|
||||
) {
|
||||
lateinit var eventFight: EventFight
|
||||
lateinit var event: Event
|
||||
lateinit var eventTeamBlue: Team
|
||||
lateinit var eventTeamRed: Team
|
||||
|
||||
val blueTeam: TeamConfig
|
||||
val redTeam: TeamConfig
|
||||
|
||||
init {
|
||||
if (eventFightId != null) {
|
||||
eventFight = EventFight.get(eventFightId) ?: throw IllegalArgumentException("EventFight with ID $eventFightId not found")
|
||||
|
||||
event = Event.get(eventFight.eventID)
|
||||
|
||||
eventTeamBlue = Team.get(eventFight.teamBlue)
|
||||
eventTeamRed = Team.get(eventFight.teamRed)
|
||||
|
||||
blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Literal("§${eventTeamBlue.teamColor}${eventTeamBlue.teamName}"), eventTeamBlue.teamColor[0])
|
||||
redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Literal("§${eventTeamRed.teamColor}${eventTeamRed.teamName}"), eventTeamRed.teamColor[0])
|
||||
} else {
|
||||
blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Translatable("BLUE"), '3')
|
||||
redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Translatable("RED"), 'c')
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val config: TNTLeagueConfig by lazy { loadConfig(plugin.config) }
|
||||
|
||||
@@ -55,6 +86,8 @@ data class TNTLeagueConfig(
|
||||
)
|
||||
}.mapKeys { Material.getMaterial(it.key) ?: Material.BARRIER }
|
||||
}
|
||||
|
||||
fun isEvent() = config.eventFightId != null
|
||||
}
|
||||
|
||||
data class Price(
|
||||
|
||||
@@ -54,8 +54,8 @@ object TNTLeagueWorldConfig {
|
||||
)
|
||||
}
|
||||
|
||||
lateinit var blueTeam: TeamConfig
|
||||
lateinit var redTeam: TeamConfig
|
||||
lateinit var blueTeam: TeamWorldConfig
|
||||
lateinit var redTeam: TeamWorldConfig
|
||||
lateinit var lobby: Location
|
||||
var teamsOnSameLine by Delegates.notNull<Boolean>()
|
||||
lateinit var targetMaterial: Material
|
||||
@@ -64,8 +64,8 @@ object TNTLeagueWorldConfig {
|
||||
|
||||
init {
|
||||
try {
|
||||
blueTeam = TeamConfig.fromConfig(config.getConfigurationSection("blueTeam")!!)
|
||||
redTeam = TeamConfig.fromConfig(config.getConfigurationSection("redTeam")!!)
|
||||
blueTeam = TeamWorldConfig.fromConfig(config.getConfigurationSection("blueTeam")!!)
|
||||
redTeam = TeamWorldConfig.fromConfig(config.getConfigurationSection("redTeam")!!)
|
||||
teamsOnSameLine = abs(blueTeam.spawnLocation.blockX - redTeam.spawnLocation.blockX) < 20
|
||||
lobby = config.getWorldLocation("lobby", blueTeam.spawnLocation.clone().add(redTeam.spawnLocation).multiply(0.5))
|
||||
targetMaterial = Material.matchMaterial(config.getString("targetMaterial", "IRON_BLOCK")!!)!!
|
||||
@@ -76,39 +76,6 @@ object TNTLeagueWorldConfig {
|
||||
Bukkit.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
@JvmRecord
|
||||
data class TeamConfig(
|
||||
val spawnLocation: Location,
|
||||
val dealerSpawn: Location,
|
||||
val itemSpawn: Location,
|
||||
val target: Area
|
||||
) {
|
||||
companion object {
|
||||
fun fromConfig(config: ConfigurationSection): TeamConfig {
|
||||
val spawnLocation = config.getWorldLocation("spawn")
|
||||
val dealerSpawn = config.getWorldLocation("dealerSpawn")
|
||||
val itemSpawn = config.getWorldLocation("itemSpawn")
|
||||
val targetPos1 = config.getWorldLocation("targetMin")
|
||||
val targetPos2 = config.getWorldLocation("targetMax")
|
||||
|
||||
spawnDealer(dealerSpawn)
|
||||
|
||||
return TeamConfig(spawnLocation, dealerSpawn, itemSpawn, Area(targetPos1, targetPos2))
|
||||
}
|
||||
|
||||
private fun spawnDealer(loc: Location) = world.spawn(loc, WanderingTrader::class.java)
|
||||
.apply {
|
||||
customName(Component.text("Shop"))
|
||||
isCustomNameVisible = false
|
||||
isInvulnerable = true
|
||||
isSilent = true
|
||||
isCollidable = false
|
||||
isAware = false
|
||||
setAI(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ConfigurationSection.getWorldLocation(s: String, default: Location? = null): Location {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.tntleague.config
|
||||
|
||||
import de.steamwar.kotlin.util.Area
|
||||
import de.steamwar.message.SubMessage
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import org.bukkit.entity.WanderingTrader
|
||||
|
||||
data class TeamConfig(
|
||||
val worldConfig: TeamWorldConfig,
|
||||
|
||||
val name: SubMessage,
|
||||
val color: Char
|
||||
)
|
||||
|
||||
@JvmRecord
|
||||
data class TeamWorldConfig(
|
||||
val spawnLocation: Location,
|
||||
val dealerSpawn: Location,
|
||||
val itemSpawn: Location,
|
||||
val target: Area
|
||||
) {
|
||||
companion object {
|
||||
fun fromConfig(config: ConfigurationSection): TeamWorldConfig {
|
||||
val spawnLocation = config.getWorldLocation("spawn")
|
||||
val dealerSpawn = config.getWorldLocation("dealerSpawn")
|
||||
val itemSpawn = config.getWorldLocation("itemSpawn")
|
||||
val targetPos1 = config.getWorldLocation("targetMin")
|
||||
val targetPos2 = config.getWorldLocation("targetMax")
|
||||
|
||||
spawnDealer(dealerSpawn)
|
||||
|
||||
return TeamWorldConfig(spawnLocation, dealerSpawn, itemSpawn, Area(targetPos1, targetPos2))
|
||||
}
|
||||
|
||||
private fun spawnDealer(loc: Location) = world.spawn(loc, WanderingTrader::class.java)
|
||||
.apply {
|
||||
customName(Component.text("Shop"))
|
||||
isCustomNameVisible = false
|
||||
isInvulnerable = true
|
||||
isSilent = true
|
||||
isCollidable = false
|
||||
isAware = false
|
||||
setAI(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user