public void onBlockBreakEvent(BlockBreakEvent event) {
Block block = event.getBlock();
if (block.getType() != Material.SPAWNER) return;
Player player = event.getPlayer();
ItemStack itemInMainHand = player.getInventory().getItemInMainHand();
boolean validItem = itemInMainHand.getType() == Material.DIAMOND_PICKAXE
|| itemInMainHand.getType() == Material.NETHERITE_PICKAXE;
boolean validEnchant = itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH);
if (!validItem || !validEnchant) {
player.sendMessage("§c§lЧтобы получить спавнер, у вас должна быть алмазная или незеритовая кирка с шелковым касанием!");
return;
}
boolean dropItem = false;
if (player.hasPermission("blockBreaked.shogun")) {
if ((random.nextDouble() < chanceShogun)) {
dropItem = true;
}
} else if (player.hasPermission("blockBreaked.samurai")) {
if ((random.nextDouble() < chanceSamurai)) {
dropItem = true;
}
} else {
player.sendMessage("§c§lУ вас должна быть как минимум привилегия §fꑴ §c§l для выпадения спавнеров!");
return;
}
if (!dropItem) {
player.sendMessage("§c§lНе повезло, блок не выпал :(");
return;
}
CreatureSpawner spawner = (CreatureSpawner) block.getState();
EntityType spawnedType = spawner.getSpawnedType();
ItemStack droppedItem = new ItemStack(Material.SPAWNER, 1);
BlockStateMeta bsm = (BlockStateMeta) droppedItem.getItemMeta();
CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
cs.setSpawnedType(spawnedType);
bsm.setBlockState(cs);
droppedItem.setItemMeta(bsm);
Location blockLocation = block.getLocation();
block.breakNaturally();
blockLocation.getWorld().dropItemNaturally(blockLocation, droppedItem);
}