Skip to content

Commit

Permalink
[2.0.9] Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFlicker committed Nov 26, 2023
1 parent 8d85ef7 commit ec43085
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 123 deletions.
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.8
taboolib_version=6.0.12-26
version=2.0.9
taboolib_version=6.0.12-35
kotlin.incremental=true
kotlin.incremental.java=true
koltin.incremental.useClasspathSnapshot=true
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:v12001:12001:universal")
compileOnly("ink.ptms.core:v12002:12002: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 @@ -135,7 +135,7 @@ object BukkitProxyManager : ClientMessageManager {
if (processor == null || Bukkit.getPlayerExact(target) != null) {
getProxyPlayer(target)?.sendLang(node, *args)
} else {
sendMessage(recipient, arrayOf("SendLang", target, node, *args))
sendMessage(recipient, arrayOf("ForwardMessage", "SendLang", target, node, *args))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ class ChatSession(val player: Player) {
var lastPrivateMessage = ""
var lastPrivateTo = ""
var cancelChat = false
var channel: String?
private set
@JvmField
var channel: String? = null

init {
val data = player.data
channel = if (data.channel != null && Channel.channels[data.channel] != null) {
data.channel
} else {
Settings.defaultChannel
val stored = player.data.channel
fun join(string: String): Boolean {
val id = Channel.channels.keys.firstOrNull { string.equals(it, ignoreCase = true) } ?: return false
val channel = Channel.channels[id]!!
setChannel(channel)
channel.listeners.add(player.name)
channel.events.join(player)
return true
}
if (stored == null || !join(stored)) {
join(Settings.defaultChannel)
}
}

Expand Down Expand Up @@ -100,6 +106,7 @@ class ChatSession(val player: Player) {
}

fun removeSession(player: Player) {
Channel.quit(player, hint = false)
sessions -= player.uniqueId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,18 @@ open class Channel(
val channels = mutableMapOf<String, Channel>()

fun join(player: Player, channel: String, hint: Boolean = true): Boolean {
val id = channels.keys.firstOrNull { channel.equals(it, ignoreCase = true) }
channels[id]?.let {
return join(player, it, hint)
}
quit(player)
return false
val id = channels.keys.firstOrNull { channel.equals(it, ignoreCase = true) } ?: return false
return join(player, channels[id]!!, hint)
}

fun join(player: Player, channel: Channel, hint: Boolean = true): Boolean {
if (!player.passPermission(channel.settings.joinPermission)) {
player.sendLang("General-No-Permission")
if (hint) {
player.sendLang("General-No-Permission")
}
return false
}
quit(player, hint = false)
player.session.setChannel(channel)
channel.listeners.add(player.name)
channel.events.join(player)
Expand All @@ -232,15 +231,17 @@ open class Channel(
return true
}

fun quit(player: Player) {
fun quit(player: Player, setDefault: Boolean = false, hint: Boolean = true) {
player.session.getChannel()?.let {
if (!it.settings.autoJoin) {
it.listeners -= player.name
}
it.events.quit(player)
player.sendLang("Channel-Quit", it.id)
if (hint) {
player.sendLang("Channel-Quit", it.id)
}
}
if (!join(player, Settings.defaultChannel)) {
if (!setDefault || !join(player, Settings.defaultChannel)) {
player.session.setChannel(null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PrivateChannel(
) {
execute<Player> { sender, _, _ ->
if (sender.session.channel == this@PrivateChannel.id) {
quit(sender)
quit(sender, true)
} else {
sender.sendLang("Private-Message-No-Player")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ object EnderChestShow : Function("ENDERCHEST") {
override fun parseVariable(sender: Player, arg: String): ComponentText? {
return computeAndCache(sender).let {
BukkitProxyManager.sendMessage(sender, arrayOf(
"ForwardMessage",
"EnderChestShow",
MinecraftVersion.minecraftVersion,
sender.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ object InventoryShow : Function("INVENTORY") {
override fun parseVariable(sender: Player, arg: String): ComponentText? {
return computeAndCache(sender).let {
BukkitProxyManager.sendMessage(sender, arrayOf(
"ForwardMessage",
"InventoryShow",
MinecraftVersion.minecraftVersion,
sender.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object ItemShow : Function("ITEM") {
private val cacheComponent: Cache<ItemStack, ComponentText> = CacheBuilder.newBuilder()
.maximumSize(50)
.build()
val cacheHopper: Cache<String, Inventory> = CacheBuilder.newBuilder()
val cacheInventory: Cache<String, Inventory> = CacheBuilder.newBuilder()
.maximumSize(50)
.build()

Expand Down Expand Up @@ -115,6 +115,7 @@ object ItemShow : Function("ITEM") {
if (ui) {
val sha1 = computeAndCache(sender, item).let {
BukkitProxyManager.sendMessage(sender, arrayOf(
"ForwardMessage",
"ItemShow",
MinecraftVersion.minecraftVersion,
sender.name,
Expand Down Expand Up @@ -165,18 +166,24 @@ object ItemShow : Function("ITEM") {

fun computeAndCache(sender: Player, item: ItemStack): Pair<String, String> {
val sha1 = item.serializeToByteArray(zipped = false).encodeBase64().digest("sha-1")
if (cacheHopper.getIfPresent(sha1) != null) {
return sha1 to cacheHopper.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64()
if (cacheInventory.getIfPresent(sha1) != null) {
return sha1 to cacheInventory.getIfPresent(sha1)!!.serializeToByteArray().encodeBase64()
}
val menu = buildMenu<Hopper>(sender.asLangText("Function-Item-Show-Title", sender.name)) {
// 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)
}
cacheHopper.put(sha1, menu)
return sha1 to menu.serializeToByteArray().encodeBase64()
// }
cacheInventory.put(sha1, inv)
return sha1 to inv.serializeToByteArray().encodeBase64()
}

@Suppress("Deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object CommandChannel {
}
literal("quit", "leave") {
execute<Player> { sender, _, _ ->
Channel.quit(sender)
Channel.quit(sender, true)
}
}
execute<Player> { _, _, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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 @@ -28,8 +30,8 @@ object CommandViews {
command("view-item", permissionDefault = PermissionDefault.TRUE) {
dynamic("item") {
execute<Player> { sender, _, argument ->
ItemShow.cacheHopper.getIfPresent(argument)?.let {
sender.openInventory(it)
ItemShow.cacheInventory.getIfPresent(argument)?.let {
sender.openVirtualInventory(it.virtualize())
} ?: kotlin.run {
sender.sendLang("Function-Inventory-Show-Unavailable")
}
Expand All @@ -46,7 +48,7 @@ object CommandViews {
dynamic("inventory") {
execute<Player> { sender, _, argument ->
InventoryShow.cache.getIfPresent(argument)?.let {
sender.openInventory(it)
sender.openVirtualInventory(it.virtualize())
} ?: kotlin.run {
sender.sendLang("Function-Inventory-Show-Unavailable")
}
Expand All @@ -63,7 +65,7 @@ object CommandViews {
dynamic("enderchest") {
execute<Player> { sender, _, argument ->
EnderChestShow.cache.getIfPresent(argument)?.let {
sender.openInventory(it)
sender.openVirtualInventory(it.virtualize())
} ?: kotlin.run {
sender.sendLang("Function-EnderChest-Show-Unavailable")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
import taboolib.common.platform.event.SubscribeEvent
import taboolib.module.nms.MinecraftVersion.majorLegacy
import taboolib.module.nms.PacketReceiveEvent
import taboolib.module.nms.PacketSendEvent

/**
Expand All @@ -15,15 +16,21 @@ import taboolib.module.nms.PacketSendEvent
object ListenerPackets {

/**
* 去除登录时右上角提示
* 去除进入时右上角提示/禁止聊天举报
*/
@SubscribeEvent
fun secure(e: PacketSendEvent) {
if (majorLegacy >= 11902) {
when (e.packet.name) {
"ClientboundServerDataPacket" -> e.packet.write("enforcesSecureChat", true)
"ClientboundPlayerChatHeaderPacket" -> e.isCancelled = true
}
if (majorLegacy < 11902) return
when (e.packet.name) {
"ClientboundServerDataPacket" -> e.packet.write("enforcesSecureChat", true)
"ClientboundPlayerChatHeaderPacket" -> e.isCancelled = true
}
}

@SubscribeEvent
fun secure(e: PacketReceiveEvent) {
if (e.packet.name == "ServerboundChatSessionUpdatePacket") {
e.isCancelled = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ 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.*
import me.arasple.mc.trchat.util.buildMessage
import me.arasple.mc.trchat.util.print
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 @@ -55,6 +59,9 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {

fun execute(data: Array<String>) {
when (data[0]) {
"ForwardMessage" -> {
execute(data.drop(1).toTypedArray())
}
"SendLang" -> {
val to = data[1]
val node = data[2]
Expand Down Expand Up @@ -116,33 +123,36 @@ sealed interface BukkitProxyProcessor : PluginMessageListener {
BukkitProxyManager.sendMessage(onlinePlayers.firstOrNull(), arrayOf("LoadedProxyChannel", id))
}
"ItemShow" -> {
if (data[1] == MinecraftVersion.minecraftVersion) {
val name = data[2]
val sha1 = data[3]
if (ItemShow.cacheHopper.getIfPresent(sha1) == null) {
val inventory = data[4].decodeBase64().deserializeToInventory(createNoClickHopper(console().asLangText("Function-Item-Show-Title", name)))
ItemShow.cacheHopper.put(sha1, inventory)
}
if (data[1] > MinecraftVersion.minecraftVersion) return
val name = data[2]
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))
)
ItemShow.cacheInventory.put(sha1, inventory)
}
}
"InventoryShow" -> {
if (data[1] == MinecraftVersion.minecraftVersion) {
val name = data[2]
val sha1 = data[3]
if (InventoryShow.cache.getIfPresent(sha1) == null) {
val inventory = data[4].decodeBase64().deserializeToInventory(createNoClickChest(6, console().asLangText("Function-Inventory-Show-Title", name)))
InventoryShow.cache.put(sha1, inventory)
}
if (data[1] > MinecraftVersion.minecraftVersion) return
val name = data[2]
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))
)
InventoryShow.cache.put(sha1, inventory)
}
}
"EnderChestShow" -> {
if (data[1] == MinecraftVersion.minecraftVersion) {
val name = data[2]
val sha1 = data[3]
if (EnderChestShow.cache.getIfPresent(sha1) == null) {
val inventory = data[4].decodeBase64().deserializeToInventory(createNoClickChest(3, console().asLangText("Function-EnderChest-Show-Title", name)))
EnderChestShow.cache.put(sha1, inventory)
}
if (data[1] > MinecraftVersion.minecraftVersion) return
val name = data[2]
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))
)
EnderChestShow.cache.put(sha1, inventory)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal object KetherActions {
now {
when (action.lowercase()) {
"join" -> Channel.join(player(), channel, hint)
"quit", "leave" -> Channel.quit(player())
"quit", "leave" -> Channel.quit(player(), true)
else -> error("Unknown channel action: $action")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,13 @@ import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryType
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.module.ui.type.Hopper
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

@Suppress("Deprecation")
fun createNoClickHopper(title: String) =
Bukkit.createInventory(MenuHolder(object : Hopper(title) {
init {
rows(1)
onClick(lock = true)
}
}), InventoryType.HOPPER, title)

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

fun Condition?.pass(commandSender: CommandSender): Boolean {
Expand Down
Loading

0 comments on commit ec43085

Please sign in to comment.