Make TNTLeague Event System Capable

This commit is contained in:
2025-02-01 21:50:36 +01:00
parent 90666e2d20
commit 3d153d49b5
10 changed files with 182 additions and 79 deletions
@@ -72,9 +72,12 @@ public class Message {
pattern += fromRB(resourceBundle, message);
for (int i = 0; i < params.length; i++) {
if (params[i] instanceof SubMessage) {
SubMessage smsg = (SubMessage) params[i];
if (params[i] instanceof SubMessage.Translatable) {
SubMessage.Translatable smsg = (SubMessage.Translatable) params[i];
params[i] = parse(smsg.getMessage(), sender, smsg.getParams());
} else if (params[i] instanceof SubMessage.Literal) {
SubMessage.Literal smsg = (SubMessage.Literal) params[i];
params[i] = smsg.getMessage();
}
}
@@ -19,20 +19,33 @@
package de.steamwar.message;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
public class SubMessage {
@AllArgsConstructor
public abstract class SubMessage {
private final String message;
private final Object[] params;
public SubMessage(String message, Object... params) {
this.message = message;
this.params = params;
@Getter
public static class Translatable extends SubMessage {
private final Object[] params;
public Translatable(String message, Object... params) {
super(message);
this.params = params;
}
public Translatable(String message) {
super(message);
this.params = new Object[0];
}
}
public SubMessage(String message) {
this.message = message;
this.params = new Object[0];
@Getter
public static class Literal extends SubMessage {
public Literal(String message) {
super(message);
}
}
}
@@ -21,8 +21,8 @@ package de.steamwar.tntleague.command
import de.steamwar.command.SWCommand
import de.steamwar.command.TypeValidator
import de.steamwar.message.SubMessage
import de.steamwar.tntleague.colorByTeam
import de.steamwar.tntleague.config.TNTLeagueConfig
import de.steamwar.tntleague.game.TNTLeagueGame
import de.steamwar.tntleague.message
import net.md_5.bungee.api.chat.ClickEvent
@@ -32,6 +32,7 @@ object InviteCommand: SWCommand("invite") {
@Register
fun invitePlayer(@Validator("isLeader") sender: Player, target: Player) {
if (TNTLeagueConfig.isEvent()) return
if (TNTLeagueGame.state != TNTLeagueGame.GameState.LOBBY) return
if (TNTLeagueGame.getTeam(target) != null) return
@@ -39,8 +40,8 @@ object InviteCommand: SWCommand("invite") {
team.invites.add(target)
message
.send("INVITED", target, message.parse("INVITED_HOVER", target, SubMessage(team.name)),
ClickEvent(ClickEvent.Action.RUN_COMMAND, "/accept " + sender.name), sender.name.colorByTeam(team), SubMessage(team.name), )
.send("INVITED", target, message.parse("INVITED_HOVER", target, team.name),
ClickEvent(ClickEvent.Action.RUN_COMMAND, "/accept " + sender.name), sender.name.colorByTeam(team), team.name)
message.send("INVITED_PLAYER", sender, target.name)
}
@@ -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)
}
}
}
@@ -66,7 +66,7 @@ object GlobalListener: Listener {
fun onPlayerMove(e: PlayerMoveEvent) {
if (e.to.blockY < TNTLeagueWorldConfig.minHeight) {
when (val team = TNTLeagueGame.getTeam(e.player)) {
is TNTLeagueTeam -> e.player.teleport(team.config.spawnLocation)
is TNTLeagueTeam -> e.player.teleport(team.config.worldConfig.spawnLocation)
null -> e.player.teleport(TNTLeagueWorldConfig.blueTeam.spawnLocation)
}
}
@@ -87,7 +87,7 @@ object GlobalListener: Listener {
@EventHandler
fun onPlayerRespawn(e: PlayerRespawnEvent) {
when (val team = TNTLeagueGame.getTeam(e.player)) {
is TNTLeagueTeam -> e.respawnLocation = team.config.spawnLocation
is TNTLeagueTeam -> e.respawnLocation = team.config.worldConfig.spawnLocation
null -> e.respawnLocation = TNTLeagueWorldConfig.lobby
}
}
@@ -100,7 +100,7 @@ object GlobalListener: Listener {
val fightTeam = TNTLeagueGame.getTeam(player)
if (fightTeam != null) {
message.broadcastPrefixless("PARTICIPANT_CHAT", SubMessage(fightTeam.name), player.name, msg)
message.broadcastPrefixless("PARTICIPANT_CHAT", fightTeam.name, player.name, msg)
} else {
message.broadcastPrefixless("SPECTATOR_CHAT", player.name, msg)
}
@@ -64,8 +64,8 @@ object TNTLeagueGame {
var gameTimeRemaining: Int = TNTLeagueConfig.config.gameTime
val blueTeam = TNTLeagueTeam(TNTLeagueWorldConfig.blueTeam, TNTLeagueTeam.Team.BLUE)
val redTeam = TNTLeagueTeam(TNTLeagueWorldConfig.redTeam, TNTLeagueTeam.Team.RED)
val blueTeam = TNTLeagueTeam(TNTLeagueConfig.config.blueTeam)
val redTeam = TNTLeagueTeam(TNTLeagueConfig.config.redTeam)
private lateinit var start: Timestamp
@@ -156,10 +156,18 @@ object TNTLeagueGame {
fun getTeam(player: Player) = if (player in blueTeam.members) blueTeam else if (player in redTeam.members) redTeam else null
fun getFreeTeam(player: Player) = if (blueTeam.leader == null && (TNTLeagueConfig.config.blueLeader == null || player.uniqueId == TNTLeagueConfig.config.blueLeader)) blueTeam
fun getFreeTeam(player: Player) = if (TNTLeagueConfig.isEvent()) getEventFreeTeam(player) else getNormalFreeTeam(player)
private fun getNormalFreeTeam(player: Player) = if (blueTeam.leader == null && (TNTLeagueConfig.config.blueLeader == null || player.uniqueId == TNTLeagueConfig.config.blueLeader)) blueTeam
else if (redTeam.leader == null && TNTLeagueConfig.config.redLeader == null || player.uniqueId == TNTLeagueConfig.config.redLeader) redTeam
else null
private fun getEventFreeTeam(player: Player) = SteamwarUser.get(player.uniqueId).let { user ->
if (user.team == TNTLeagueConfig.config.eventTeamBlue.teamId && blueTeam.members.size < TNTLeagueConfig.config.event.maximumTeamMembers) blueTeam
else if (user.team == TNTLeagueConfig.config.eventTeamRed.teamId && redTeam.members.size < TNTLeagueConfig.config.event.maximumTeamMembers) redTeam
else null
}
fun checkStart() {
if (blueTeam.isReady && redTeam.isReady) {
blueTeam.leader?.inventory?.clear()
@@ -209,18 +217,26 @@ object TNTLeagueGame {
fun win(tntLeagueTeam: TNTLeagueTeam, reason: WinReason) {
if (state != GameState.RUNNING) return
end()
plugin.server.onlinePlayers.forEach { message.send("TEAM_WIN", it, SubMessage(tntLeagueTeam.name)) }
plugin.server.onlinePlayers.forEach { message.send("TEAM_WIN", it, tntLeagueTeam.name) }
explode(tntLeagueTeam.opposite)
if (TNTLeagueConfig.isEvent()) {
TNTLeagueConfig.config.eventFight.ergebnis = tntLeagueTeam.ergebnisInt
}
}
fun draw(reason: WinReason) {
if (state != GameState.RUNNING) return
end()
message.broadcast("DRAW")
if (TNTLeagueConfig.isEvent()) {
TNTLeagueConfig.config.eventFight.ergebnis = 3
}
}
fun explode(team: TNTLeagueTeam) {
Area(team.config.spawnLocation.clone().add(20.0, 30.0, 20.0), team.config.spawnLocation.clone().subtract(20.0, 0.0, 20.0).add(0.0, 30.0, 0.0))
Area(team.config.worldConfig.spawnLocation.clone().add(20.0, 30.0, 20.0), team.config.worldConfig.spawnLocation.clone().subtract(20.0, 0.0, 20.0).add(0.0, 30.0, 0.0))
.locations
.filterIndexed { index, _ -> index % 7 == 0 }
.forEachIndexed { index, location ->
@@ -235,8 +251,8 @@ object TNTLeagueGame {
plugin.server.worlds.first().name,
"TNTLeague",
"",
blueTeam.name.colorByTeam(blueTeam),
redTeam.name.colorByTeam(redTeam),
blueTeam.name.message.colorByTeam(blueTeam),
redTeam.name.message.colorByTeam(redTeam),
state.lobbyName,
TNTLeagueConfig.config.gameTime - gameTimeRemaining,
blueTeam.leader?.let { SteamwarUser.get(it.uniqueId).id } ?: 0,
@@ -22,6 +22,7 @@ package de.steamwar.tntleague.game
import de.steamwar.message.SubMessage
import de.steamwar.tntleague.colorByTeam
import de.steamwar.tntleague.config.TNTLeagueWorldConfig
import de.steamwar.tntleague.config.TeamConfig
import de.steamwar.tntleague.config.targetedBlocks
import de.steamwar.tntleague.game.TNTLeagueGame.WinReason
import de.steamwar.tntleague.game.TNTLeagueGame.updateFightinfo
@@ -32,11 +33,10 @@ import net.kyori.adventure.text.Component
import org.bukkit.GameMode
import org.bukkit.Material
import org.bukkit.Sound
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private val team: Team) {
data class TNTLeagueTeam(val config: TeamConfig) {
var leader: Player? = null
set(player) {
@@ -52,11 +52,11 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va
val members = mutableListOf<Player>()
val invites = mutableListOf<Player>()
val name: String
get() = team.name.uppercase()
val name: SubMessage
get() = config.name
val color: Char
get() = team.color
get() = config.color
var isReady: Boolean = false
set(value) {
@@ -64,7 +64,7 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va
leader?.inventory?.setItem(4, readyItem())
leader?.let { it.playSound(it.location, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 1f) }
message.broadcastActionbar(if (value) "IS_READY" else "IS_NOT_READY", SubMessage(name))
message.broadcastActionbar(if (value) "IS_READY" else "IS_NOT_READY", name)
if (value && opposite.isReady) {
TNTLeagueGame.checkStart()
@@ -82,19 +82,27 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va
var coins: Int = 0
val opposite: TNTLeagueTeam
get() = when (team) {
Team.BLUE -> TNTLeagueGame.redTeam
Team.RED -> TNTLeagueGame.blueTeam
get() = when (this) {
TNTLeagueGame.redTeam -> TNTLeagueGame.blueTeam
TNTLeagueGame.blueTeam -> TNTLeagueGame.redTeam
else -> error("Invalid Team")
}
val ergebnisInt: Int
get() = when (this) {
TNTLeagueGame.redTeam -> 2
TNTLeagueGame.blueTeam -> 3
else -> error("Invalid Team")
}
fun join(player: Player): Boolean {
members.add(player)
with(player) {
teleport(config.spawnLocation)
teleport(config.worldConfig.spawnLocation)
gameMode = GameMode.ADVENTURE
inventory.clear()
message.broadcast("JOIN_TEAM", name.colorByTeam(this@TNTLeagueTeam), SubMessage(this@TNTLeagueTeam.name))
message.broadcast("JOIN_TEAM", name.colorByTeam(this@TNTLeagueTeam), this@TNTLeagueTeam.name)
}
if (leader == null) {
@@ -154,13 +162,8 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va
teleport(TNTLeagueWorldConfig.lobby)
gameMode = GameMode.SPECTATOR
inventory.clear()
message.broadcast("QUIT_TEAM", name.colorByTeam(this@TNTLeagueTeam), SubMessage(this@TNTLeagueTeam.name))
message.broadcast("QUIT_TEAM", name.colorByTeam(this@TNTLeagueTeam), this@TNTLeagueTeam.name)
}
updateFightinfo()
}
enum class Team(val color: Char) {
BLUE('3'),
RED('c');
}
}
@@ -50,10 +50,10 @@ data class TNTLeagueScoreboard(val p: Player): ScoreboardCallback {
lines.add("§3")
with(TNTLeagueGame.redTeam) {
lines.add(message.parse("SCOREBOARD_TEAM", p, SubMessage(name), targetedBlocks - damagedBlocks))
lines.add(message.parse("SCOREBOARD_TEAM", p, name, targetedBlocks - damagedBlocks))
}
with(TNTLeagueGame.blueTeam) {
lines.add(message.parse("SCOREBOARD_TEAM", p, SubMessage(name), targetedBlocks - damagedBlocks))
lines.add(message.parse("SCOREBOARD_TEAM", p, name, targetedBlocks - damagedBlocks))
}
lines.add("§4")