diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/BlastingCrisis.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/BlastingCrisis.kt index 85d9a40..4a65247 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/BlastingCrisis.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/BlastingCrisis.kt @@ -1,9 +1,17 @@ package cc.maxmc.blastingcrisis import cc.maxmc.blastingcrisis.command.DebugCommand +import cc.maxmc.blastingcrisis.game.Game +import cc.maxmc.blastingcrisis.map.GameMap +import cc.maxmc.blastingcrisis.map.MapTeam +import cc.maxmc.blastingcrisis.misc.Area +import cc.maxmc.blastingcrisis.misc.GameManager import cc.maxmc.blastingcrisis.misc.info import cc.maxmc.blastingcrisis.misc.pluginScope import kotlinx.coroutines.cancel +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location import taboolib.common.env.RuntimeDependency import taboolib.common.platform.Plugin @@ -15,9 +23,55 @@ object BlastingCrisis : Plugin() { info("§a| §7Loading BlastingCrisis") DebugCommand.debug("debugcmd") info("§a| §7Loading BlastingCrisis") + createDefaultGame() } override fun onDisable() { pluginScope.cancel() } + + private fun createDefaultGame() { + fun location(x: Int, y: Int, z: Int) = + Location(Bukkit.getWorlds().first(), x.toDouble(), y.toDouble(), z.toDouble()) + + val teamRed = MapTeam( + "红队", + ChatColor.RED, + location(0, 72, -44), + location(0, 72, -44), + location(-8, 73, -47), + Area(location(14, 72, -48), location(-13, 78, -34)), + Area(location(-13, 78, -33), location(13, 72, -33)), + Area(location(-13, 78, -32), location(13, 71, -1)), + Area(location(7, 72, -45), location(9, 74, -48)), + listOf( + Area(location(15, 72, -1), location(19, 78, -48)), Area(location(19, 78, -48), location(-15, 72, -1)) + ), + ) + val teamGreen = MapTeam( + "绿队", + ChatColor.GREEN, + location(0, 72, 44), + location(0, 72, 44), + location(8, 73, 47), + Area(location(-14, 72, 48), location(13, 78, 34)), + Area(location(13, 78, 33), location(-13, 72, 33)), + Area(location(13, 78, 32), location(-13, 71, 1)), + Area(location(-7, 72, 45), location(-9, 74, 48)), + listOf( + Area(location(-15, 72, 1), location(-19, 78, 48)), Area(location(-19, 78, 48), location(15, 72, 1)) + ), + ) + val map = GameMap( + "test", + Area(location(20, 70, -49), location(-20, 79, 49)), + Area(location(-13, 78, 0), location(13, 72, 0)), + listOf( + teamRed, teamGreen + ), + 1 + ) + DebugCommand.game = Game(map) + GameManager.currentGame = DebugCommand.game + } } \ No newline at end of file diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/command/DebugCommand.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/command/DebugCommand.kt index 6c2803b..8b05565 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/command/DebugCommand.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/command/DebugCommand.kt @@ -3,15 +3,10 @@ package cc.maxmc.blastingcrisis.command import cc.maxmc.blastingcrisis.game.Game import cc.maxmc.blastingcrisis.game.GameOreGenerator import cc.maxmc.blastingcrisis.game.GameState -import cc.maxmc.blastingcrisis.map.GameMap -import cc.maxmc.blastingcrisis.map.MapTeam import cc.maxmc.blastingcrisis.misc.Area -import cc.maxmc.blastingcrisis.misc.GameManager import cc.maxmc.blastingcrisis.packet.BEntityVillager import kotlinx.coroutines.cancel import org.bukkit.Bukkit -import org.bukkit.ChatColor -import org.bukkit.Location import org.bukkit.entity.Player import taboolib.common.platform.ProxyPlayer import taboolib.common.platform.command.command @@ -27,52 +22,6 @@ object DebugCommand { lateinit var villager: BEntityVillager fun debug(cmd: String) = command(cmd) { literal("game") { - execute { sender, _, _ -> - fun location(x: Int, y: Int, z: Int) = Location(sender.world, x.toDouble(), y.toDouble(), z.toDouble()) - Bukkit.broadcastMessage(sender.name) - val teamRed = MapTeam( - "红队", - ChatColor.RED, - location(0, 72, -44), - location(0, 72, -44), - location(-8, 73, -47), - Area(location(14, 72, -48), location(-13, 78, -34)), - Area(location(-13, 78, -33), location(13, 72, -33)), - Area(location(-13, 78, -32), location(13, 71, -1)), - Area(location(7, 72, -45), location(9, 74, -48)), - listOf( - Area(location(15, 72, -1), location(19, 78, -48)), - Area(location(19, 78, -48), location(-15, 72, -1)) - ), - ) - val teamGreen = MapTeam( - "绿队", - ChatColor.GREEN, - location(0, 72, 44), - location(0, 72, 44), - location(8, 73, 47), - Area(location(-14, 72, 48), location(13, 78, 34)), - Area(location(13, 78, 33), location(-13, 72, 33)), - Area(location(13, 78, 32), location(-13, 71, 1)), - Area(location(-7, 72, 45), location(-9, 74, 48)), - listOf( - Area(location(-15, 72, 1), location(-19, 78, 48)), - Area(location(-19, 78, 48), location(15, 72, 1)) - ), - ) - val map = GameMap( - "test", - Area(location(20, 70, -49), location(-20, 79, 49)), - Area(location(-13, 78, 0), location(13, 72, 0)), - listOf( - teamRed, teamGreen - ), - 1 - ) - game = Game(map) - GameManager.currentGame = game - } - literal("join") { execute { sender, _, _ -> game.join(sender) diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/game/Game.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/game/Game.kt index 9517fb5..3976e76 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/game/Game.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/game/Game.kt @@ -2,7 +2,6 @@ package cc.maxmc.blastingcrisis.game import cc.maxmc.blastingcrisis.map.GameMap import cc.maxmc.blastingcrisis.misc.debug -import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.entity.Player import taboolib.common.platform.function.submit @@ -52,7 +51,7 @@ class Game( timer.startTimer() timer.submitEvent("wall_fall", Duration.ofMinutes(1)) { broadcast { it.sendLang("game_wall_fall") } - submit(now = true) { + submit { map.wall.forBlocksInArea().forEach { it.block.type = Material.AIR } diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GamePlayer.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GamePlayer.kt index bc8d9fd..5993c64 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GamePlayer.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GamePlayer.kt @@ -5,5 +5,5 @@ import org.bukkit.entity.Player val Player.team: GameTeam? get() = GameManager.currentGame.teams.findLast { - it.players.contains(this) - } \ No newline at end of file + it.players.contains(this) + } \ No newline at end of file diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameScoreboard.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameScoreboard.kt index 53a671c..a1da8eb 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameScoreboard.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameScoreboard.kt @@ -1,7 +1,6 @@ package cc.maxmc.blastingcrisis.game import cc.maxmc.blastingcrisis.game.GameState.* -import cc.maxmc.blastingcrisis.misc.debug import org.bukkit.entity.Player import taboolib.module.nms.sendScoreboard import taboolib.platform.util.asLangText @@ -14,7 +13,6 @@ class GameScoreboard(val game: Game) { } fun sendScoreboardPlayer(player: Player) { - debug("sending Scoreboard to ${player.name}") val scoreboardText = when (game.state) { WAITING -> { player.asLangText("scoreboard_waiting", game.players.size, game.map.maxPlayer) diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTeam.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTeam.kt index 36c1944..0821223 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTeam.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTeam.kt @@ -3,6 +3,7 @@ package cc.maxmc.blastingcrisis.game import cc.maxmc.blastingcrisis.listener.GameListener import cc.maxmc.blastingcrisis.map.MapTeam import cc.maxmc.blastingcrisis.misc.debug +import cc.maxmc.blastingcrisis.misc.toPlayerLocation import org.bukkit.entity.Player import taboolib.platform.util.sendLang @@ -14,7 +15,7 @@ class GameTeam(val game: Game, val teamInfo: MapTeam) { private set fun start() { - players.forEach { it.teleport(teamInfo.spawn) } + players.forEach { it.teleport(teamInfo.spawn.toPlayerLocation()) } villager.spawn() GameListener.interactSubscribed[teamInfo.upgrade] = { debug("interact team ${teamInfo.name} upgrade.") diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTimer.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTimer.kt index 0532123..68cfc87 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTimer.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTimer.kt @@ -1,7 +1,6 @@ package cc.maxmc.blastingcrisis.game import cc.maxmc.blastingcrisis.configuration.GlobalSettings -import cc.maxmc.blastingcrisis.misc.info import cc.maxmc.blastingcrisis.misc.pluginScope import kotlinx.coroutines.Job import kotlinx.coroutines.delay diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/game/TeamVillager.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/game/TeamVillager.kt index 7b02c4c..2ea44ef 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/game/TeamVillager.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/game/TeamVillager.kt @@ -1,13 +1,14 @@ package cc.maxmc.blastingcrisis.game import cc.maxmc.blastingcrisis.configuration.GlobalSettings +import cc.maxmc.blastingcrisis.misc.toPlayerLocation import cc.maxmc.blastingcrisis.packet.BEntityVillager import org.bukkit.Bukkit import taboolib.platform.BukkitPlugin import taboolib.platform.util.asLangText class TeamVillager(private val team: GameTeam) { - private val packetVillager = BEntityVillager.create(team.teamInfo.villager) + private val packetVillager = BEntityVillager.create(team.teamInfo.villager.toPlayerLocation()) var health: Int = GlobalSettings.GameSettings.villagerMaxHealth private set diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/listener/GameListener.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/listener/GameListener.kt index b3c342f..93df12b 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/listener/GameListener.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/listener/GameListener.kt @@ -3,8 +3,9 @@ package cc.maxmc.blastingcrisis.listener import cc.maxmc.blastingcrisis.game.team import cc.maxmc.blastingcrisis.misc.GameManager import cc.maxmc.blastingcrisis.misc.debug +import cc.maxmc.blastingcrisis.misc.toPlayerLocation import org.bukkit.Location -import org.bukkit.event.block.BlockExplodeEvent +import org.bukkit.event.entity.EntityExplodeEvent import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.event.player.PlayerMoveEvent import taboolib.common.platform.event.SubscribeEvent @@ -19,7 +20,7 @@ object GameListener { val team = player.team ?: return if (!team.teamInfo.teleport.isInArea(event.to)) return debug("teleporting ${event.player} to battle field") - player.teleport(team.teamInfo.mine.randomLocation()) + player.teleport(team.teamInfo.mine.randomLocation().toPlayerLocation()) } @SubscribeEvent @@ -29,11 +30,12 @@ object GameListener { } @SubscribeEvent - fun onTNT(tntExplode: BlockExplodeEvent) { - debug("tnt exploded at ${tntExplode.block.location}") + fun onTNT(tntExplode: EntityExplodeEvent) { + debug("${tntExplode.entityType} exploded at ${tntExplode.location}") tntExplode.blockList().clear() + if (!GameManager.currentGame.state.isStarted()) return GameManager.currentGame.teams.findLast { - it.teamSurvive && it.teamInfo.home.isInArea(tntExplode.block.location) + it.teamSurvive && it.teamInfo.home.isInArea(tntExplode.location) }?.apply { villager.damage() debug("team ${teamInfo.name}'s villager damaged") diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/map/MapInitializer.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/map/MapInitializer.kt index 77066f1..417accb 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/map/MapInitializer.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/map/MapInitializer.kt @@ -2,10 +2,7 @@ package cc.maxmc.blastingcrisis.map import cc.maxmc.blastingcrisis.misc.Area -object MapInitializer { - - -} +object MapInitializer class MapInfo( var name: String, @@ -13,6 +10,4 @@ class MapInfo( val teams: List, val maxPlayersPerTeam: Int, -) { - -} \ No newline at end of file + ) \ No newline at end of file diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Area.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Area.kt index 3f7dab9..2048436 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Area.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Area.kt @@ -2,6 +2,7 @@ package cc.maxmc.blastingcrisis.misc import org.bukkit.Location import org.bukkit.Material +import org.bukkit.block.Block import org.bukkit.configuration.serialization.ConfigurationSerializable import org.bukkit.configuration.serialization.SerializableAs import org.bukkit.util.Vector @@ -30,10 +31,19 @@ class Area(loc1: Location, loc2: Location) : ConfigurationSerializable { * @return true if the location is in this area */ fun isInArea(location: Location): Boolean { - if (location.world != locTop.world) return debug("world").let { false } - if (location.x !in locTop.x..locMin.x) return debug("x").let { false } - if (location.y !in locTop.y..locMin.y) return debug("y").let { false } - if (location.z !in locTop.z..locMin.z) return debug("z").let { false } + if (location.world != locTop.world) return false + if (location.x !in (locMin.x - 1)..(locTop.x + 1)) return false + if (location.y !in locMin.y..locTop.y + 1) return false + if (location.z !in (locMin.z - 1)..(locTop.z + 1)) return false + return true + } + + fun isBlockInArea(block: Block): Boolean { + val location = block.location + if (location.world != locTop.world) return false + if (location.x !in locMin.x..locTop.x) return false + if (location.y !in locMin.y..locTop.y) return false + if (location.z !in locMin.z..locTop.z) return false return true } @@ -44,9 +54,9 @@ class Area(loc1: Location, loc2: Location) : ConfigurationSerializable { */ fun forBlocksInArea(): List { val blocks = arrayListOf() - for (x in locTop.blockX..locMin.blockX) { - for (y in locTop.blockY..locMin.blockY) { - for (z in locTop.blockZ..locMin.blockZ) { + for (x in locMin.blockX..locTop.blockX) { + for (y in locMin.blockY..locTop.blockY) { + for (z in locMin.blockZ..locTop.blockZ) { blocks.add(Location(locTop.world, x.toDouble(), y.toDouble(), z.toDouble())) } } diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/misc/GameManager.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/misc/GameManager.kt index b427686..f9515c7 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/misc/GameManager.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/misc/GameManager.kt @@ -3,5 +3,5 @@ package cc.maxmc.blastingcrisis.misc import cc.maxmc.blastingcrisis.game.Game object GameManager { - lateinit var currentGame : Game + lateinit var currentGame: Game } \ No newline at end of file diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Math.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Math.kt index 64511ca..608d93a 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Math.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/misc/Math.kt @@ -1,6 +1,7 @@ package cc.maxmc.blastingcrisis.misc import com.google.common.base.Preconditions +import org.bukkit.Location import java.util.* @@ -21,4 +22,10 @@ class WeightRandom(list: List>) { val tailMap: SortedMap = weightMap.tailMap(randomWeight, false) return weightMap[tailMap.firstKey()]!! } +} + +fun Location.toPlayerLocation(): Location = clone().apply { + x = blockX + 0.5 + y = blockY.toDouble() + z = blockZ + 0.5 } \ No newline at end of file diff --git a/src/main/kotlin/cc/maxmc/blastingcrisis/packet/ExternalDataWatcher.kt b/src/main/kotlin/cc/maxmc/blastingcrisis/packet/ExternalDataWatcher.kt index 505df8b..771368a 100644 --- a/src/main/kotlin/cc/maxmc/blastingcrisis/packet/ExternalDataWatcher.kt +++ b/src/main/kotlin/cc/maxmc/blastingcrisis/packet/ExternalDataWatcher.kt @@ -2,6 +2,6 @@ package cc.maxmc.blastingcrisis.packet import net.minecraft.server.v1_8_R3.DataWatcher import taboolib.library.reflex.Reflex.Companion.invokeMethod -import java.lang.IllegalStateException -fun DataWatcher.getWatchableObject(id: Int): DataWatcher.WatchableObject = this.invokeMethod("j", id) ?: throw IllegalStateException("Object not exists.") \ No newline at end of file +fun DataWatcher.getWatchableObject(id: Int): DataWatcher.WatchableObject = + this.invokeMethod("j", id) ?: throw IllegalStateException("Object not exists.") \ No newline at end of file