Compare commits

..

No commits in common. "a063e8c6dd90f535aae378690c93f0d85a2ecdc7" and "1d753801dd32efef89925d1dcbf12aaf7e58fc9d" have entirely different histories.

23 changed files with 87 additions and 1633 deletions

View File

@ -1,15 +1,15 @@
job("Build and run tests") {
// run 'gradlew build'
gradlew("azul/zulu-openjdk:17", "build", "--no-daemon") {
// mountDir = "/root"
// cache {
// storeKey = "dot-gradle"
// localPath = "/root/.gradle"
// }
mountDir = "/root"
cache {
storeKey = "dot-gradle"
localPath = "/root/.gradle"
}
fileArtifacts {
localPath = "build/libs/*"
archive = true
localPath = "build/libs"
archive = false
remotePath = "{{ run:number }}/build"
onStatus = OnStatus.SUCCESS
}

View File

@ -1,9 +1,8 @@
import io.izzel.taboolib.gradle.*
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "2.0.0"
id("io.izzel.taboolib") version "2.0.11"
kotlin("jvm") version "1.7.20"
id("io.izzel.taboolib") version "1.50"
}
group = "cc.maxmc.blastingcrisis"
@ -12,14 +11,12 @@ version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
mavenLocal()
maven("https://repo.vip.maxmc.cc:30443/releases")
}
dependencies {
implementation(kotlin("stdlib"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("ink.ptms.core:v10800:10800")
// taboo("cc.maxmc.agones:AgonesKt:0.1.3")
// implementation("ink.ptms.core:v11200:11200")
}
@ -30,22 +27,16 @@ taboolib {
name("TONY_All")
}
}
env {
// install("common", "common-5")
install(BUKKIT_ALL)
install(NMS, NMS_UTIL)
install(CHAT, LANG, CONFIGURATION)
install("common", "common-5")
install("platform-bukkit")
install("module-nms", "module-nms-util")
install("module-chat", "module-lang", "module-configuration")
classifier = null
options("skip-kotlin-relocate")
version = "6.0.10-12"
}
// classifier = null
// options("skip-kotlin-relocate")
version {
taboolib = "6.1.1"
}
}
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -9,13 +9,11 @@ import cc.maxmc.blastingcrisis.misc.GameManager
import cc.maxmc.blastingcrisis.misc.info
import cc.maxmc.blastingcrisis.misc.pluginScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Location
import taboolib.common.env.RuntimeDependency
import taboolib.common.platform.Plugin
import taboolib.common.platform.function.submit
@RuntimeDependency(
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4",
@ -25,21 +23,9 @@ object BlastingCrisis : Plugin() {
info("§a| §7Loading BlastingCrisis")
DebugCommand.debug("debugcmd")
createDefaultGame()
submit(delay = 1) {
pluginScope.launch {
// AgonesSDK().use { sdk ->
// sdk.ready()
// }
}
}
}
override fun onDisable() {
pluginScope.launch {
// AgonesSDK().use { sdk ->
// sdk.shutdown()
// }
}
pluginScope.cancel()
}
@ -58,7 +44,8 @@ object BlastingCrisis : Plugin() {
Area(location(-13, 78, -32), location(13, 72, -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))
Area(location(15, 72, -1), location(19, 78, -48)),
Area(location(-19, 78, -48), location(-15, 72, -1))
),
)
val teamGreen = MapTeam(
@ -72,7 +59,8 @@ object BlastingCrisis : Plugin() {
Area(location(13, 78, 32), location(-13, 72, 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))
Area(location(-15, 72, 1), location(-19, 78, 48)),
Area(location(19, 78, 48), location(15, 72, 1))
),
)
val map = GameMap(
@ -82,12 +70,7 @@ object BlastingCrisis : Plugin() {
listOf(
teamRed, teamGreen
),
1,
"default",
listOf(
location(-5, 72, -44), location(5, 72, -44), location(0, 72, -48),
location(-5, 72, 44), location(5, 72, 44), location(0, 72, 48)
)
1
)
DebugCommand.game = Game(map)
GameManager.currentGame = DebugCommand.game

View File

@ -4,7 +4,6 @@ import cc.maxmc.blastingcrisis.game.Game
import cc.maxmc.blastingcrisis.game.GameOreGenerator
import cc.maxmc.blastingcrisis.game.GameState
import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.UniArea
import cc.maxmc.blastingcrisis.packet.BEntityVillager
import kotlinx.coroutines.cancel
import org.bukkit.Bukkit
@ -78,12 +77,6 @@ object DebugCommand {
}
}
literal("respawn") {
execute<Player> { sender, _, _ ->
villager.spawnForPlayer(sender)
}
}
literal("rename") {
dynamic {
execute<Player> { _, _, arg ->
@ -123,7 +116,7 @@ object DebugCommand {
println("saved")
val config = Configuration.loadFromFile(File(getDataFolder(), "ore-generators/default.yml"))
val gen = GameOreGenerator(config)
val job = gen.enable(UniArea(listOf(area)))
val job = gen.enable(area)
Bukkit.getScheduler().runTaskLater(BukkitPlugin.getInstance(), {
job.cancel("Stop by hand")
}, 60 * 20)

View File

@ -8,10 +8,7 @@ object GlobalSettings {
lateinit var settings: Configuration
val timeToStart
get() = settings.getInt("time_to_start")
val itemGenDelay
get() = settings.getLong("item_gen_delay")
get() = settings.getInt("time-to-start")
object GameSettings {
val villagerMaxHealth

View File

@ -1,13 +1,10 @@
package cc.maxmc.blastingcrisis.debug
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving
import org.bukkit.Bukkit
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.reflex.Reflex.Companion.getProperty
import taboolib.module.nms.PacketSendEvent
import taboolib.platform.BukkitPlugin
import taboolib.platform.util.broadcast
object DListener {
@SubscribeEvent
@ -15,18 +12,13 @@ object DListener {
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance()) {
if (it.player.name != "TONY_All") return@runTask
// val source = it.packet.source
// if (!it.packet.name.lowercase().contains("entity")) return@runTask
val pname = listOf("PacketPlayOutSpawnEntityLiving", "PacketPlayOutEntityDestroy")
if (pname.contains(it.packet.name)) println(it.packet.name)
if (it.packet.source is PacketPlayOutSpawnEntityLiving) {
it.packet.source.getProperty<Int>("a")!!.broadcast()
it.packet.source.getProperty<Int>("b")!!.broadcast()
}
if (it.packet.source is PacketPlayOutEntityDestroy) {
it.packet.source.getProperty<IntArray>("a")!!.contentToString().broadcast()
if (!it.packet.name.lowercase().contains("entity")) return@runTask
// println(it.packet.name)
if (it.packet.source !is PacketPlayOutSpawnEntityLiving) {
return@runTask
}
// it.packet.source.getProperty<Int>("a")!!.broadcast()
// it.packet.source.getProperty<Int>("b")!!.broadcast()
}
}
}

View File

@ -1,11 +1,7 @@
package cc.maxmc.blastingcrisis.game
import cc.maxmc.blastingcrisis.map.GameMap
import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.BlockGenManager
import cc.maxmc.blastingcrisis.misc.UniArea
import cc.maxmc.blastingcrisis.misc.debug
import kotlinx.coroutines.Job
import org.bukkit.Material
import org.bukkit.entity.Player
import taboolib.common.platform.function.submit
@ -20,10 +16,7 @@ class Game(
val timer: GameTimer = GameTimer(this)
val players = ArrayList<Player>()
val placeBreakRule = GamePlaceBreakRule(this)
val generator = BlockGenManager.getGenerator(map.blockGen)!!
var state: GameState = GameState.WAITING
private lateinit var oreGenJob: Job
private lateinit var itemGenJob: List<Job>
private fun autoJoinTeam() {
players.filter { it.team == null }.shuffled().forEach {
@ -53,21 +46,16 @@ class Game(
checkEnd()
}
fun respawnPlayer(player: Player) {
teams.forEach { it.villager.respawn(player) }
}
fun start() {
debug("game ${map.name} started.")
placeBreakRule.loadDefaultRule()
// startOreGen()
// startItemGen()
state = GameState.START
timer.startTimer()
timer.submitEvent("wall_fall", Duration.ofMinutes(1)) {
broadcast { it.sendLang("game_wall_fall") }
placeBreakRule.addRuleLast("allow_center_wall") { (_, _, loc, _) ->
if (map.wall.contains(loc)) GamePlaceBreakRule.MatchResult.ALLOW else GamePlaceBreakRule.MatchResult.DEFAULT
placeBreakRule.addRule("allow_center_wall") { _, _, loc ->
map.wall.contains(loc)
}
submit {
map.wall.forBlocksInArea().forEach {
@ -94,22 +82,6 @@ class Game(
}
}
private fun startOreGen() {
val mines = map.teams.fold(ArrayList<Area>()) { list, team ->
list += team.mine
list += team.sides
list
}
oreGenJob = generator.enable(UniArea(mines))
}
private fun startItemGen() {
val generator = GameItemGenerator(Material.LOG)
itemGenJob = map.itemGen.map {
generator.generate(it)
}
}
fun checkEnd() {
if (teams.filter { it.teamSurvive }.size > 1) {
return

View File

@ -1,31 +0,0 @@
package cc.maxmc.blastingcrisis.game
import cc.maxmc.blastingcrisis.configuration.GlobalSettings
import cc.maxmc.blastingcrisis.misc.debug
import cc.maxmc.blastingcrisis.misc.pluginScope
import cc.maxmc.blastingcrisis.misc.toEntityLocation
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.util.Vector
import taboolib.platform.BukkitPlugin
class GameItemGenerator(val type: Material) {
fun generate(location: Location): Job = pluginScope.launch {
while (true) {
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance()) {
val item = location.world.dropItem(location.toEntityLocation(), ItemStack(type))
item.teleport(location.toEntityLocation())
item.velocity = Vector(0.0, 0.2, 0.0)
debug("Generate Item at ${location.toVector()}")
}
delay(GlobalSettings.itemGenDelay * 50)
}
}
}

View File

@ -1,6 +1,9 @@
package cc.maxmc.blastingcrisis.game
import cc.maxmc.blastingcrisis.misc.*
import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.WeightRandom
import cc.maxmc.blastingcrisis.misc.debug
import cc.maxmc.blastingcrisis.misc.pluginScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -21,14 +24,13 @@ class GameOreGenerator(config: Configuration) {
}
private val random = WeightRandom(ores.map { it.key to it.value })
fun enable(area: UniArea): Job {
fun enable(area: Area): Job {
return pluginScope.launch {
while (true) {
val targetArea = area.randomizer.random()
val airPercent = targetArea.getAirPercentage()
val airPercent = area.getAirPercentage()
debug("remain air: $airPercent.")
if (airPercent > 0.5) {
generate(targetArea)
generate(area)
}
delay(rate * 50L)
}
@ -52,5 +54,4 @@ class GameOreGenerator(config: Configuration) {
return generate(area, times + 1)
}
}
}

View File

@ -1,41 +1,24 @@
package cc.maxmc.blastingcrisis.game
import cc.maxmc.blastingcrisis.game.GamePlaceBreakRule.ActionType.BREAK
import cc.maxmc.blastingcrisis.game.GamePlaceBreakRule.ActionType.PLACE
import cc.maxmc.blastingcrisis.misc.EnhancedLinkedList
import cc.maxmc.blastingcrisis.misc.debug
import org.bukkit.Location
import org.bukkit.entity.Player
import taboolib.library.xseries.XMaterial
typealias PlaceBreakRule = (GamePlaceBreakRule.GamePlaceBreakEvent) -> GamePlaceBreakRule.MatchResult
@Suppress("unused") // API
class GamePlaceBreakRule(val game: Game) {
enum class ActionType {
PLACE,
BREAK
}
enum class MatchResult {
DEFAULT,
ALLOW,
DENY
}
data class GamePlaceBreakEvent(val player: Player, val actionType: ActionType, val loc: Location, val type: XMaterial)
private val rules = HashMap<String, PlaceBreakRule>()
private val rulesPriority = EnhancedLinkedList<String>()
private val rules = HashMap<String, (Player, ActionType, Location, XMaterial) -> Boolean>()
fun matchRule(player: Player, actionType: ActionType, location: Location, type: XMaterial): Boolean {
// match rules
rules.forEach { (name, func) ->
val result = func(GamePlaceBreakEvent(player, actionType, location, type))
if (result != MatchResult.DEFAULT) {
if (func(player, actionType, location, type)) {
debug("Hit rule $name")
return result == MatchResult.ALLOW
return true
}
}
@ -43,7 +26,10 @@ class GamePlaceBreakRule(val game: Game) {
return false
}
private fun recordRule(name: String, rule: PlaceBreakRule) {
fun addRule(
name: String,
rule: (player: Player, actionType: ActionType, loc: Location, type: XMaterial) -> Boolean
) {
if (rules.containsKey(name)) {
throw IllegalArgumentException("Rule $name already exists.")
}
@ -51,80 +37,42 @@ class GamePlaceBreakRule(val game: Game) {
rules[name] = rule
}
fun addRuleLast(
name: String,
rule: PlaceBreakRule
) {
recordRule(name, rule)
rulesPriority.addLast(name)
}
fun addRuleFirst(
name: String,
rule: PlaceBreakRule
) {
recordRule(name, rule)
rulesPriority.addFirst(name)
}
fun addRuleBefore(
base: String,
name: String,
rule: PlaceBreakRule
) {
recordRule(name, rule)
rulesPriority.addBefore(base, name)
}
fun addRuleAfter(
base: String,
name: String,
rule: PlaceBreakRule
) {
recordRule(name, rule)
rulesPriority.addAfter(base, name)
}
fun loadDefaultRule() {
// allow mine
addRuleLast("allow_mine") { (_, _, loc, _) ->
val result = game.map.teams.flatMap {
addRule("allow_mine") { _, _, loc, _ ->
game.map.teams.flatMap {
it.sides + it.mine
}.map {
it.containsBlock(loc)
}.reduce { a, b -> a || b }
if (result) MatchResult.ALLOW else MatchResult.DEFAULT
}
// allow enemy wall
addRuleLast("allow_wall_conditional") { (player, actionType, loc, _) ->
val team = player.team ?: return@addRuleLast MatchResult.DENY
addRule("allow_wall_conditional") { player, actionType, loc, _ ->
val team = player.team ?: return@addRule false
val isWall = game.teams
.map {
it.teamInfo.wall.containsBlock(loc)
.also { result -> debug("area ${it.teamInfo.wall} contains $loc is $result") }
}
.reduce { a, b -> a || b }
if (!isWall) return@addRuleLast MatchResult.DEFAULT
if (!isWall) return@addRule false
val isHome = team.teamInfo.wall.containsBlock(loc)
if ((actionType == BREAK) xor isHome) MatchResult.ALLOW else MatchResult.DENY
(actionType == BREAK) xor isHome
}
// allow tnt in enemy's home
addRuleFirst("allow_tnt_conditional") { (player, actionType, loc, type) ->
if (type != XMaterial.TNT) return@addRuleFirst MatchResult.DEFAULT
val team = player.team ?: return@addRuleFirst MatchResult.DENY
addRule("allow_tnt_conditional") { player, actionType, loc, type ->
if (actionType == BREAK) return@addRule false
if (type != XMaterial.TNT) return@addRule false
val team = player.team ?: return@addRule false
val isHome = game.teams
.map {
it.teamInfo.home.containsBlock(loc)
.also { result -> debug("area ${it.teamInfo.home} contains $loc is $result") }
}
.reduce { a, b -> a || b }
if (!isHome) return@addRuleFirst MatchResult.DENY
val isSelf = team.teamInfo.home.containsBlock(loc)
if ((actionType == PLACE) xor isSelf) MatchResult.ALLOW else MatchResult.DENY
if (!isHome) return@addRule false
return@addRule !team.teamInfo.home.containsBlock(loc)
}
}
}

View File

@ -3,7 +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.toEntityLocation
import cc.maxmc.blastingcrisis.misc.toPlayerLocation
import org.bukkit.entity.Player
import taboolib.platform.util.sendLang
@ -15,7 +15,7 @@ class GameTeam(val game: Game, val teamInfo: MapTeam) {
private set
fun start() {
players.forEach { it.teleport(teamInfo.spawn.toEntityLocation()) }
players.forEach { it.teleport(teamInfo.spawn.toPlayerLocation()) }
villager.spawn()
GameListener.interactSubscribed[teamInfo.upgrade] = {
debug("interact team ${teamInfo.name} upgrade.")
@ -24,7 +24,7 @@ class GameTeam(val game: Game, val teamInfo: MapTeam) {
val player = it.player ?: throw IllegalStateException("Bukkit API LOL")
debug("teleporting $player to battle field")
val team = player.team ?: throw IllegalStateException("Player ${player.name} should have a team")
player.teleport(team.teamInfo.mine.randomLocationRestrict().toEntityLocation())
player.teleport(team.teamInfo.mine.randomLocation().toPlayerLocation())
})
}

View File

@ -1,15 +1,14 @@
package cc.maxmc.blastingcrisis.game
import cc.maxmc.blastingcrisis.configuration.GlobalSettings
import cc.maxmc.blastingcrisis.misc.toEntityLocation
import cc.maxmc.blastingcrisis.misc.toPlayerLocation
import cc.maxmc.blastingcrisis.packet.BEntityVillager
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import taboolib.platform.BukkitPlugin
import taboolib.platform.util.asLangText
class TeamVillager(private val team: GameTeam) {
private val packetVillager = BEntityVillager.create(team.teamInfo.villager.toEntityLocation())
private val packetVillager = BEntityVillager.create(team.teamInfo.villager.toPlayerLocation())
var health: Int = GlobalSettings.GameSettings.villagerMaxHealth
private set
@ -41,9 +40,5 @@ class TeamVillager(private val team: GameTeam) {
team.game.checkEnd()
}
fun respawn(player: Player) {
packetVillager.respawnForPlayer(player)
}
}

View File

@ -5,20 +5,17 @@ import cc.maxmc.blastingcrisis.game.team
import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.GameManager
import cc.maxmc.blastingcrisis.misc.debug
import cc.maxmc.blastingcrisis.misc.toEntityLocation
import cc.maxmc.blastingcrisis.misc.toPlayerLocation
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.entity.ExplosionPrimeEvent
import org.bukkit.event.entity.EntityExplodeEvent
import org.bukkit.event.entity.FoodLevelChangeEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.player.PlayerRespawnEvent
import taboolib.common.platform.event.EventPriority
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.sendLang
@ -42,32 +39,23 @@ object GameListener {
}
@SubscribeEvent
fun onTNT(tntExplode: ExplosionPrimeEvent) {
debug("${tntExplode.entityType} exploded at ${tntExplode.entity.location}")
tntExplode.radius = 0.0f
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.contains(tntExplode.entity.location)
it.teamSurvive && it.teamInfo.home.contains(tntExplode.location)
}?.apply {
villager.damage()
debug("team ${teamInfo.name}'s villager damaged")
} ?: return run {
debug("§cTNT Exploded at no team, which shouldn't happen")
tntExplode.isCancelled = true
}
} ?: throw IllegalStateException("TNT Exploded at no team, which shouldn't happen")
}
@SubscribeEvent
fun onBreak(breakEvent: BlockBreakEvent) {
val loc = breakEvent.block.location ?: return
val player = breakEvent.player ?: return
if (GameManager.currentGame.placeBreakRule.matchRule(
player,
GamePlaceBreakRule.ActionType.BREAK,
loc,
XMaterial.matchXMaterial(breakEvent.block.type)
)
) return
if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.BREAK, loc, XMaterial.matchXMaterial(breakEvent.block.type))) return
breakEvent.isCancelled = true
player.sendLang("game_cant_break_block")
}
@ -76,13 +64,7 @@ object GameListener {
fun onPlace(placeEvent: BlockPlaceEvent) {
val loc = placeEvent.block.location ?: return
val player = placeEvent.player ?: return
if (GameManager.currentGame.placeBreakRule.matchRule(
player,
GamePlaceBreakRule.ActionType.PLACE,
loc,
XMaterial.matchXMaterial(placeEvent.blockPlaced.type)
)
) return
if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.PLACE, loc, XMaterial.matchXMaterial(placeEvent.blockPlaced.type))) return
placeEvent.isCancelled = true
player.sendLang("game_cant_place_block")
}
@ -90,11 +72,10 @@ object GameListener {
@SubscribeEvent
fun onRespawn(respawnEvent: PlayerRespawnEvent) {
val team = respawnEvent.player.team ?: return // ignore none game player
GameManager.currentGame.respawnPlayer(respawnEvent.player)
respawnEvent.respawnLocation = team.teamInfo.spawn.toEntityLocation()
respawnEvent.respawnLocation = team.teamInfo.spawn.toPlayerLocation()
}
// @SubscribeEvent
@SubscribeEvent
fun protectDamageBeforeGame(damageEvent: EntityDamageEvent) {
if (damageEvent.entity !is Player) return // ignore none player entity
if (GameManager.currentGame.state.isStarted()) return
@ -109,12 +90,4 @@ object GameListener {
saturation = 20f
}
}
@SubscribeEvent(EventPriority.HIGH, true)
fun tntIgnite(tntPlace: BlockPlaceEvent) {
if (tntPlace.blockPlaced.type != Material.TNT) return
val loc = tntPlace.blockPlaced.location
tntPlace.block.type = Material.AIR
loc.world.spawnEntity(loc.clone().apply { y += 0.5 }, EntityType.PRIMED_TNT)
}
}

View File

@ -1,16 +1,13 @@
package cc.maxmc.blastingcrisis.map
import cc.maxmc.blastingcrisis.misc.Area
import org.bukkit.Location
class GameMap(
val name: String,
val area: Area,
val wall: Area,
val teams: List<MapTeam>,
val maxPlayersPerTeam: Int,
val blockGen: String,
val itemGen: List<Location>
val maxPlayersPerTeam: Int
) {
val maxPlayer: Int
get() = maxPlayersPerTeam * teams.size

View File

@ -80,7 +80,7 @@ class Area(loc1: Location, loc2: Location) : ConfigurationSerializable {
*
* @return a random Location that player can stand
*/
tailrec fun randomLocationRestrict(): Location {
tailrec fun randomLocation(): Location {
val x = random(locMin.blockX, locTop.blockX)
val z = random(locMin.blockZ, locTop.blockZ)
for (y in locMin.blockY..locTop.blockY) {
@ -88,21 +88,9 @@ class Area(loc1: Location, loc2: Location) : ConfigurationSerializable {
val add = loc.clone().add(0.0, 1.0, 0.0)
if (loc.block.type == Material.AIR && add.block.type == Material.AIR) return loc
}
return randomLocationRestrict()
return randomLocation()
}
tailrec fun randomLocationAny(): Location {
val x = random(locMin.blockX, locTop.blockX)
val y = random(locMin.blockY, locTop.blockY)
val z = random(locMin.blockZ, locTop.blockZ)
val loc = Vector(x, y, z).toLocation(locMin.world)
if (loc.block.type == Material.AIR) return loc
return randomLocationAny()
}
fun volume(): Int =
(locTop.blockX - locMin.blockX) * (locTop.blockY - locMin.blockY) * (locTop.blockZ - locMin.blockZ)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

View File

@ -1,25 +0,0 @@
package cc.maxmc.blastingcrisis.misc
import cc.maxmc.blastingcrisis.game.GameOreGenerator
import taboolib.common.platform.function.getDataFolder
import taboolib.module.configuration.Configuration
object BlockGenManager {
private val generators = HashMap<String, GameOreGenerator>()
init {
load()
}
private fun load() {
getDataFolder().resolve("ore-generators").listFiles()!!.forEach {
try {
generators[it.nameWithoutExtension] = GameOreGenerator(Configuration.loadFromFile(it))
} catch (e: Exception) {
info("§c| §7加载矿石生成器 §c${it.nameWithoutExtension} §7时出现错误已跳过.")
}
}
}
fun getGenerator(name: String): GameOreGenerator? = generators[name]
}

View File

@ -11,7 +11,7 @@ class WeightRandom<K, V : Number>(list: List<Pair<K, V>>) {
init {
Preconditions.checkNotNull(list, "list can NOT be null!")
for (pair in list) {
// Preconditions.checkArgument(pair.second.toDouble() > 0, "非法权重值pair=$pair")
Preconditions.checkArgument(pair.second.toDouble() > 0, "非法权重值pair=$pair")
val lastWeight: Double = if (weightMap.size == 0) 0.0 else weightMap.lastKey().toDouble() //统一转为double
weightMap[pair.second.toDouble() + lastWeight] = pair.first //权重累加
}
@ -24,11 +24,7 @@ class WeightRandom<K, V : Number>(list: List<Pair<K, V>>) {
}
}
fun <K, V : Number> List<Pair<K, V>>.weightedRandom(): WeightRandom<K, V> {
return WeightRandom(this)
}
fun Location.toEntityLocation(): Location = clone().apply {
fun Location.toPlayerLocation(): Location = clone().apply {
x = blockX + 0.5
y = blockY.toDouble()
z = blockZ + 0.5

View File

@ -1,6 +0,0 @@
package cc.maxmc.blastingcrisis.misc
class UniArea(subArea: List<Area>) {
val randomizer = subArea.map { it to it.volume() }.weightedRandom()
}

View File

@ -11,7 +11,6 @@ import taboolib.library.reflex.Reflex.Companion.getProperty
import taboolib.library.reflex.Reflex.Companion.setProperty
import taboolib.library.reflex.Reflex.Companion.unsafeInstance
import taboolib.module.nms.sendPacket
import taboolib.module.nms.sendPacketBlocking
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.locks.ReentrantReadWriteLock
@ -59,7 +58,7 @@ abstract class BEntity(var loc: Location, val entityType: Int) {
}
packet.setProperty("l", dataWatcher)
player.sendPacketBlocking(packet)
viewers.forEach { it.sendPacket(packet) }
}
open fun addViewer(viewer: Player) {
@ -68,18 +67,10 @@ abstract class BEntity(var loc: Location, val entityType: Int) {
}
open fun removeViewer(viewer: Player) {
viewer.sendPacketBlocking(PacketPlayOutEntityDestroy(entityID))
viewer.sendPacket(PacketPlayOutEntityDestroy(entityID))
viewers.remove(viewer)
}
fun respawnForPlayer(player: Player) {
println(viewers)
if (!viewers.contains(player)) return
println("Respawning?")
removeViewer(player)
addViewer(player)
}
fun destroy() {
ArrayList(viewers).forEach { removeViewer(it) }
}

View File

@ -30,8 +30,6 @@ class BEntityVillager private constructor(loc: Location) : BEntity(loc, 120) {
nameTag.removeViewer(viewer)
}
override fun DataWatcher.initEntity() {
a(6, 1.0f) // Health
a(7, 0) // Potion Effect Color

View File

@ -1,10 +1,7 @@
# Time before game start
# Unit: second
time_to_start: 15
# Unit: tick
item_gen_delay: 20
time-to-start: 15
game:
villager_max_health: 150