Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Mar 12, 2024
1 parent cf4c1e5 commit a2b07d3
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 56 deletions.
1 change: 1 addition & 0 deletions api/src/main/java/kr/toxicity/hud/api/nms/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.NotNull;

public interface NMS {
void inject(@NotNull Player player, @NotNull BarColor color);
void showBossBar(@NotNull Player player, @NotNull BarColor color, @NotNull Component component);
void removeBossBar(@NotNull Player player);
@NotNull NMSVersion getVersion();
Expand Down
36 changes: 20 additions & 16 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/DatabaseManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package kr.toxicity.hud.manager

import kr.toxicity.hud.api.database.HudDatabase
import kr.toxicity.hud.api.database.HudDatabaseConnector
import kr.toxicity.hud.api.hud.Hud
import kr.toxicity.hud.api.manager.DatabaseManager
import kr.toxicity.hud.api.player.HudPlayer
import kr.toxicity.hud.api.popup.Popup
import kr.toxicity.hud.player.HudPlayerImpl
import kr.toxicity.hud.resource.GlobalResource
import kr.toxicity.hud.util.*
Expand All @@ -27,19 +29,20 @@ object DatabaseManagerImpl: BetterHudManager, DatabaseManager {
}

override fun load(player: Player): HudPlayer {
val hud = HudPlayerImpl(player)
val yaml = getFile(player).toYaml()
hud.popups.addAll(yaml.getStringList("popups").mapNotNull {
PopupManagerImpl.getPopup(it)
}.filter {
!it.isDefault
})
hud.huds.addAll(yaml.getStringList("huds").mapNotNull {
HudManagerImpl.getHud(it)
}.filter {
!it.isDefault
})
return hud
return HudPlayerImpl(
player,
yaml.getStringList("huds").mapNotNull {
HudManagerImpl.getHud(it)
}.filter {
!it.isDefault
}.toMutableSet(),
yaml.getStringList("popups").mapNotNull {
PopupManagerImpl.getPopup(it)
}.filter {
!it.isDefault
}.toMutableSet()
)
}

override fun save(player: HudPlayer): Boolean {
Expand Down Expand Up @@ -81,21 +84,22 @@ object DatabaseManagerImpl: BetterHudManager, DatabaseManager {

override fun load(player: Player): HudPlayer {
val uuid = player.uniqueId.toString()
val hud = HudPlayerImpl(player)
val huds = HashSet<Hud>()
val popups = HashSet<Popup>()
mysql.prepareStatement("SELECT type, name FROM enabled_hud WHERE uuid = '$uuid';").use { s ->
val result = s.executeQuery()
while (result.next()) {
when (result.getString("type")) {
"hud" -> HudManagerImpl.getHud(result.getString("name"))?.let { h ->
if (!h.isDefault) hud.huds.add(h)
if (!h.isDefault) huds.add(h)
}
"popup" -> PopupManagerImpl.getPopup(result.getString("popup"))?.let { p ->
if (!p.isDefault) hud.popups.add(p)
if (!p.isDefault) popups.add(p)
}
}
}
}
return hud
return HudPlayerImpl(player, huds, popups)
}

override fun save(player: HudPlayer): Boolean {
Expand Down
19 changes: 15 additions & 4 deletions dist/src/main/kotlin/kr/toxicity/hud/player/HudPlayerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ import org.bukkit.boss.BarColor
import org.bukkit.entity.Player
import java.util.concurrent.ConcurrentHashMap

class HudPlayerImpl(private val player: Player): HudPlayer {

private var popups = PopupManagerImpl.defaultPopups.toMutableSet()
private var huds = HudManagerImpl.defaultHuds.toMutableSet()
class HudPlayerImpl(
private val player: Player,
huds: MutableSet<Hud>,
popups: MutableSet<Popup>
): HudPlayer {
private var huds = huds.apply {
addAll(HudManagerImpl.defaultHuds)
}
private var popups = popups.apply {
addAll(PopupManagerImpl.defaultPopups)
}

private var tick = 0L
private var last: WidthComponent = EMPTY_WIDTH_COMPONENT
Expand Down Expand Up @@ -71,6 +78,9 @@ class HudPlayerImpl(private val player: Player): HudPlayer {
private val autoSave = asyncTaskTimer(6000, 6000) {
save()
}
init {
PLUGIN.nms.inject(player, ShaderManager.barColor)
}

override fun getHudComponent(): WidthComponent = last
override fun getAdditionalComponent(): WidthComponent? = additionalComp
Expand Down Expand Up @@ -108,6 +118,7 @@ class HudPlayerImpl(private val player: Player): HudPlayer {
addAll(HudManagerImpl.defaultHuds)
}
}

override fun cancel() {
popupGroup.forEach {
it.value.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class NMSImpl: NMS {
}
}

override fun showBossBar(player: Player, color: BarColor, component: Component) {
override fun inject(player: Player, color: BarColor) {
player as CraftPlayer
bossBarMap.getOrPut(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, component)
}.update(color, component)
bossBarMap.computeIfAbsent(player.uniqueId) {
PlayerBossBar(player, player.handle.connection, color, Component.empty())
}
}
override fun showBossBar(player: Player, color: BarColor, component: Component) {
bossBarMap[player.uniqueId]?.update(color, component)
}

override fun removeBossBar(player: Player) {
Expand Down

0 comments on commit a2b07d3

Please sign in to comment.