Add cachedItems to kits; prevent kit item drops
Introduce an abstract cachedItems property on Kit (ConcurrentHashMap<UUID, List<ItemStack>>) to track per-player kit items. Update implementations (BackupKit, GoblinKit, IceMageKit, TemplateKit) to override and initialize cachedItems. GameStateListener now checks dropped items against the selected kit cache and cancels drops (playing a sound) for kit items, and adds handlers to cancel item pickup/despawn outside active game states. Add necessary imports for ItemStack, UUID, ConcurrentHashMap and new event types.
This commit is contained in:
@@ -5,6 +5,9 @@ import club.mcscrims.speedhg.kit.ability.PassiveAbility
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* Base class for every kit in SpeedHG.
|
||||
@@ -61,6 +64,8 @@ abstract class Kit {
|
||||
// Item distribution
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
abstract val cachedItems: ConcurrentHashMap<UUID, List<ItemStack>>
|
||||
|
||||
/**
|
||||
* Give the player their kit-specific items at game start (after teleportation).
|
||||
* The standard HG items (soup, compass, etc.) are already given by [GameManager].
|
||||
|
||||
@@ -9,6 +9,9 @@ import club.mcscrims.speedhg.kit.ability.PassiveAbility
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class BackupKit : Kit() {
|
||||
|
||||
@@ -52,6 +55,8 @@ class BackupKit : Kit() {
|
||||
|
||||
// ── Item distribution ─────────────────────────────────────────────────────
|
||||
|
||||
override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
|
||||
|
||||
override fun giveItems( player: Player, playstyle: Playstyle ) {}
|
||||
|
||||
private class NoActive( playstyle: Playstyle ) : ActiveAbility( playstyle ) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class GoblinKit : Kit() {
|
||||
|
||||
// ── Item distribution ─────────────────────────────────────────────────────
|
||||
|
||||
private val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
|
||||
override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
|
||||
|
||||
override fun giveItems(
|
||||
player: Player,
|
||||
|
||||
@@ -62,7 +62,7 @@ class IceMageKit : Kit() {
|
||||
|
||||
// ── Item distribution ─────────────────────────────────────────────────────
|
||||
|
||||
private val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
|
||||
override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
|
||||
|
||||
override fun giveItems(
|
||||
player: Player,
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.potion.PotionEffect
|
||||
import org.bukkit.potion.PotionEffectType
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* ──────────────────────────────────────────────────────────────────────────────
|
||||
@@ -60,6 +62,8 @@ class TemplateKit : Kit() {
|
||||
|
||||
// ── Item distribution ─────────────────────────────────────────────────────
|
||||
|
||||
override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
|
||||
|
||||
override fun giveItems(player: Player, playstyle: Playstyle) {
|
||||
// Slot 8 = ability trigger item (always present)
|
||||
player.inventory.setItem(8, ItemStack(Material.BLAZE_ROD))
|
||||
|
||||
Reference in New Issue
Block a user