Skip to main content

Documentation Index

Fetch the complete documentation index at: https://kotly.voxray.su/llms.txt

Use this file to discover all available pages before exploring further.

Данный плагин реализует супер кирку, которая ломает окружающие блоки в радиусе 5 блоков.
package kplugin.superpickaxe

import kotly.plugin.KotlyPlugin
import kotly.util.amperstand
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType

class SuperPickaxe : KotlyPlugin() {
    init {
        manager.registerCommand(this, "give-pick").setExecutor(GiveCommand())
        manager.registerListener(this, InteractListener())
    }

    inner class GiveCommand : CommandExecutor {
        override fun onCommand(sender: CommandSender, cmd: Command, label: String, args: Array<out String>): Boolean {
            if (sender !is Player) return false
            val item = createItem()
            (sender as Player).inventory.addItem(item)
            return true
        }

        private fun createItem(): ItemStack {
            val item = ItemStack(Material.DIAMOND_PICKAXE)
            val meta = item.itemMeta

            meta.displayName("&b&lСупер кирка".amperstand())

            val key = NamespacedKey(kotly, "type")
            meta.persistentDataContainer.set(key, PersistentDataType.STRING, "sp")
            item.itemMeta = meta
            return item
        }
    }

    inner class InteractListener : Listener {
        @EventHandler
        fun onInteract(event: BlockBreakEvent) {
            val item = event.player.inventory.itemInMainHand
            if (item.type != Material.DIAMOND_PICKAXE) return

            val key = NamespacedKey(kotly, "type")
            val value = item.itemMeta.persistentDataContainer.get(key, PersistentDataType.STRING) ?: return

            if (value != "sp") return
            breakInRadius(event.player, 5)
        }

        private fun breakInRadius(player: Player, radius: Int) {
            val world = player.world
            val origin = player.location.block

            Bukkit.getScheduler().runTask(kotly, Runnable {
                for (x in -radius..radius) {
                    for (y in -radius..radius) {
                        for (z in -radius..radius) {
                            val block = world.getBlockAt(
                                origin.x + x,
                                origin.y + y,
                                origin.z + z
                            )

                            if (block.type.isAir) continue
                            val event = BlockBreakEvent(block, player)
                            Bukkit.getPluginManager().callEvent(event)
                            if (event.isCancelled) continue // Защита для плагинов правата
                            block.breakNaturally(player.inventory.itemInMainHand)
                            block.type = Material.AIR
                        }
                    }
                }
            })
        }
    }
}


SuperPickaxe::class