Skip to content

Commit

Permalink
[2.0.10] Update 1.20.4 & Fix
Browse files Browse the repository at this point in the history
* Abandon hopper gui
* Abandon virtual gui
* Support latest colors
* Show shulker box
* Switch Cheat-Client-Secure-Chat
  • Loading branch information
ItsFlicker committed Dec 29, 2023
1 parent 7353708 commit a608c61
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 97 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ subprojects {
compileOnly(fileTree("${rootDir.resolve("libs")}"))
compileOnly("com.google.code.gson:gson:2.8.5")
compileOnly("com.google.guava:guava:21.0")
compileOnly("net.kyori:adventure-api:4.13.0")
compileOnly("net.kyori:adventure-api:4.15.0")
implementation("com.eatthepath:fast-uuid:0.2.0")

compileOnly("io.izzel.taboolib:common:$taboolib_version")
Expand Down Expand Up @@ -80,6 +80,7 @@ subprojects {
relocate("taboolib", "${rootProject.group}.taboolib")
relocate("kotlin.", "kotlin${kotlinVersionNum}.") { exclude("kotlin.Metadata") }
relocate("com.eatthepath.uuid", "${rootProject.group}.library.uuid")
// Velocity properties
relocate("@plugin_id@", rootProject.name.toLowerCase())
relocate("@plugin_name@", rootProject.name)
relocate("@plugin_version@", rootProject.version.toString())
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
group=me.arasple.mc.trchat
version=2.0.9
taboolib_version=6.0.12-35
version=2.0.10
taboolib_version=6.0.12-55
kotlin.incremental=true
kotlin.incremental.java=true
koltin.incremental.useClasspathSnapshot=true
Expand Down
2 changes: 1 addition & 1 deletion project/module-adventure/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
compileOnly(project(":project:common"))
compileOnly(project(":project:module-nms"))
compileOnly("net.kyori:adventure-platform-bukkit:4.3.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,12 @@ fun ComponentText.toAdventure() = gson(toRawMessage())
fun Packet.getComponent(): ComponentText? {
return when (name) {
"ClientboundSystemChatPacket" -> {
// val raw = if (gsonSerializer != null) {
// gson(source.invokeMethod<Component>("adventure\$content")!!)
// } else {
// NMS.instance.rawMessageFromCraftChatMessage(source.invokeMethod<Any>("content")!!)
// }
val raw = source.invokeMethod<String>("content", findToParent = false, remap = false) ?: return null
Components.parseRaw(raw)
val iChat = source.invokeMethod<Any>("a", findToParent = false, remap = false) ?: return null
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
}
"PacketPlayOutChat" -> {
// val raw = if (gsonSerializer != null) {
// gson(read<Component>("adventure\$message")!!)
// } else {
// NMS.instance.rawMessageFromCraftChatMessage(read<Any>("a")!!)
// }
val raw = NMS.instance.rawMessageFromCraftChatMessage(read<Any>("a") ?: return null)
Components.parseRaw(raw)
val iChat = read<Any>("a") ?: return null
Components.parseRaw(NMS.instance.rawMessageFromCraftChatMessage(iChat))
}
else -> error("Unsupported packet $name")
}
Expand Down
2 changes: 1 addition & 1 deletion project/module-nms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
compileOnly(project(":project:common"))
compileOnly("ink.ptms.core:v12004:12004:mapped")
compileOnly("ink.ptms.core:v12002:12002:mapped")
compileOnly("ink.ptms.core:v12001:12001:mapped")
compileOnly("ink.ptms.core:v11903:11903:mapped")
compileOnly("ink.ptms.core:v11902:11902:mapped")
compileOnly("ink.ptms.core:v11901:11901:mapped")
Expand Down
2 changes: 1 addition & 1 deletion project/runtime-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
compileOnly(project(":project:common"))
compileOnly(project(":project:module-adventure"))
compileOnly(project(":project:module-nms"))
compileOnly("ink.ptms.core:v12002:12002:universal")
compileOnly("ink.ptms.core:v12004:12004:universal")
compileOnly("net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT")

compileOnly("com.discordsrv:discordsrv:1.26.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import me.arasple.mc.trchat.module.display.channel.PrivateChannel
import me.arasple.mc.trchat.util.color.CustomColor
import me.arasple.mc.trchat.util.color.MessageColors
import me.arasple.mc.trchat.util.data
import me.arasple.mc.trchat.util.reportOnce
import org.bukkit.entity.Player
import taboolib.expansion.getDataContainer
import taboolib.module.nms.Packet
Expand Down Expand Up @@ -54,7 +53,7 @@ class ChatSession(val player: Player) {
if (selectedColor != null && player.hasPermission(MessageColors.COLOR_PERMISSION_NODE + selectedColor)) {
CustomColor.get(selectedColor)
} else {
default ?: CustomColor(CustomColor.ColorType.NORMAL, "§r")
default ?: CustomColor(CustomColor.ColorType.NORMAL, "§f")
}
}
}
Expand All @@ -73,15 +72,15 @@ class ChatSession(val player: Player) {

fun addMessage(packet: Packet) {
try {
val component = packet.getComponent()
receivedMessages += ChatMessage(
packet.source,
packet.getComponent()?.toPlainText()?.replace("\\s".toRegex(), "")?.takeLast(48)
component?.toPlainText()?.replace("\\s".toRegex(), "")?.takeLast(48)
)
if (receivedMessages.size > 100) {
receivedMessages.removeFirstOrNull()
}
} catch (t: Throwable) {
t.reportOnce("Error occurred while caching chat packet!Maybe your server doesn't support it")
} catch (_: Throwable) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ object EnderChestShow : Function("ENDERCHEST") {
.maximumSize(10)
.build()

private val inventorySlots = IntRange(0, 26).toList()
private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§r" }
private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
Expand Down Expand Up @@ -114,7 +113,7 @@ object EnderChestShow : Function("ENDERCHEST") {
}
val menu = buildMenu<Linked<ItemStack>>(sender.asLangText("Function-EnderChest-Show-Title", sender.name)) {
rows(3)
slots(inventorySlots)
slots((0..26).toList())
elements { (0..26).map { inventory.getItem(it).replaceAir() } }
onGenerate { _, element, _, _ -> element }
onClick(lock = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ object InventoryShow : Function("INVENTORY") {
.build()

private val inventorySlots = IntRange(18, 53).toList()
private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§r" }
private val PLACEHOLDER_ITEM = buildItem(XMaterial.WHITE_STAINED_GLASS_PANE) { name = "§r" }
private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" }
private val PLACEHOLDER_ITEM = buildItem(XMaterial.WHITE_STAINED_GLASS_PANE) { name = "§f" }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import me.arasple.mc.trchat.module.internal.hook.type.HookDisplayItem
import me.arasple.mc.trchat.module.internal.script.Reaction
import me.arasple.mc.trchat.util.*
import org.bukkit.Material
import org.bukkit.block.ShulkerBox
import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.BlockStateMeta
import taboolib.common.io.digest
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
Expand All @@ -33,11 +35,9 @@ import taboolib.module.nms.MinecraftVersion
import taboolib.module.nms.getI18nName
import taboolib.module.nms.getLocaleKey
import taboolib.module.ui.buildMenu
import taboolib.module.ui.type.Hopper
import taboolib.platform.util.asLangText
import taboolib.platform.util.buildItem
import taboolib.platform.util.sendLang
import taboolib.platform.util.serializeToByteArray
import taboolib.module.ui.type.Basic
import taboolib.module.ui.type.Linked
import taboolib.platform.util.*

/**
* @author ItsFlicker
Expand Down Expand Up @@ -81,6 +81,8 @@ object ItemShow : Function("ITEM") {
.maximumSize(50)
.build()

private val AIR_ITEM = buildItem(XMaterial.GRAY_STAINED_GLASS_PANE) { name = "§f" }

override fun createVariable(sender: Player, message: String): String {
return if (!enabled) {
message
Expand Down Expand Up @@ -169,19 +171,30 @@ object ItemShow : Function("ITEM") {
if (cacheInventory.getIfPresent(sha1) != null) {
return sha1 to cacheInventory.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64()
}
// val inv = if (item.type.name.endsWith("SHULKER_BOX")) {
// val blockStateMeta = item.itemMeta!!.clone() as BlockStateMeta
// val shulkerBox = blockStateMeta.blockState as ShulkerBox
// shulkerBox.inventory
// } else {
val inv = buildMenu<Hopper>(sender.asLangText("Function-Item-Show-Title", sender.name)) {
rows(1)
map("xxixx")
set('x', XMaterial.BLACK_STAINED_GLASS_PANE) { name = "§r" }
set('i', item)
onClick(lock = true)
val inv = if (item.type.name.endsWith("SHULKER_BOX")) {
val blockStateMeta = item.itemMeta!! as BlockStateMeta
val shulkerBox = blockStateMeta.blockState as ShulkerBox
val shulkerInv = shulkerBox.inventory
buildMenu<Linked<ItemStack>>(sender.asLangText("Function-Item-Show-Title", sender.name)) {
rows(3)
slots((0..26).toList())
elements { (0..26).map { shulkerInv.getItem(it).replaceAir() } }
onGenerate { _, element, _, _ -> element }
onClick(lock = true)
}
} else {
buildMenu<Basic>(sender.asLangText("Function-Item-Show-Title", sender.name)) {
rows(3)
map(
"xxxxxxxxx",
"xxxxixxxx",
"xxxxxxxxx"
)
set('x', XMaterial.BLACK_STAINED_GLASS_PANE) { name = "§f" }
set('i', item)
onClick(lock = true)
}
}
// }
cacheInventory.put(sha1, inv)
return sha1 to inv.serializeToByteArray().encodeBase64()
}
Expand All @@ -207,4 +220,6 @@ object ItemShow : Function("ITEM") {
}
}

private fun ItemStack?.replaceAir() = if (isAir()) AIR_ITEM else this

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import taboolib.common.platform.command.command
import taboolib.common5.util.decodeBase64
import taboolib.expansion.createHelper
import taboolib.module.lang.sendLang
import taboolib.module.ui.virtual.openVirtualInventory
import taboolib.module.ui.virtual.virtualize
import taboolib.platform.util.sendLang

/**
Expand All @@ -31,7 +29,7 @@ object CommandViews {
dynamic("item") {
execute<Player> { sender, _, argument ->
ItemShow.cacheInventory.getIfPresent(argument)?.let {
sender.openVirtualInventory(it.virtualize())
sender.openInventory(it)
} ?: kotlin.run {
sender.sendLang("Function-Inventory-Show-Unavailable")
}
Expand All @@ -48,7 +46,7 @@ object CommandViews {
dynamic("inventory") {
execute<Player> { sender, _, argument ->
InventoryShow.cache.getIfPresent(argument)?.let {
sender.openVirtualInventory(it.virtualize())
sender.openInventory(it)
} ?: kotlin.run {
sender.sendLang("Function-Inventory-Show-Unavailable")
}
Expand All @@ -65,7 +63,7 @@ object CommandViews {
dynamic("enderchest") {
execute<Player> { sender, _, argument ->
EnderChestShow.cache.getIfPresent(argument)?.let {
sender.openVirtualInventory(it.virtualize())
sender.openInventory(it)
} ?: kotlin.run {
sender.sendLang("Function-EnderChest-Show-Unavailable")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HookNova : HookDisplayItem() {
val novaMaterial = Nova.materialRegistry.getOrNull(item) ?: return item
return buildItem(XMaterial.SHULKER_SHELL) {
amount = item.amount
name = "§r" + novaMaterial.getLocalizedName(adaptPlayer(player).getLocale().lowercase())
name = "§f" + novaMaterial.getLocalizedName(adaptPlayer(player).getLocale().lowercase())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import me.arasple.mc.trchat.module.display.ChatSession
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
import taboolib.common.platform.event.SubscribeEvent
import taboolib.module.configuration.ConfigNode
import taboolib.module.nms.MinecraftVersion.majorLegacy
import taboolib.module.nms.PacketReceiveEvent
import taboolib.module.nms.PacketSendEvent
Expand All @@ -15,14 +16,20 @@ import taboolib.module.nms.PacketSendEvent
@PlatformSide([Platform.BUKKIT])
object ListenerPackets {

@ConfigNode("Options.Cheat-Client-Secure-Chat", "settings.yml")
var cheatClientSecureChat = true
private set

/**
* 去除进入时右上角提示/禁止聊天举报
*/
@SubscribeEvent
fun secure(e: PacketSendEvent) {
if (majorLegacy < 11902) return
when (e.packet.name) {
"ClientboundServerDataPacket" -> e.packet.write("enforcesSecureChat", true)
"ClientboundServerDataPacket" -> {
if (cheatClientSecureChat) e.packet.write("enforcesSecureChat", true)
}
"ClientboundPlayerChatHeaderPacket" -> e.isCancelled = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import me.arasple.mc.trchat.module.display.function.standard.ItemShow
import me.arasple.mc.trchat.module.internal.TrChatBukkit
import me.arasple.mc.trchat.module.internal.proxy.redis.RedisManager
import me.arasple.mc.trchat.module.internal.proxy.redis.TrRedisMessage
import me.arasple.mc.trchat.util.buildMessage
import me.arasple.mc.trchat.util.print
import me.arasple.mc.trchat.util.*
import me.arasple.mc.trchat.util.proxy.common.MessageReader
import me.arasple.mc.trchat.util.sendComponent
import me.arasple.mc.trchat.util.toUUID
import org.bukkit.Bukkit
import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryType
import org.bukkit.plugin.messaging.PluginMessageListener
import org.bukkit.plugin.messaging.PluginMessageRecipient
import taboolib.common.platform.function.console
Expand Down Expand Up @@ -128,7 +124,7 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {
val sha1 = data[3]
if (ItemShow.cacheInventory.getIfPresent(sha1) == null) {
val inventory = data[4].decodeBase64().deserializeToInventory(
Bukkit.createInventory(null, InventoryType.HOPPER, console().asLangText("Function-Item-Show-Title", name))
createNoClickChest(3, console().asLangText("Function-Item-Show-Title", name))
)
ItemShow.cacheInventory.put(sha1, inventory)
}
Expand All @@ -139,7 +135,7 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {
val sha1 = data[3]
if (InventoryShow.cache.getIfPresent(sha1) == null) {
val inventory = data[4].decodeBase64().deserializeToInventory(
Bukkit.createInventory(null, 6, console().asLangText("Function-Inventory-Show-Title", name))
createNoClickChest(6, console().asLangText("Function-Inventory-Show-Title", name))
)
InventoryShow.cache.put(sha1, inventory)
}
Expand All @@ -150,7 +146,7 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {
val sha1 = data[3]
if (EnderChestShow.cache.getIfPresent(sha1) == null) {
val inventory = data[4].decodeBase64().deserializeToInventory(
Bukkit.createInventory(null, 3, console().asLangText("Function-EnderChest-Show-Title", name))
createNoClickChest(3, console().asLangText("Function-EnderChest-Show-Title", name))
)
EnderChestShow.cache.put(sha1, inventory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ import org.bukkit.entity.Player
import taboolib.common.util.unsafeLazy
import taboolib.module.chat.ComponentText
import taboolib.module.nms.MinecraftVersion
import taboolib.module.ui.MenuHolder
import taboolib.module.ui.type.Basic
import taboolib.platform.util.sendLang

val isDragonCoreHooked by unsafeLazy { Bukkit.getPluginManager().isPluginEnabled("DragonCore") && MinecraftVersion.major < 8 }

fun createNoClickChest(rows: Int, title: String) =
MenuHolder(object : Basic(title) {
init {
rows(rows)
onClick(lock = true)
}
}).inventory

fun String?.toCondition() = if (this == null) Condition.EMPTY else Condition(this)

fun Condition?.pass(commandSender: CommandSender): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ object Hex {
}

fun parseLegacy(message: String): String {
return ChatColor.translateAlternateColorCodes('&', message)
return ChatColor.translateAlternateColorCodes('&', message.replace("&r", "&f").replace("§r", "§f"))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Formats:
text: '&8[&3%server_name%&8] '
hover: |-
&7Server &3%server_name%
&r
&f
&7Version: &6%server_version%
&7Online: &a%server_online%&7/&2%server_max_players%
&7TPS: &b%server_tps%
Expand Down
Loading

0 comments on commit a608c61

Please sign in to comment.