From 3803e27a061e26ee1b3265a1402193cc6739fc3e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 5 Oct 2025 19:06:56 +0800 Subject: [PATCH] :sparkles: Bedrock remover --- .../solsynth/snConnect/SolarNetworkConnect.kt | 5 + .../commands/BedrockRemoverCommand.kt | 220 ++++++++++++++++++ src/main/resources/plugin.yml | 11 +- 3 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/dev/solsynth/snConnect/commands/BedrockRemoverCommand.kt diff --git a/src/main/kotlin/dev/solsynth/snConnect/SolarNetworkConnect.kt b/src/main/kotlin/dev/solsynth/snConnect/SolarNetworkConnect.kt index 123ff01..2c8474a 100644 --- a/src/main/kotlin/dev/solsynth/snConnect/SolarNetworkConnect.kt +++ b/src/main/kotlin/dev/solsynth/snConnect/SolarNetworkConnect.kt @@ -1,5 +1,7 @@ package dev.solsynth.snConnect +import dev.solsynth.snConnect.commands.BedrockRemoverCommand +import dev.solsynth.snConnect.commands.BedrockRemoverCompleter import dev.solsynth.snConnect.commands.SnCommand import dev.solsynth.snConnect.commands.SnCommandCompleter import dev.solsynth.snConnect.listeners.SnChatListener @@ -106,6 +108,9 @@ class SolarNetworkConnect : JavaPlugin() { Bukkit.getPluginCommand("solar")!!.setExecutor(SnCommand(this.sn!!, this.economy)) Bukkit.getPluginCommand("solar")!!.tabCompleter = SnCommandCompleter() + Bukkit.getPluginCommand("eatrock")!!.setExecutor(BedrockRemoverCommand(this.economy)) + Bukkit.getPluginCommand("eatrock")!!.tabCompleter = BedrockRemoverCompleter() + logger.info( String.format( "Successfully loaded Solar Network Connect connected with %s", diff --git a/src/main/kotlin/dev/solsynth/snConnect/commands/BedrockRemoverCommand.kt b/src/main/kotlin/dev/solsynth/snConnect/commands/BedrockRemoverCommand.kt new file mode 100644 index 0000000..490dac2 --- /dev/null +++ b/src/main/kotlin/dev/solsynth/snConnect/commands/BedrockRemoverCommand.kt @@ -0,0 +1,220 @@ +package dev.solsynth.snConnect.commands + +import net.milkbowl.vault.economy.Economy +import net.milkbowl.vault.economy.EconomyResponse +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.Sound +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender +import org.bukkit.command.TabCompleter +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack + +class BedrockRemoverCommand(private val economy: Economy?) : CommandExecutor { + private val paymentMethods = listOf("money", "materials") + private val requiredMaterials = listOf( + Material.PISTON, + Material.TNT, + Material.LEVER, + Material.OAK_TRAPDOOR // Representative for trapdoor group + ) + + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + if (sender !is Player) { + sender.sendMessage(ChatColor.RED.toString() + "This command can only be used by players.") + return true + } + + if (args.isEmpty() || args.size > 1) { + sender.sendMessage(ChatColor.RED.toString() + "Usage: /bedrockremove ") + return true + } + + val paymentMethod = args[0].lowercase() + if (paymentMethod !in paymentMethods) { + sender.sendMessage(ChatColor.RED.toString() + "Invalid payment method. Use: money or materials.") + return true + } + + // Get the block the player is looking at + val targetBlock = sender.getTargetBlock(null, 10) + if (targetBlock == null || targetBlock.type != Material.BEDROCK) { + sender.sendMessage(ChatColor.RED.toString() + "You must be looking at a bedrock block within 10 blocks.") + return true + } + + // Attempt payment + val success = when (paymentMethod) { + "money" -> payWithMoney(sender, 100.0) + "materials" -> payWithAllMaterials(sender) + else -> return false + } + + if (!success) { + // Error messages are handled in the pay methods + return true + } + + // Remove the bedrock + targetBlock.type = Material.AIR + sender.sendMessage(ChatColor.GREEN.toString() + "Bedrock removed successfully!") + sender.playSound(sender.location, Sound.BLOCK_STONE_BREAK, 1.0f, 1.0f) + + return true + } + + private fun payWithMoney(player: Player, amount: Double): Boolean { + if (economy == null) { + player.sendMessage(ChatColor.RED.toString() + "Economy not available.") + return false + } + val response = economy.withdrawPlayer(player, "Bedrock removal", amount) + if (response.type != EconomyResponse.ResponseType.SUCCESS) { + player.sendMessage(ChatColor.RED.toString() + "Insufficient funds. You need ${amount}.") + return false + } + player.sendMessage(ChatColor.GREEN.toString() + "Withdrew $amount from your account.") + return true + } + + private fun payWithMaterial(player: Player, material: Material): Boolean { + val inventory = player.inventory + + // Special handling for materials with multiple variants + val hasItem = when (material) { + Material.OAK_TRAPDOOR -> { + // Check for any trapdoor type + inventory.contents.any { item -> item != null && item.type.name.endsWith("_TRAPDOOR") } + } + Material.PISTON -> { + // Check for any piston type + inventory.contents.any { item -> item != null && (item.type == Material.PISTON || item.type == Material.STICKY_PISTON) } + } + else -> inventory.contains(material, 1) + } + + if (!hasItem) { + player.sendMessage(ChatColor.RED.toString() + "You don't have a ${material.name.lowercase()} in your inventory.") + return false + } + + // Remove the item + when (material) { + Material.OAK_TRAPDOOR -> { + // Find and remove any trapdoor + for (item in inventory.contents) { + if (item != null && item.type.name.endsWith("_TRAPDOOR")) { + val amount = item.amount + if (amount > 1) { + item.amount = amount - 1 + } else { + inventory.remove(item) + } + break + } + } + } + Material.PISTON -> { + // Find and remove any piston + for (item in inventory.contents) { + if (item != null && (item.type == Material.PISTON || item.type == Material.STICKY_PISTON)) { + val amount = item.amount + if (amount > 1) { + item.amount = amount - 1 + } else { + inventory.remove(item) + } + break + } + } + } + else -> { + inventory.removeItem(ItemStack(material, 1)) + } + } + + player.sendMessage(ChatColor.GREEN.toString() + "Consumed 1 ${material.name.lowercase()}.") + return true + } + + private fun payWithAllMaterials(player: Player): Boolean { + val inventory = player.inventory + + // Check if player has all required materials + for (material in requiredMaterials) { + val hasItem = when (material) { + Material.OAK_TRAPDOOR -> { + // Check for any trapdoor type + inventory.contents.any { item -> item != null && item.type.name.endsWith("_TRAPDOOR") } + } + Material.PISTON -> { + // Check for any piston type + inventory.contents.any { item -> item != null && (item.type == Material.PISTON || item.type == Material.STICKY_PISTON) } + } + else -> inventory.contains(material, 1) + } + if (!hasItem) { + player.sendMessage(ChatColor.RED.toString() + "You don't have all required materials: piston, tnt, lever, and trapdoor.") + return false + } + } + + // Remove one of each material + for (material in requiredMaterials) { + when (material) { + Material.OAK_TRAPDOOR -> { + // Find and remove any trapdoor + for (item in inventory.contents) { + if (item != null && item.type.name.endsWith("_TRAPDOOR")) { + val amount = item.amount + if (amount > 1) { + item.amount = amount - 1 + } else { + inventory.remove(item) + } + break + } + } + } + Material.PISTON -> { + // Find and remove any piston + for (item in inventory.contents) { + if (item != null && (item.type == Material.PISTON || item.type == Material.STICKY_PISTON)) { + val amount = item.amount + if (amount > 1) { + item.amount = amount - 1 + } else { + inventory.remove(item) + } + break + } + } + } + else -> { + inventory.removeItem(ItemStack(material, 1)) + } + } + } + + player.sendMessage(ChatColor.GREEN.toString() + "Consumed materials: piston, tnt, lever, trapdoor.") + return true + } +} + +class BedrockRemoverCompleter : TabCompleter { + private val paymentMethods = listOf("money", "materials") + + override fun onTabComplete( + sender: CommandSender, + command: Command, + label: String, + args: Array + ): MutableList { + return when (args.size) { + 1 -> paymentMethods.filter { it.startsWith(args[0], ignoreCase = true) }.toMutableList() + else -> mutableListOf() + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f594edc..240c714 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,7 +17,16 @@ commands: aliases: ['sn'] permission: solar-network.command.sn permission-message: §cYou don't have the permission -> §6[solar-network.command.sn] + eatrock: + description: Remove bedrock with payment + usage: §e/eatrock §r + aliases: ['eatrock'] + permission: solar-network.command.eatrock + permission-message: §cYou don't have the permission -> §6[solar-network.command.eatrock] permissions: solar-network.command.sn: description: Permission of uses Solar Network Command - default: true \ No newline at end of file + default: true + solar-network.command.eatrock: + description: Permission to remove bedrock with payment + default: op