finish item generating part

update TabooLib
This commit is contained in:
TONY_All 2024-08-04 16:11:12 +08:00
parent 439cbccfe2
commit be0bc6ffba
Signed by: tony_all
GPG Key ID: 08A2261D5D6F746A
16 changed files with 146 additions and 41 deletions

View File

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

View File

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

View File

@ -78,6 +78,12 @@ object DebugCommand {
} }
} }
literal("respawn") {
execute<Player> { sender, _, _ ->
villager.spawnForPlayer(sender)
}
}
literal("rename") { literal("rename") {
dynamic { dynamic {
execute<Player> { _, _, arg -> execute<Player> { _, _, arg ->

View File

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

View File

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

View File

@ -5,6 +5,7 @@ import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.BlockGenManager import cc.maxmc.blastingcrisis.misc.BlockGenManager
import cc.maxmc.blastingcrisis.misc.UniArea import cc.maxmc.blastingcrisis.misc.UniArea
import cc.maxmc.blastingcrisis.misc.debug import cc.maxmc.blastingcrisis.misc.debug
import kotlinx.coroutines.Job
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.entity.Player import org.bukkit.entity.Player
import taboolib.common.platform.function.submit import taboolib.common.platform.function.submit
@ -21,6 +22,8 @@ class Game(
val placeBreakRule = GamePlaceBreakRule(this) val placeBreakRule = GamePlaceBreakRule(this)
val generator = BlockGenManager.getGenerator(map.blockGen)!! val generator = BlockGenManager.getGenerator(map.blockGen)!!
var state: GameState = GameState.WAITING var state: GameState = GameState.WAITING
private lateinit var oreGenJob: Job
private lateinit var itemGenJob: List<Job>
private fun autoJoinTeam() { private fun autoJoinTeam() {
players.filter { it.team == null }.shuffled().forEach { players.filter { it.team == null }.shuffled().forEach {
@ -50,10 +53,15 @@ class Game(
checkEnd() checkEnd()
} }
fun respawnPlayer(player: Player) {
teams.forEach { it.villager.respawn(player) }
}
fun start() { fun start() {
debug("game ${map.name} started.") debug("game ${map.name} started.")
placeBreakRule.loadDefaultRule() placeBreakRule.loadDefaultRule()
startOreGen() // startOreGen()
// startItemGen()
state = GameState.START state = GameState.START
timer.startTimer() timer.startTimer()
timer.submitEvent("wall_fall", Duration.ofMinutes(1)) { timer.submitEvent("wall_fall", Duration.ofMinutes(1)) {
@ -92,7 +100,14 @@ class Game(
list += team.sides list += team.sides
list list
} }
generator.enable(UniArea(mines)) oreGenJob = generator.enable(UniArea(mines))
}
private fun startItemGen() {
val generator = GameItemGenerator(Material.LOG)
itemGenJob = map.itemGen.map {
generator.generate(it)
}
} }
fun checkEnd() { fun checkEnd() {

View File

@ -0,0 +1,31 @@
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

@ -53,5 +53,4 @@ class GameOreGenerator(config: Configuration) {
} }
} }
} }

View File

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

View File

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

View File

@ -5,7 +5,7 @@ import cc.maxmc.blastingcrisis.game.team
import cc.maxmc.blastingcrisis.misc.Area import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.GameManager import cc.maxmc.blastingcrisis.misc.GameManager
import cc.maxmc.blastingcrisis.misc.debug import cc.maxmc.blastingcrisis.misc.debug
import cc.maxmc.blastingcrisis.misc.toPlayerLocation import cc.maxmc.blastingcrisis.misc.toEntityLocation
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.entity.EntityType import org.bukkit.entity.EntityType
@ -90,10 +90,11 @@ object GameListener {
@SubscribeEvent @SubscribeEvent
fun onRespawn(respawnEvent: PlayerRespawnEvent) { fun onRespawn(respawnEvent: PlayerRespawnEvent) {
val team = respawnEvent.player.team ?: return // ignore none game player val team = respawnEvent.player.team ?: return // ignore none game player
respawnEvent.respawnLocation = team.teamInfo.spawn.toPlayerLocation() GameManager.currentGame.respawnPlayer(respawnEvent.player)
respawnEvent.respawnLocation = team.teamInfo.spawn.toEntityLocation()
} }
@SubscribeEvent // @SubscribeEvent
fun protectDamageBeforeGame(damageEvent: EntityDamageEvent) { fun protectDamageBeforeGame(damageEvent: EntityDamageEvent) {
if (damageEvent.entity !is Player) return // ignore none player entity if (damageEvent.entity !is Player) return // ignore none player entity
if (GameManager.currentGame.state.isStarted()) return if (GameManager.currentGame.state.isStarted()) return

View File

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

View File

@ -28,7 +28,7 @@ fun <K, V : Number> List<Pair<K, V>>.weightedRandom(): WeightRandom<K, V> {
return WeightRandom(this) return WeightRandom(this)
} }
fun Location.toPlayerLocation(): Location = clone().apply { fun Location.toEntityLocation(): Location = clone().apply {
x = blockX + 0.5 x = blockX + 0.5
y = blockY.toDouble() y = blockY.toDouble()
z = blockZ + 0.5 z = blockZ + 0.5

View File

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

View File

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

View File

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