From 3d153d49b52b162fdfacf3d5537d5fe3c433ef8f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 1 Feb 2025 21:50:36 +0100 Subject: [PATCH 1/2] Make TNTLeague Event System Capable --- .../src/de/steamwar/message/Message.java | 7 +- .../src/de/steamwar/message/SubMessage.java | 29 +++++--- .../tntleague/command/InviteCommand.kt | 7 +- .../tntleague/config/TNTLeagueConfig.kt | 33 +++++++++ .../tntleague/config/TNTLeagueWorldConfig.kt | 41 ++---------- .../steamwar/tntleague/config/TeamConfig.kt | 67 +++++++++++++++++++ .../tntleague/events/GlobalListener.kt | 6 +- .../steamwar/tntleague/game/TNTLeagueGame.kt | 30 +++++++-- .../steamwar/tntleague/game/TNTLeagueTeam.kt | 37 +++++----- .../tntleague/util/TNTLeagueScoreboard.kt | 4 +- 10 files changed, 182 insertions(+), 79 deletions(-) create mode 100644 TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java index b9ae84b7..f953ce8d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -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(); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java index e40b74a5..4c302689 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java @@ -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); + } } } diff --git a/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt b/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt index 8ecf50cb..e89e3443 100644 --- a/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt +++ b/TNTLeague/src/de/steamwar/tntleague/command/InviteCommand.kt @@ -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) } diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt index e4677a4e..e5bccb08 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt @@ -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( diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt index df2dd34e..01667abd 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueWorldConfig.kt @@ -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() 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 { diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt new file mode 100644 index 00000000..61cb3431 --- /dev/null +++ b/TNTLeague/src/de/steamwar/tntleague/config/TeamConfig.kt @@ -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 . + */ + +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) + } + } +} diff --git a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt index 77aa9dfb..60f921fc 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt @@ -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) } diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt index e064a350..80c86314 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueGame.kt @@ -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, diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt index 200f457e..773c4a46 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt @@ -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() val invites = mutableListOf() - 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'); - } } \ No newline at end of file diff --git a/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt b/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt index 77ba1d48..204680d0 100644 --- a/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt +++ b/TNTLeague/src/de/steamwar/tntleague/util/TNTLeagueScoreboard.kt @@ -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") From 482282f913cceb3011b6e6fd7b258630880d40ef Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 1 Feb 2025 22:00:36 +0100 Subject: [PATCH 2/2] Make TNTLeague Event System Capable --- .../src/de/steamwar/message/Message.java | 7 ++--- .../src/de/steamwar/message/SubMessage.java | 29 +++++-------------- .../steamwar/tntleague/TNTLeague.properties | 1 + .../tntleague/config/TNTLeagueConfig.kt | 8 ++--- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java index f953ce8d..b9ae84b7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -72,12 +72,9 @@ public class Message { pattern += fromRB(resourceBundle, message); for (int i = 0; i < params.length; i++) { - if (params[i] instanceof SubMessage.Translatable) { - SubMessage.Translatable smsg = (SubMessage.Translatable) params[i]; + if (params[i] instanceof SubMessage) { + SubMessage smsg = (SubMessage) 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(); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java index 4c302689..e40b74a5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/message/SubMessage.java @@ -19,33 +19,20 @@ package de.steamwar.message; -import lombok.AllArgsConstructor; import lombok.Getter; @Getter -@AllArgsConstructor -public abstract class SubMessage { +public class SubMessage { private final String message; + private final Object[] 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, Object... params) { + this.message = message; + this.params = params; } - @Getter - public static class Literal extends SubMessage { - public Literal(String message) { - super(message); - } + public SubMessage(String message) { + this.message = message; + this.params = new Object[0]; } } diff --git a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties index 05d998e2..73e3b416 100644 --- a/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties +++ b/TNTLeague/src/de/steamwar/tntleague/TNTLeague.properties @@ -18,6 +18,7 @@ # PREFIX=§eTNT§7League§8» +PLAIN_STRING={0} JOIN=§e{0} §7joined the game! JOIN_TEAM={0} §7joined the {1} §7team! QUIT={0} §7left the game! diff --git a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt index e5bccb08..7b1e865a 100644 --- a/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt +++ b/TNTLeague/src/de/steamwar/tntleague/config/TNTLeagueConfig.kt @@ -60,11 +60,11 @@ data class TNTLeagueConfig( 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]) + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("PLAIN_STRING", "§${eventTeamBlue.teamColor}${eventTeamBlue.teamName}"), eventTeamBlue.teamColor[0]) + redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage("PLAIN_STRING", "§${eventTeamRed.teamColor}${eventTeamRed.teamName}"), eventTeamRed.teamColor[0]) } else { - blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage.Translatable("BLUE"), '3') - redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage.Translatable("RED"), 'c') + blueTeam = TeamConfig(TNTLeagueWorldConfig.blueTeam, SubMessage("BLUE"), '3') + redTeam = TeamConfig(TNTLeagueWorldConfig.redTeam, SubMessage("RED"), 'c') } }