Skip to content

Commit ec43085

Browse files
committed
[2.0.9] Fix
1 parent 8d85ef7 commit ec43085

File tree

17 files changed

+102
-123
lines changed

17 files changed

+102
-123
lines changed

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group=me.arasple.mc.trchat
2-
version=2.0.8
3-
taboolib_version=6.0.12-26
2+
version=2.0.9
3+
taboolib_version=6.0.12-35
44
kotlin.incremental=true
55
kotlin.incremental.java=true
66
koltin.incremental.useClasspathSnapshot=true

project/runtime-bukkit/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies {
1212
compileOnly(project(":project:common"))
1313
compileOnly(project(":project:module-adventure"))
1414
compileOnly(project(":project:module-nms"))
15-
compileOnly("ink.ptms.core:v12001:12001:universal")
15+
compileOnly("ink.ptms.core:v12002:12002:universal")
1616
compileOnly("net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT")
1717

1818
compileOnly("com.discordsrv:discordsrv:1.26.0")

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/api/impl/BukkitProxyManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ object BukkitProxyManager : ClientMessageManager {
135135
if (processor == null || Bukkit.getPlayerExact(target) != null) {
136136
getProxyPlayer(target)?.sendLang(node, *args)
137137
} else {
138-
sendMessage(recipient, arrayOf("SendLang", target, node, *args))
138+
sendMessage(recipient, arrayOf("ForwardMessage", "SendLang", target, node, *args))
139139
}
140140
}
141141

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/ChatSession.kt

+14-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@ class ChatSession(val player: Player) {
2727
var lastPrivateMessage = ""
2828
var lastPrivateTo = ""
2929
var cancelChat = false
30-
var channel: String?
31-
private set
30+
@JvmField
31+
var channel: String? = null
3232

3333
init {
34-
val data = player.data
35-
channel = if (data.channel != null && Channel.channels[data.channel] != null) {
36-
data.channel
37-
} else {
38-
Settings.defaultChannel
34+
val stored = player.data.channel
35+
fun join(string: String): Boolean {
36+
val id = Channel.channels.keys.firstOrNull { string.equals(it, ignoreCase = true) } ?: return false
37+
val channel = Channel.channels[id]!!
38+
setChannel(channel)
39+
channel.listeners.add(player.name)
40+
channel.events.join(player)
41+
return true
42+
}
43+
if (stored == null || !join(stored)) {
44+
join(Settings.defaultChannel)
3945
}
4046
}
4147

@@ -100,6 +106,7 @@ class ChatSession(val player: Player) {
100106
}
101107

102108
fun removeSession(player: Player) {
109+
Channel.quit(player, hint = false)
103110
sessions -= player.uniqueId
104111
}
105112

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/Channel.kt

+11-10
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,18 @@ open class Channel(
209209
val channels = mutableMapOf<String, Channel>()
210210

211211
fun join(player: Player, channel: String, hint: Boolean = true): Boolean {
212-
val id = channels.keys.firstOrNull { channel.equals(it, ignoreCase = true) }
213-
channels[id]?.let {
214-
return join(player, it, hint)
215-
}
216-
quit(player)
217-
return false
212+
val id = channels.keys.firstOrNull { channel.equals(it, ignoreCase = true) } ?: return false
213+
return join(player, channels[id]!!, hint)
218214
}
219215

220216
fun join(player: Player, channel: Channel, hint: Boolean = true): Boolean {
221217
if (!player.passPermission(channel.settings.joinPermission)) {
222-
player.sendLang("General-No-Permission")
218+
if (hint) {
219+
player.sendLang("General-No-Permission")
220+
}
223221
return false
224222
}
223+
quit(player, hint = false)
225224
player.session.setChannel(channel)
226225
channel.listeners.add(player.name)
227226
channel.events.join(player)
@@ -232,15 +231,17 @@ open class Channel(
232231
return true
233232
}
234233

235-
fun quit(player: Player) {
234+
fun quit(player: Player, setDefault: Boolean = false, hint: Boolean = true) {
236235
player.session.getChannel()?.let {
237236
if (!it.settings.autoJoin) {
238237
it.listeners -= player.name
239238
}
240239
it.events.quit(player)
241-
player.sendLang("Channel-Quit", it.id)
240+
if (hint) {
241+
player.sendLang("Channel-Quit", it.id)
242+
}
242243
}
243-
if (!join(player, Settings.defaultChannel)) {
244+
if (!setDefault || !join(player, Settings.defaultChannel)) {
244245
player.session.setChannel(null)
245246
}
246247
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/channel/PrivateChannel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PrivateChannel(
5757
) {
5858
execute<Player> { sender, _, _ ->
5959
if (sender.session.channel == this@PrivateChannel.id) {
60-
quit(sender)
60+
quit(sender, true)
6161
} else {
6262
sender.sendLang("Private-Message-No-Player")
6363
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/EnderChestShow.kt

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ object EnderChestShow : Function("ENDERCHEST") {
7878
override fun parseVariable(sender: Player, arg: String): ComponentText? {
7979
return computeAndCache(sender).let {
8080
BukkitProxyManager.sendMessage(sender, arrayOf(
81+
"ForwardMessage",
8182
"EnderChestShow",
8283
MinecraftVersion.minecraftVersion,
8384
sender.name,

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/InventoryShow.kt

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ object InventoryShow : Function("INVENTORY") {
7979
override fun parseVariable(sender: Player, arg: String): ComponentText? {
8080
return computeAndCache(sender).let {
8181
BukkitProxyManager.sendMessage(sender, arrayOf(
82+
"ForwardMessage",
8283
"InventoryShow",
8384
MinecraftVersion.minecraftVersion,
8485
sender.name,

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/display/function/standard/ItemShow.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ object ItemShow : Function("ITEM") {
7777
private val cacheComponent: Cache<ItemStack, ComponentText> = CacheBuilder.newBuilder()
7878
.maximumSize(50)
7979
.build()
80-
val cacheHopper: Cache<String, Inventory> = CacheBuilder.newBuilder()
80+
val cacheInventory: Cache<String, Inventory> = CacheBuilder.newBuilder()
8181
.maximumSize(50)
8282
.build()
8383

@@ -115,6 +115,7 @@ object ItemShow : Function("ITEM") {
115115
if (ui) {
116116
val sha1 = computeAndCache(sender, item).let {
117117
BukkitProxyManager.sendMessage(sender, arrayOf(
118+
"ForwardMessage",
118119
"ItemShow",
119120
MinecraftVersion.minecraftVersion,
120121
sender.name,
@@ -165,18 +166,24 @@ object ItemShow : Function("ITEM") {
165166

166167
fun computeAndCache(sender: Player, item: ItemStack): Pair<String, String> {
167168
val sha1 = item.serializeToByteArray(zipped = false).encodeBase64().digest("sha-1")
168-
if (cacheHopper.getIfPresent(sha1) != null) {
169-
return sha1 to cacheHopper.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64()
169+
if (cacheInventory.getIfPresent(sha1) != null) {
170+
return sha1 to cacheInventory.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64()
170171
}
171-
val menu = buildMenu<Hopper>(sender.asLangText("Function-Item-Show-Title", sender.name)) {
172+
// val inv = if (item.type.name.endsWith("SHULKER_BOX")) {
173+
// val blockStateMeta = item.itemMeta!!.clone() as BlockStateMeta
174+
// val shulkerBox = blockStateMeta.blockState as ShulkerBox
175+
// shulkerBox.inventory
176+
// } else {
177+
val inv = buildMenu<Hopper>(sender.asLangText("Function-Item-Show-Title", sender.name)) {
172178
rows(1)
173179
map("xxixx")
174180
set('x', XMaterial.BLACK_STAINED_GLASS_PANE) { name = "§r" }
175181
set('i', item)
176182
onClick(lock = true)
177183
}
178-
cacheHopper.put(sha1, menu)
179-
return sha1 to menu.serializeToByteArray().encodeBase64()
184+
// }
185+
cacheInventory.put(sha1, inv)
186+
return sha1 to inv.serializeToByteArray().encodeBase64()
180187
}
181188

182189
@Suppress("Deprecation")

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/main/CommandChannel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object CommandChannel {
3232
}
3333
literal("quit", "leave") {
3434
execute<Player> { sender, _, _ ->
35-
Channel.quit(sender)
35+
Channel.quit(sender, true)
3636
}
3737
}
3838
execute<Player> { _, _, _ ->

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/command/main/CommandViews.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import taboolib.common.platform.command.command
1414
import taboolib.common5.util.decodeBase64
1515
import taboolib.expansion.createHelper
1616
import taboolib.module.lang.sendLang
17+
import taboolib.module.ui.virtual.openVirtualInventory
18+
import taboolib.module.ui.virtual.virtualize
1719
import taboolib.platform.util.sendLang
1820

1921
/**
@@ -28,8 +30,8 @@ object CommandViews {
2830
command("view-item", permissionDefault = PermissionDefault.TRUE) {
2931
dynamic("item") {
3032
execute<Player> { sender, _, argument ->
31-
ItemShow.cacheHopper.getIfPresent(argument)?.let {
32-
sender.openInventory(it)
33+
ItemShow.cacheInventory.getIfPresent(argument)?.let {
34+
sender.openVirtualInventory(it.virtualize())
3335
} ?: kotlin.run {
3436
sender.sendLang("Function-Inventory-Show-Unavailable")
3537
}
@@ -46,7 +48,7 @@ object CommandViews {
4648
dynamic("inventory") {
4749
execute<Player> { sender, _, argument ->
4850
InventoryShow.cache.getIfPresent(argument)?.let {
49-
sender.openInventory(it)
51+
sender.openVirtualInventory(it.virtualize())
5052
} ?: kotlin.run {
5153
sender.sendLang("Function-Inventory-Show-Unavailable")
5254
}
@@ -63,7 +65,7 @@ object CommandViews {
6365
dynamic("enderchest") {
6466
execute<Player> { sender, _, argument ->
6567
EnderChestShow.cache.getIfPresent(argument)?.let {
66-
sender.openInventory(it)
68+
sender.openVirtualInventory(it.virtualize())
6769
} ?: kotlin.run {
6870
sender.sendLang("Function-EnderChest-Show-Unavailable")
6971
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerPackets.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import taboolib.common.platform.Platform
55
import taboolib.common.platform.PlatformSide
66
import taboolib.common.platform.event.SubscribeEvent
77
import taboolib.module.nms.MinecraftVersion.majorLegacy
8+
import taboolib.module.nms.PacketReceiveEvent
89
import taboolib.module.nms.PacketSendEvent
910

1011
/**
@@ -15,15 +16,21 @@ import taboolib.module.nms.PacketSendEvent
1516
object ListenerPackets {
1617

1718
/**
18-
* 去除登录时右上角提示
19+
* 去除进入时右上角提示/禁止聊天举报
1920
*/
2021
@SubscribeEvent
2122
fun secure(e: PacketSendEvent) {
22-
if (majorLegacy >= 11902) {
23-
when (e.packet.name) {
24-
"ClientboundServerDataPacket" -> e.packet.write("enforcesSecureChat", true)
25-
"ClientboundPlayerChatHeaderPacket" -> e.isCancelled = true
26-
}
23+
if (majorLegacy < 11902) return
24+
when (e.packet.name) {
25+
"ClientboundServerDataPacket" -> e.packet.write("enforcesSecureChat", true)
26+
"ClientboundPlayerChatHeaderPacket" -> e.isCancelled = true
27+
}
28+
}
29+
30+
@SubscribeEvent
31+
fun secure(e: PacketReceiveEvent) {
32+
if (e.packet.name == "ServerboundChatSessionUpdatePacket") {
33+
e.isCancelled = true
2734
}
2835
}
2936

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/proxy/BukkitProxyProcessor.kt

+32-22
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import me.arasple.mc.trchat.module.display.function.standard.ItemShow
1010
import me.arasple.mc.trchat.module.internal.TrChatBukkit
1111
import me.arasple.mc.trchat.module.internal.proxy.redis.RedisManager
1212
import me.arasple.mc.trchat.module.internal.proxy.redis.TrRedisMessage
13-
import me.arasple.mc.trchat.util.*
13+
import me.arasple.mc.trchat.util.buildMessage
14+
import me.arasple.mc.trchat.util.print
1415
import me.arasple.mc.trchat.util.proxy.common.MessageReader
16+
import me.arasple.mc.trchat.util.sendComponent
17+
import me.arasple.mc.trchat.util.toUUID
1518
import org.bukkit.Bukkit
1619
import org.bukkit.configuration.file.YamlConfiguration
1720
import org.bukkit.entity.Player
21+
import org.bukkit.event.inventory.InventoryType
1822
import org.bukkit.plugin.messaging.PluginMessageListener
1923
import org.bukkit.plugin.messaging.PluginMessageRecipient
2024
import taboolib.common.platform.function.console
@@ -55,6 +59,9 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {
5559

5660
fun execute(data: Array<String>) {
5761
when (data[0]) {
62+
"ForwardMessage" -> {
63+
execute(data.drop(1).toTypedArray())
64+
}
5865
"SendLang" -> {
5966
val to = data[1]
6067
val node = data[2]
@@ -116,33 +123,36 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {
116123
BukkitProxyManager.sendMessage(onlinePlayers.firstOrNull(), arrayOf("LoadedProxyChannel", id))
117124
}
118125
"ItemShow" -> {
119-
if (data[1] == MinecraftVersion.minecraftVersion) {
120-
val name = data[2]
121-
val sha1 = data[3]
122-
if (ItemShow.cacheHopper.getIfPresent(sha1) == null) {
123-
val inventory = data[4].decodeBase64().deserializeToInventory(createNoClickHopper(console().asLangText("Function-Item-Show-Title", name)))
124-
ItemShow.cacheHopper.put(sha1, inventory)
125-
}
126+
if (data[1] > MinecraftVersion.minecraftVersion) return
127+
val name = data[2]
128+
val sha1 = data[3]
129+
if (ItemShow.cacheInventory.getIfPresent(sha1) == null) {
130+
val inventory = data[4].decodeBase64().deserializeToInventory(
131+
Bukkit.createInventory(null, InventoryType.HOPPER, console().asLangText("Function-Item-Show-Title", name))
132+
)
133+
ItemShow.cacheInventory.put(sha1, inventory)
126134
}
127135
}
128136
"InventoryShow" -> {
129-
if (data[1] == MinecraftVersion.minecraftVersion) {
130-
val name = data[2]
131-
val sha1 = data[3]
132-
if (InventoryShow.cache.getIfPresent(sha1) == null) {
133-
val inventory = data[4].decodeBase64().deserializeToInventory(createNoClickChest(6, console().asLangText("Function-Inventory-Show-Title", name)))
134-
InventoryShow.cache.put(sha1, inventory)
135-
}
137+
if (data[1] > MinecraftVersion.minecraftVersion) return
138+
val name = data[2]
139+
val sha1 = data[3]
140+
if (InventoryShow.cache.getIfPresent(sha1) == null) {
141+
val inventory = data[4].decodeBase64().deserializeToInventory(
142+
Bukkit.createInventory(null, 6, console().asLangText("Function-Inventory-Show-Title", name))
143+
)
144+
InventoryShow.cache.put(sha1, inventory)
136145
}
137146
}
138147
"EnderChestShow" -> {
139-
if (data[1] == MinecraftVersion.minecraftVersion) {
140-
val name = data[2]
141-
val sha1 = data[3]
142-
if (EnderChestShow.cache.getIfPresent(sha1) == null) {
143-
val inventory = data[4].decodeBase64().deserializeToInventory(createNoClickChest(3, console().asLangText("Function-EnderChest-Show-Title", name)))
144-
EnderChestShow.cache.put(sha1, inventory)
145-
}
148+
if (data[1] > MinecraftVersion.minecraftVersion) return
149+
val name = data[2]
150+
val sha1 = data[3]
151+
if (EnderChestShow.cache.getIfPresent(sha1) == null) {
152+
val inventory = data[4].decodeBase64().deserializeToInventory(
153+
Bukkit.createInventory(null, 3, console().asLangText("Function-EnderChest-Show-Title", name))
154+
)
155+
EnderChestShow.cache.put(sha1, inventory)
146156
}
147157
}
148158
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/script/kether/KetherActions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal object KetherActions {
2222
now {
2323
when (action.lowercase()) {
2424
"join" -> Channel.join(player(), channel, hint)
25-
"quit", "leave" -> Channel.quit(player())
25+
"quit", "leave" -> Channel.quit(player(), true)
2626
else -> error("Unknown channel action: $action")
2727
}
2828
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/util/BukkitUtil.kt

-21
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,13 @@ import org.bukkit.Bukkit
1212
import org.bukkit.OfflinePlayer
1313
import org.bukkit.command.CommandSender
1414
import org.bukkit.entity.Player
15-
import org.bukkit.event.inventory.InventoryType
1615
import taboolib.common.util.unsafeLazy
1716
import taboolib.module.chat.ComponentText
1817
import taboolib.module.nms.MinecraftVersion
19-
import taboolib.module.ui.MenuHolder
20-
import taboolib.module.ui.type.Basic
21-
import taboolib.module.ui.type.Hopper
2218
import taboolib.platform.util.sendLang
2319

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

26-
fun createNoClickChest(rows: Int, title: String) =
27-
MenuHolder(object : Basic(title) {
28-
init {
29-
rows(rows)
30-
onClick(lock = true)
31-
}
32-
}).inventory
33-
34-
@Suppress("Deprecation")
35-
fun createNoClickHopper(title: String) =
36-
Bukkit.createInventory(MenuHolder(object : Hopper(title) {
37-
init {
38-
rows(1)
39-
onClick(lock = true)
40-
}
41-
}), InventoryType.HOPPER, title)
42-
4322
fun String?.toCondition() = if (this == null) Condition.EMPTY else Condition(this)
4423

4524
fun Condition?.pass(commandSender: CommandSender): Boolean {

0 commit comments

Comments
 (0)