mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-04 15:41:36 +00:00
Added persistent action bar
This commit is contained in:
@@ -6,6 +6,7 @@ dependencies {
|
||||
compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
|
||||
compileOnly 'com.willfp:EcoEnchants:8.2.0'
|
||||
compileOnly 'net.kyori:adventure-api:4.9.2'
|
||||
compileOnly 'net.essentialsx:EssentialsX:2.19.0'
|
||||
compileOnly 'org.jetbrains.exposed:exposed-core:0.34.1'
|
||||
compileOnly 'org.jetbrains.exposed:exposed-dao:0.34.1'
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.willfp.ecoskills;
|
||||
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.ecoskills.actionbar.ActionBarCompatChatMessage;
|
||||
import com.willfp.ecoskills.actionbar.ActionBarCompatSetActionBar;
|
||||
import com.willfp.ecoskills.actionbar.ActionBarUtils;
|
||||
import com.willfp.ecoskills.commands.CommandEcoskills;
|
||||
import com.willfp.ecoskills.commands.CommandSkills;
|
||||
import com.willfp.ecoskills.config.EffectsYml;
|
||||
@@ -76,6 +80,10 @@ public class EcoSkillsPlugin extends EcoPlugin {
|
||||
this.getEventManager().registerListener(skill);
|
||||
}
|
||||
|
||||
if (this.getConfigYml().getBool("persistent-action-bar.enabled")) {
|
||||
ActionBarUtils.startRunnable();
|
||||
}
|
||||
|
||||
this.getScheduler().runTimer(new LeaderboardHandler.Runnable(), 50, 2400);
|
||||
}
|
||||
|
||||
@@ -117,6 +125,14 @@ public class EcoSkillsPlugin extends EcoPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPacketAdapter> loadPacketAdapters() {
|
||||
return Arrays.asList(
|
||||
new ActionBarCompatChatMessage(this),
|
||||
new ActionBarCompatSetActionBar(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PluginCommand> loadPluginCommands() {
|
||||
return Arrays.asList(
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.willfp.ecoskills.actionbar
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
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(
|
||||
plugin: EcoPlugin
|
||||
) : AbstractPacketAdapter(
|
||||
plugin,
|
||||
PacketType.Play.Server.SET_ACTION_BAR_TEXT,
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ActionBarCompatChatMessage(
|
||||
plugin: EcoPlugin
|
||||
) : AbstractPacketAdapter(
|
||||
plugin,
|
||||
PacketType.Play.Server.CHAT,
|
||||
false
|
||||
) {
|
||||
override fun onSend(packet: PacketContainer, player: Player, event: PacketEvent) {
|
||||
val position = packet.bytes.read(0).toInt()
|
||||
|
||||
if (position != 2) {
|
||||
return
|
||||
}
|
||||
|
||||
val component = StringUtils.toComponent(
|
||||
StringUtils.jsonToLegacy(
|
||||
packet.chatComponents.read(0).json
|
||||
)
|
||||
)
|
||||
|
||||
if (!component.contains(ActionBarUtils.ecoSkillsComponentSignature)) {
|
||||
val uuid = player.uniqueId
|
||||
ActionBarUtils.blacklist(uuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoskills.actionbar
|
||||
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import com.willfp.ecoskills.EcoSkillsPlugin
|
||||
import net.md_5.bungee.api.ChatMessageType
|
||||
import net.md_5.bungee.api.chat.TextComponent
|
||||
import org.bukkit.Bukkit
|
||||
import java.util.UUID
|
||||
|
||||
object ActionBarUtils {
|
||||
private val blacklist = mutableSetOf<UUID>()
|
||||
private val plugin = EcoSkillsPlugin.getInstance()
|
||||
|
||||
val ecoSkillsComponentSignature = StringUtils.toComponent(
|
||||
"§t" // Literally a random character
|
||||
)
|
||||
|
||||
fun blacklist(uuid: UUID) {
|
||||
blacklist.add(uuid)
|
||||
plugin.scheduler.runLater({
|
||||
unBlacklist(uuid)
|
||||
}, 60)
|
||||
}
|
||||
|
||||
fun unBlacklist(uuid: UUID) {
|
||||
blacklist.remove(uuid)
|
||||
}
|
||||
|
||||
fun isBlacklisted(uuid: UUID): Boolean {
|
||||
return blacklist.contains(uuid)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun startRunnable() {
|
||||
plugin.scheduler.runTimer({
|
||||
for (player in Bukkit.getOnlinePlayers()) {
|
||||
if (isBlacklisted(player.uniqueId)) {
|
||||
continue
|
||||
}
|
||||
|
||||
val message = plugin.configYml
|
||||
.getString("persistent-action-bar.format", false)
|
||||
val component = StringUtils.formatToComponent(message, player)
|
||||
.append(ecoSkillsComponentSignature)
|
||||
|
||||
player.spigot().sendMessage(
|
||||
ChatMessageType.ACTION_BAR,
|
||||
*TextComponent.fromLegacyText(StringUtils.toLegacy(component))
|
||||
)
|
||||
}
|
||||
}, 5, 5)
|
||||
}
|
||||
}
|
||||
@@ -313,6 +313,13 @@ damage-indicators:
|
||||
max-y-offset: 0.6
|
||||
max-z-offset: 0.6
|
||||
|
||||
# A constant action bar showing health and any other information to all players online
|
||||
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%"
|
||||
|
||||
commands:
|
||||
top:
|
||||
# If displayname (including rank) should be used
|
||||
|
||||
Reference in New Issue
Block a user