From f3f025a51e7c1587d6e61ce3c1955367fab842b5 Mon Sep 17 00:00:00 2001 From: TDSTOS Date: Mon, 13 Apr 2026 04:36:16 +0200 Subject: [PATCH] Update GameStateListener.kt Fix block breaking --- .../speedhg/listener/GameStateListener.kt | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/club/mcscrims/speedhg/listener/GameStateListener.kt b/src/main/kotlin/club/mcscrims/speedhg/listener/GameStateListener.kt index 7c8006e..12d209a 100644 --- a/src/main/kotlin/club/mcscrims/speedhg/listener/GameStateListener.kt +++ b/src/main/kotlin/club/mcscrims/speedhg/listener/GameStateListener.kt @@ -72,10 +72,10 @@ class GameStateListener : Listener { ) private val alwaysMaterials = mapOf( - Material.RED_MUSHROOM to Sound.BLOCK_GRASS_BREAK, + Material.RED_MUSHROOM to Sound.BLOCK_GRASS_BREAK, Material.BROWN_MUSHROOM to Sound.BLOCK_GRASS_BREAK, - Material.COCOA_BEANS to Sound.BLOCK_WOOD_BREAK, - Material.CACTUS to Sound.BLOCK_WOOL_BREAK + Material.COCOA to Sound.BLOCK_WOOD_BREAK, // ← Block heißt COCOA, nicht COCOA_BEANS + Material.CACTUS to Sound.BLOCK_WOOL_BREAK ) @EventHandler @@ -114,21 +114,9 @@ class GameStateListener : Listener { return } - // Invincibility: nur Whitelist-Blöcke erlaubt - if ( gameManager.currentState == GameState.INVINCIBILITY ) - { - if ( beforeInvisMaterials.containsKey( block.type ) || - alwaysMaterials.containsKey( block.type ) ) - { - pickupBlock( event, player ) - } else { - event.isCancelled = true - } - return - } - - // INGAME: alle Blöcke direkt in Inventar — nie auf den Boden fallen lassen - // (ItemDespawnEvent cancelt sonst alle Drops sofort) + // BUG 2 FIX: Kein separater Invis-Whitelist-Block mehr. + // Beide States (INVINCIBILITY + INGAME) laufen direkt in pickupBlock — + // Map-Protection (Diamant, Eisen) ist bereits oben abgehandelt. pickupBlock( event, player ) } @@ -138,7 +126,6 @@ class GameStateListener : Listener { ) { val block = event.block - // In pickupBlock, direkt vor event.isCancelled = true: if ( block.type == Material.RED_MUSHROOM || block.type == Material.BROWN_MUSHROOM ) { @@ -150,23 +137,32 @@ class GameStateListener : Listener { event.isCancelled = true + // BUG 1 FIX: !! entfernt → Elvis mit null-Safe-Fallback auf GENERIC_SOUND. + // Blöcke, die in keiner Map stehen (z.B. Erde, Gras im INGAME-State), + // bekommen einen neutralen Standard-Sound statt einer NPE. val sound = beforeInvisMaterials[ block.type ] - ?: alwaysMaterials[ block.type ]!! + ?: alwaysMaterials[ block.type ] + ?: Sound.BLOCK_STONE_BREAK - // block.getDrops( tool, player ) gibt den korrekten Vanilla-Drop-Context - // inkl. Age-State bei Cocoa, Fortune-Enchant, Silk-Touch usw. + // BUG 3 FIX: block.getDrops(tool, player) gibt für Material.COCOA + // korrekt Material.COCOA_BEANS zurück — Paper löst den Block→Item- + // Mapping intern auf. Kein manueller Sonderfall nötig. val drops = block.getDrops( player.inventory.itemInMainHand, player ) if ( !hasInventorySpace( player ) ) { drops.forEach { player.world.dropItem( block.location, it ) } - player.playSound( player.location, sound, 1f, 1f ) block.type = Material.AIR + + if ( sound != Sound.BLOCK_STONE_BREAK ) + player.playSound( player.location, sound, 1f, 1f ) return } + if ( sound != Sound.BLOCK_STONE_BREAK ) + player.playSound( player.location, sound, 1f, 1f ) + drops.forEach { player.inventory.addItem( it ) } - player.playSound( player.location, sound, 1f, 1f ) block.type = Material.AIR }