Minecraft Plugin, Mineable Spawner?

Yi
- in Plugins
2

I'm supposed to be programming plugins for a buddy. I've also been programming for 3 years. But now I've encountered a problem.

Who wants to be able to dismantle Spawner. With a pickaxe that Silktouch has. This is my first problem. My second is how I can save the type of spawner. So zombie, creeper, etc.

How can you program that.

Minecraft: 1.16.5, Spigot

gl

1. You need the BlockBreakEvent and test whether p.getInventory (). GetItemInMainHand () is a pickaxe and it has the Enchantment Silk Touch and then spawn the item

2. I think that works with SpawnerMeta spawnerMeta = spawner.getItemMeta () or something

ma

You ask whether the dismantled block is a spawner with event.getBlock.getType (). Equals (Material.SPAWNER)

2. You ask whether the player is holding a pickaxe with event.getPlayer (). GetItemInHand (). Equals (new ItemStack (Material.DIAMOND_PICKAXE))
(You have to do this for every pickaxe with which this should be possible, i.e. Diamond, Iron, etc.)

3. You ask whether the pickaxe is enchanted with Silktouch. Unfortunately I don't know exactly how to do it, but there are probably other people who have already answered the same question.

4. If all previous queries are true you drop a spawner with event.getBlock (). GetWorld (). DropItemNaturally (event.getBlock (). GetLocation (), new ItemStack ((ItemStack) material))

material is a variable here:
BlockData material = Material.SPAWNER.createBlockData (String.valueOf (event.getBlock (). GetBlockData (;

Unfortunately, I can't test whether this works with the Spawner type, but if it's enough to drop a normal Spawner to test everything, you can also use event.getBlock (). GetWorld (). DropItemNaturally (event.getBlock (). Use getLocation (), new ItemStack (Material.SPAWNER))

I hope everything works, as I said I haven't been able to test anything yet, but I think it should work that way