Destroy glass when it gets hit
This commit is contained in:
parent
8c9dc40350
commit
e6f1eec9e3
3 changed files with 25 additions and 17 deletions
|
@ -16,6 +16,7 @@ import org.bukkit.entity.Player
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.EventPriority
|
import org.bukkit.event.EventPriority
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.block.Action
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||||
import org.bukkit.event.entity.EntityDamageEvent
|
import org.bukkit.event.entity.EntityDamageEvent
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent
|
import org.bukkit.event.entity.PlayerDeathEvent
|
||||||
|
@ -110,6 +111,13 @@ object GameListener : Listener {
|
||||||
event.deathMessage = null
|
event.deathMessage = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onPlayerInteract(event: PlayerInteractEvent) {
|
||||||
|
if (event.player.inventory.itemInMainHand.type == Material.AIR && event.action == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
GameManager.destroyBlock(event.clickedBlock!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
fun onPlayerSwapHandItemsLowest(event: PlayerSwapHandItemsEvent) {
|
fun onPlayerSwapHandItemsLowest(event: PlayerSwapHandItemsEvent) {
|
||||||
event.isCancelled = true
|
event.isCancelled = true
|
||||||
|
|
|
@ -14,9 +14,8 @@ import de.moritzruth.spigot_ttt.game.players.Role
|
||||||
import de.moritzruth.spigot_ttt.plugin
|
import de.moritzruth.spigot_ttt.plugin
|
||||||
import de.moritzruth.spigot_ttt.utils.call
|
import de.moritzruth.spigot_ttt.utils.call
|
||||||
import de.moritzruth.spigot_ttt.utils.teleportToWorldSpawn
|
import de.moritzruth.spigot_ttt.utils.teleportToWorldSpawn
|
||||||
import org.bukkit.GameRule
|
import org.bukkit.*
|
||||||
import org.bukkit.Location
|
import org.bukkit.block.Block
|
||||||
import org.bukkit.Material
|
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
object GameManager {
|
object GameManager {
|
||||||
|
@ -177,6 +176,20 @@ object GameManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun destroyBlock(block: Block) {
|
||||||
|
if (phase != null && block.type.toString().contains("glass", true)) {
|
||||||
|
destroyedBlocks[block.location] = block.type
|
||||||
|
block.type = Material.AIR
|
||||||
|
world.playSound(
|
||||||
|
block.location,
|
||||||
|
Sound.BLOCK_GLASS_BREAK,
|
||||||
|
SoundCategory.BLOCKS,
|
||||||
|
1F,
|
||||||
|
1F
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun ensurePhase(phase: GamePhase?) {
|
fun ensurePhase(phase: GamePhase?) {
|
||||||
if (this.phase !== phase) throw IllegalStateException("The game must be in $phase phase")
|
if (this.phase !== phase) throw IllegalStateException("The game must be in $phase phase")
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,20 +88,7 @@ abstract class Gun(
|
||||||
|
|
||||||
if (rayTraceResult !== null) {
|
if (rayTraceResult !== null) {
|
||||||
val hitBlock = rayTraceResult.hitBlock
|
val hitBlock = rayTraceResult.hitBlock
|
||||||
|
if (hitBlock != null) GameManager.destroyBlock(hitBlock)
|
||||||
if (hitBlock != null) {
|
|
||||||
if (hitBlock.type.toString().contains("glass", true)) {
|
|
||||||
GameManager.destroyedBlocks[hitBlock.location] = hitBlock.type
|
|
||||||
hitBlock.type = Material.AIR
|
|
||||||
GameManager.world.playSound(
|
|
||||||
hitBlock.location,
|
|
||||||
Sound.BLOCK_GLASS_BREAK,
|
|
||||||
SoundCategory.BLOCKS,
|
|
||||||
1F,
|
|
||||||
1F
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val entity = rayTraceResult.hitEntity
|
val entity = rayTraceResult.hitEntity
|
||||||
|
|
||||||
|
|
Reference in a new issue