9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-04 15:41:36 +00:00

Fixed action bar compatibility

This commit is contained in:
Auxilor
2021-11-25 12:13:21 +00:00
parent b59ed55d46
commit 1131dd6c50
3 changed files with 25 additions and 33 deletions

View File

@@ -1,11 +1,12 @@
package com.willfp.ecoskills.actionbar
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.ListenerPriority
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.events.PacketEvent
import com.comphenix.protocol.wrappers.EnumWrappers
import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.util.StringUtils
import org.bukkit.entity.Player
class ActionBarCompatSetActionBar(
@@ -16,16 +17,7 @@ class ActionBarCompatSetActionBar(
false
) {
override fun onSend(packet: PacketContainer, player: Player, event: PacketEvent) {
val component = StringUtils.toComponent(
StringUtils.jsonToLegacy(
packet.chatComponents.read(0).json
)
)
if (!component.contains(ActionBarUtils.ecoSkillsComponentSignature)) {
val uuid = player.uniqueId
ActionBarUtils.blacklist(uuid)
}
ActionBarUtils.blacklist(player.uniqueId)
}
}
@@ -34,24 +26,16 @@ class ActionBarCompatChatMessage(
) : AbstractPacketAdapter(
plugin,
PacketType.Play.Server.CHAT,
ListenerPriority.LOWEST,
false
) {
override fun onSend(packet: PacketContainer, player: Player, event: PacketEvent) {
val position = packet.bytes.read(0).toInt()
val type = packet.chatTypes.read(0)
if (position != 2) {
if (type != EnumWrappers.ChatType.GAME_INFO) {
return
}
val component = StringUtils.toComponent(
StringUtils.jsonToLegacy(
packet.chatComponents.read(0).json
)
)
if (!component.contains(ActionBarUtils.ecoSkillsComponentSignature)) {
val uuid = player.uniqueId
ActionBarUtils.blacklist(uuid)
}
ActionBarUtils.blacklist(player.uniqueId)
}
}

View File

@@ -8,7 +8,8 @@ import org.bukkit.Bukkit
import java.util.UUID
object ActionBarUtils {
private val blacklist = mutableSetOf<UUID>()
private val blacklist = mutableMapOf<UUID, Long>()
private val whitelist = mutableMapOf<UUID, Long>()
private val plugin = EcoSkillsPlugin.getInstance()
val ecoSkillsComponentSignature = StringUtils.toComponent(
@@ -16,18 +17,24 @@ object ActionBarUtils {
)
fun blacklist(uuid: UUID) {
blacklist.add(uuid)
plugin.scheduler.runLater({
unBlacklist(uuid)
}, 60)
if (isWhitelisted(uuid)) {
return
}
blacklist[uuid] = System.currentTimeMillis() + 3000
}
fun unBlacklist(uuid: UUID) {
blacklist.remove(uuid)
private fun isBlacklisted(uuid: UUID): Boolean {
val endTime = blacklist[uuid] ?: return false
return endTime > System.currentTimeMillis()
}
fun isBlacklisted(uuid: UUID): Boolean {
return blacklist.contains(uuid)
private fun whitelistTemp(uuid: UUID) {
whitelist[uuid] = System.currentTimeMillis() + 50
}
private fun isWhitelisted(uuid: UUID): Boolean {
val endTime = whitelist[uuid] ?: return false
return endTime > System.currentTimeMillis()
}
@JvmStatic
@@ -43,6 +50,7 @@ object ActionBarUtils {
val component = StringUtils.formatToComponent(message, player)
.append(ecoSkillsComponentSignature)
whitelistTemp(player.uniqueId)
player.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
*TextComponent.fromLegacyText(StringUtils.toLegacy(component))

View File

@@ -318,7 +318,7 @@ persistent-action-bar:
# If the persistent action bar should be enabled
enabled: true
# The format
format: "&c &f%player_health%/%player_max_health% &#e884b0🛡 &f%ecoskills_defense% &8| &#db0000🗡 &f%ecoskills_strength%"
format: "&c &f%player_health_rounded%/%player_max_health_rounded% &#e884b0🛡 &f%ecoskills_defense% &8| &#db0000🗡 &f%ecoskills_strength%"
commands:
top: