Refactor kits, add safety checks and fixes
Multiple refactors and defensive fixes across kits and event handling: - RecraftManager: use Bukkit.getOnlinePlayers() collection API instead of stream. - ActiveAbility: mark backing _hitsRequired as @Volatile for thread-safety. - BlackPanther, Rattlesnake, TheWorld, Gladiator, Goblin, Venom, Voodoo: change how kit overrides are accessed (lazy or helper) to avoid stale initialization and improve readability. - Gladiator: add an ended flag to avoid double-ending fights. - Goblin & TheWorld: add game state checks to avoid restoring kits or operating on players after game end. - Rattlesnake: guard scheduled miss task with player.isOnline check and simplify action bar call. - Venom: clean up active shield tasks on kit removal and make damage handling null-safe with apply. - Voodoo: wrap passive tick in runCatching and log failures to prevent uncaught exceptions from killing tasks. - KitEventDispatcher: skip handling if victim is not alive, change interact handler to ignoreCancelled = false, and add isAlive helper. - ItemBuilder: switch lore serialization to MiniMessage, disable default italic decoration, and reuse a MiniMessage instance. These changes improve robustness, avoid race conditions, and add defensive guards against invalid state during scheduled tasks and event handling.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package club.mcscrims.speedhg.util
|
||||
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.format.TextDecoration
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
@@ -11,6 +13,8 @@ class ItemBuilder(
|
||||
private val itemStack: ItemStack
|
||||
) {
|
||||
|
||||
private val mm = MiniMessage.miniMessage()
|
||||
|
||||
constructor(
|
||||
type: Material
|
||||
) : this(
|
||||
@@ -48,13 +52,10 @@ class ItemBuilder(
|
||||
lore: List<String>
|
||||
): ItemBuilder
|
||||
{
|
||||
itemStack.editMeta {
|
||||
val cLore = lore.stream()
|
||||
.map( this::color )
|
||||
.map( Component::text )
|
||||
.toList()
|
||||
|
||||
it.lore( cLore as List<Component> )
|
||||
itemStack.editMeta { meta ->
|
||||
meta.lore(lore.map { line ->
|
||||
mm.deserialize( line ).decoration( TextDecoration.ITALIC, false )
|
||||
})
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user