Skip to content

Commit

Permalink
[6.0.10] supported 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Mar 15, 2023
1 parent bbfdb63 commit fb0b812
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class ScriptContext(service: ScriptService, script: Script) : AbstractQuest

/** 脚本执行者 */
var sender: ProxyCommandSender?
get() = get<ProxyCommandSender?>("@Sender")?.let { adaptCommandSender(it) }
get() = get<Any?>("@Sender")?.let { adaptCommandSender(it) }
set(value) {
this["@Sender"] = value?.origin
}
Expand Down
4 changes: 2 additions & 2 deletions module/module-nms-util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ dependencies {
compileOnly("com.google.code.gson:gson:2.8.7")
compileOnly("net.md-5:bungeecord-chat:1.17")
compileOnly("ink.ptms:nms-all:1.0.0")
compileOnly("ink.ptms.core:v11903:11903-minimize:mapped")
compileOnly("ink.ptms.core:v11903:11903-minimize:universal")
compileOnly("ink.ptms.core:v11904:11904-minimize:mapped")
compileOnly("ink.ptms.core:v11904:11904-minimize:universal")
compileOnly("com.mojang:brigadier:1.0.18")
compileOnly(project(":common"))
compileOnly(project(":module:module-nms"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package taboolib.module.nms

import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.jetbrains.annotations.Contract
import taboolib.common.util.unsafeLazy
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

internal val nmsGeneric by unsafeLazy { nmsProxy<NMSGeneric>() }

Expand Down
2 changes: 1 addition & 1 deletion module/module-nms/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
compileOnly("org.ow2.asm:asm-commons:9.1")
compileOnly("io.netty:netty-all:5.0.0.Alpha2")
compileOnly("ink.ptms:nms-all:1.0.0")
compileOnly("ink.ptms.core:v11903:11903-minimize:mapped")
compileOnly("ink.ptms.core:v11904:11904-minimize:mapped")
compileOnly("ink.ptms.core:v11800:11800-minimize:mapped")
compileOnly("ink.ptms.core:v11200:11200-minimize")
compileOnly(project(":common"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ abstract class ConnectionGetter {

abstract fun release(address: InetSocketAddress)

abstract fun newBundlePacket(iterator: List<Any>): Any

companion object {

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package taboolib.module.nms

import io.netty.channel.Channel
import net.minecraft.network.NetworkManager
import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.game.ClientboundBundlePacket
import net.minecraft.network.protocol.game.PacketListenerPlayOut
import net.minecraft.server.network.ServerConnection
import org.bukkit.Bukkit
import org.tabooproject.reflex.Reflex.Companion.getProperty
Expand Down Expand Up @@ -94,6 +97,11 @@ class ConnectionGetterImpl : ConnectionGetter() {
addressUsed.remove(address)
}

@Suppress("UNCHECKED_CAST")
override fun newBundlePacket(iterator: List<Any>): Any {
return ClientboundBundlePacket(iterator.asIterable() as Iterable<Packet<PacketListenerPlayOut>>)
}

private fun getAddress(connection: Any): InetSocketAddress {
// 这种方式无法在 BungeeCord 中获取到正确的地址:
// return (getChannel(connection).remoteAddress() as? InetSocketAddress)?.address
Expand All @@ -118,7 +126,7 @@ typealias CraftServer8 = org.bukkit.craftbukkit.v1_8_R3.CraftServer

typealias CraftServer16 = org.bukkit.craftbukkit.v1_16_R2.CraftServer

typealias CraftServer19 = org.bukkit.craftbukkit.v1_19_R2.CraftServer
typealias CraftServer19 = org.bukkit.craftbukkit.v1_19_R3.CraftServer

typealias NMS16MinecraftServer = net.minecraft.server.v1_16_R2.MinecraftServer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ import taboolib.common.env.RuntimeResources
hash = "65539f95551a967e096f916896c031c5969d2e34",
zip = true,
tag = "1.19.3:fields"
),
RuntimeResource(
value = "https://skymc.oss-cn-shanghai.aliyuncs.com/taboolib/resources/bukkit-1.19.4-cl.csrg",
hash = "523cd77ba9aa25f0f59cebee1eb6b3e9a4e9c602",
zip = true,
tag = "1.19.4:combined"
),
RuntimeResource(
value = "https://skymc.oss-cn-shanghai.aliyuncs.com/taboolib/resources/bukkit-0207e96c-members.csrg",
hash = "a357798e3ce7e23f857e833914b765fca3b8ca4c",
zip = true,
tag = "1.19.4:fields"
)
)
class MappingFile(val combined: String, val fields: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
import taboolib.common.io.runningClassMapWithoutLibrary
import taboolib.common.platform.event.SubscribeEvent
import taboolib.common.platform.function.disablePlugin
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ExecutorService
Expand Down Expand Up @@ -76,15 +77,34 @@ inline fun <reified T> nmsProxyClass(bind: String = "{name}Impl"): Class<T> {
return nmsProxyClass(T::class.java, bind)
}

/**
* 向玩家发送打包数据包(异步,1.19.4+)
*/
fun Player.sendBundlePacket(vararg packet: Any): CompletableFuture<Void> {
return sendBundlePacket(packet.toList())
}

/**
* 向玩家发送打包数据包(异步,1.19.4+)
*/
fun Player.sendBundlePacket(packet: List<Any>): CompletableFuture<Void> {
return if (MinecraftVersion.isBundlePacketSupported) {
sendPacket(ConnectionGetter.instance.newBundlePacket(packet))
} else {
CompletableFuture.allOf(*packet.map { sendPacket(it) }.toTypedArray())
}
}

/**
* 向玩家发送数据包(异步)
*/
fun Player.sendPacket(packet: Any): CompletableFuture<Unit> {
val future = CompletableFuture<Unit>()
fun Player.sendPacket(packet: Any): CompletableFuture<Void> {
val future = CompletableFuture<Void>()
val pool = packetPool.computeIfAbsent(name) { Executors.newSingleThreadExecutor() }
pool.submit {
try {
future.complete(sendPacketBlocking(packet))
sendPacketBlocking(packet)
future.complete(null)
} catch (e: Throwable) {
future.completeExceptionally(e)
e.printStackTrace()
Expand All @@ -93,6 +113,24 @@ fun Player.sendPacket(packet: Any): CompletableFuture<Unit> {
return future
}

/**
* 向玩家发送打包数据包(1.19.4+)
*/
fun Player.sendBundlePacketBlocking(vararg packet: Any) {
sendBundlePacketBlocking(packet.toList())
}

/**
* 向玩家发送打包数据包(1.19.4+)
*/
fun Player.sendBundlePacketBlocking(packet: List<Any>) {
if (MinecraftVersion.isBundlePacketSupported) {
sendPacketBlocking(ConnectionGetter.instance.newBundlePacket(packet))
} else {
packet.forEach { sendPacketBlocking(it) }
}
}

/**
* 向玩家发送数据包
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ object MinecraftVersion {

@Awake(LifeCycle.LOAD)
fun init() {
if (!isSupported) {
disablePlugin()
error("Unsupported Minecraft version, plugin disabled")
}
if (runningPlatform == Platform.BUKKIT) {
Reflex.remapper.add(RefRemapper)
}
Expand Down Expand Up @@ -50,7 +54,7 @@ object MinecraftVersion {
// universal >= 9
arrayOf("1.17", "1.17.1"),
arrayOf("1.18", "1.18.1", "1.18.2"), // 10
arrayOf("1.19", "1.19.1", "1.19.2", "1.19.3") // 11
arrayOf("1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4") // 11
)

/**
Expand Down Expand Up @@ -106,6 +110,13 @@ object MinecraftVersion {
major >= 9
}

/**
* 是否支持打包数据包(1.19.4+)
*/
val isBundlePacketSupported by unsafeLazy {
majorLegacy >= 11904
}

val mapping by unsafeLazy {
val mappingFile = if (isUniversal) {
MappingFile.files[runningVersion]
Expand Down
2 changes: 1 addition & 1 deletion module/module-ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
compileOnly("ink.ptms.core:v11903:11903-minimize:mapped")
compileOnly("ink.ptms.core:v11904:11904-minimize:mapped")
compileOnly("ink.ptms.core:v11600:11600-minimize")
compileOnly("ink.ptms.core:v10900:10900")
compileOnly(project(":common"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ typealias NMSPacketPlayOutSetSlot = net.minecraft.network.protocol.game.PacketPl

typealias NMSItemStack = net.minecraft.world.item.ItemStack

typealias Craft19Container = org.bukkit.craftbukkit.v1_19_R2.inventory.CraftContainer
typealias Craft19Container = org.bukkit.craftbukkit.v1_19_R3.inventory.CraftContainer

typealias Craft19ItemStack = org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack
typealias Craft19ItemStack = org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack

typealias Craft19Player = org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer
typealias Craft19Player = org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer

// 1.16

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Isolated
@file:Suppress("OPT_IN_IS_NOT_ENABLED")

package taboolib.platform.util

Expand All @@ -7,20 +8,30 @@ import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta
import taboolib.common.Isolated
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
fun Material?.isAir(): Boolean {
return this == null || this == Material.AIR || this.name.endsWith("_AIR")
contract { returns(false) implies (this@isAir != null) }
return this == null || this == Material.AIR || name.endsWith("_AIR")
}

@OptIn(ExperimentalContracts::class)
fun Material?.isNotAir(): Boolean {
contract { returns(true) implies (this@isNotAir != null) }
return !isAir()
}

@OptIn(ExperimentalContracts::class)
fun ItemStack?.isAir(): Boolean {
contract { returns(false) implies (this@isAir != null) }
return this == null || type == Material.AIR || type.name.endsWith("_AIR")
}

@OptIn(ExperimentalContracts::class)
fun ItemStack?.isNotAir(): Boolean {
contract { returns(true) implies (this@isNotAir != null) }
return !isAir()
}

Expand Down

0 comments on commit fb0b812

Please sign in to comment.