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:
TDSTOS
2026-03-25 21:42:04 +01:00
parent ef183f6add
commit 0f95499a0f
6 changed files with 47 additions and 3 deletions

View File

@@ -5,6 +5,9 @@ import club.mcscrims.speedhg.kit.ability.PassiveAbility
import net.kyori.adventure.text.Component import net.kyori.adventure.text.Component
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.entity.Player 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. * Base class for every kit in SpeedHG.
@@ -61,6 +64,8 @@ abstract class Kit {
// Item distribution // Item distribution
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
abstract val cachedItems: ConcurrentHashMap<UUID, List<ItemStack>>
/** /**
* Give the player their kit-specific items at game start (after teleportation). * Give the player their kit-specific items at game start (after teleportation).
* The standard HG items (soup, compass, etc.) are already given by [GameManager]. * The standard HG items (soup, compass, etc.) are already given by [GameManager].

View File

@@ -9,6 +9,9 @@ import club.mcscrims.speedhg.kit.ability.PassiveAbility
import net.kyori.adventure.text.Component import net.kyori.adventure.text.Component
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
class BackupKit : Kit() { class BackupKit : Kit() {
@@ -52,6 +55,8 @@ class BackupKit : Kit() {
// ── Item distribution ───────────────────────────────────────────────────── // ── Item distribution ─────────────────────────────────────────────────────
override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
override fun giveItems( player: Player, playstyle: Playstyle ) {} override fun giveItems( player: Player, playstyle: Playstyle ) {}
private class NoActive( playstyle: Playstyle ) : ActiveAbility( playstyle ) { private class NoActive( playstyle: Playstyle ) : ActiveAbility( playstyle ) {

View File

@@ -61,7 +61,7 @@ class GoblinKit : Kit() {
// ── Item distribution ───────────────────────────────────────────────────── // ── Item distribution ─────────────────────────────────────────────────────
private val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>() override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
override fun giveItems( override fun giveItems(
player: Player, player: Player,

View File

@@ -62,7 +62,7 @@ class IceMageKit : Kit() {
// ── Item distribution ───────────────────────────────────────────────────── // ── Item distribution ─────────────────────────────────────────────────────
private val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>() override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
override fun giveItems( override fun giveItems(
player: Player, player: Player,

View File

@@ -14,6 +14,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import org.bukkit.potion.PotionEffect import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType import org.bukkit.potion.PotionEffectType
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
/** /**
* ────────────────────────────────────────────────────────────────────────────── * ──────────────────────────────────────────────────────────────────────────────
@@ -60,6 +62,8 @@ class TemplateKit : Kit() {
// ── Item distribution ───────────────────────────────────────────────────── // ── Item distribution ─────────────────────────────────────────────────────
override val cachedItems = ConcurrentHashMap<UUID, List<ItemStack>>()
override fun giveItems(player: Player, playstyle: Playstyle) { override fun giveItems(player: Player, playstyle: Playstyle) {
// Slot 8 = ability trigger item (always present) // Slot 8 = ability trigger item (always present)
player.inventory.setItem(8, ItemStack(Material.BLAZE_ROD)) player.inventory.setItem(8, ItemStack(Material.BLAZE_ROD))

View File

@@ -16,7 +16,9 @@ import org.bukkit.event.block.LeavesDecayEvent
import org.bukkit.event.enchantment.EnchantItemEvent import org.bukkit.event.enchantment.EnchantItemEvent
import org.bukkit.event.entity.EntityDamageByEntityEvent import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.FoodLevelChangeEvent import org.bukkit.event.entity.FoodLevelChangeEvent
import org.bukkit.event.entity.ItemDespawnEvent
import org.bukkit.event.inventory.* import org.bukkit.event.inventory.*
import org.bukkit.event.player.PlayerAttemptPickupItemEvent
import org.bukkit.event.player.PlayerDropItemEvent import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerItemDamageEvent import org.bukkit.event.player.PlayerItemDamageEvent
import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerJoinEvent
@@ -169,7 +171,35 @@ class GameStateListener : Listener {
return return
} }
// TODO: add kit item check val kitItems = plugin.kitManager.getSelectedKit( player )?.cachedItems?.get( player.uniqueId ) ?: return
val item = event.itemDrop.itemStack
if (kitItems.contains( item ))
{
event.isCancelled = true
player.playSound( player.location, Sound.BLOCK_NOTE_BLOCK_BASS, 1f, 1f )
}
}
@EventHandler
fun onPickupItem(
event: PlayerAttemptPickupItemEvent
) {
val player = event.player
if ( gameManager.currentState == GameState.INVINCIBILITY ||
gameManager.currentState == GameState.INGAME )
return
event.isCancelled = true
player.playSound( player.location, Sound.BLOCK_NOTE_BLOCK_BASS, 1f, 1f )
}
@EventHandler
fun onItemDespawn(
event: ItemDespawnEvent
) {
event.isCancelled = true
} }
private val swordNerf = 0.5 private val swordNerf = 0.5