Add teamsOnSameLine for Arena Monochrome

This commit is contained in:
2024-12-28 17:07:00 +01:00
parent e9ac198fcb
commit 658dcd024d
2 changed files with 14 additions and 9 deletions
@@ -29,6 +29,7 @@ import org.bukkit.configuration.ConfigurationSection
import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.entity.WanderingTrader
import java.io.File
import kotlin.math.abs
import kotlin.properties.Delegates
val world by lazy { plugin.server.worlds.first()!! }
@@ -56,6 +57,7 @@ object TNTLeagueWorldConfig {
lateinit var blueTeam: TeamConfig
lateinit var redTeam: TeamConfig
lateinit var lobby: Location
var teamsOnSameLine by Delegates.notNull<Boolean>()
lateinit var targetMaterial: Material
var minHeight by Delegates.notNull<Int>()
var target by Delegates.notNull<Int>()
@@ -64,6 +66,7 @@ object TNTLeagueWorldConfig {
try {
blueTeam = TeamConfig.fromConfig(config.getConfigurationSection("blueTeam")!!)
redTeam = TeamConfig.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")!!)!!
minHeight = config.getInt("minHeight", 0)
@@ -38,13 +38,13 @@ import org.bukkit.event.player.PlayerInteractEntityEvent
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerMoveEvent
object IngameListener: Listener {
object IngameListener : Listener {
@EventHandler
fun onEntityInteract(e: PlayerInteractEntityEvent) {
if (e.player.gameMode == GameMode.SPECTATOR) return
if(e.rightClicked.type == EntityType.WANDERING_TRADER) {
if (e.rightClicked.type == EntityType.WANDERING_TRADER) {
e.isCancelled = true
e.player.openInventory(DealerInventory(e.player).getInventory())
}
@@ -66,11 +66,12 @@ object IngameListener: Listener {
@EventHandler
fun onMove(e: PlayerMoveEvent) {
if (TNTLeagueGame.getTeam(e.player) != null) {
if (e.to.blockX >= TNTLeagueWorldConfig.lobby.blockX && e.to.blockX <= TNTLeagueWorldConfig.lobby.blockX + 1 ||
e.to.blockZ >= TNTLeagueWorldConfig.lobby.blockZ && e.to.blockZ <= TNTLeagueWorldConfig.lobby.blockZ + 1) {
e.isCancelled = true
}
if (TNTLeagueGame.getTeam(e.player) == null) return
if (e.to.blockZ >= TNTLeagueWorldConfig.lobby.blockZ && e.to.blockZ <= TNTLeagueWorldConfig.lobby.blockZ + 1) {
e.isCancelled = true
}
if (!TNTLeagueWorldConfig.teamsOnSameLine && e.to.blockX >= TNTLeagueWorldConfig.lobby.blockX && e.to.blockX <= TNTLeagueWorldConfig.lobby.blockX + 1) {
e.isCancelled = true
}
}
@@ -84,7 +85,8 @@ object IngameListener: Listener {
@EventHandler
fun onPickupCoins(e: PlayerAttemptPickupItemEvent) {
if (e.item.itemStack.isSimilar(DealerInventory.coins)) {
TNTLeagueGame.getTeam(e.player)?.coins = e.item.itemStack.amount + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0)
TNTLeagueGame.getTeam(e.player)?.coins =
e.item.itemStack.amount + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0)
e.item.itemStack.amount = 0
e.isCancelled = true
@@ -100,7 +102,7 @@ object IngameListener: Listener {
}
private fun <K, T> Map<K?, T>.filterKeysNotNull(destination: MutableMap<K, T> = mutableMapOf()): Map<K, T> {
this.forEach { (t, u) -> if(t != null) destination[t] = u }
this.forEach { (t, u) -> if (t != null) destination[t] = u }
return destination
}
}