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))
|
||||
|
||||
@@ -16,7 +16,9 @@ import org.bukkit.event.block.LeavesDecayEvent
|
||||
import org.bukkit.event.enchantment.EnchantItemEvent
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent
|
||||
import org.bukkit.event.entity.ItemDespawnEvent
|
||||
import org.bukkit.event.inventory.*
|
||||
import org.bukkit.event.player.PlayerAttemptPickupItemEvent
|
||||
import org.bukkit.event.player.PlayerDropItemEvent
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
@@ -169,7 +171,35 @@ class GameStateListener : Listener {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user