✨ Bedrock remover
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package dev.solsynth.snConnect
|
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.SnCommand
|
||||||
import dev.solsynth.snConnect.commands.SnCommandCompleter
|
import dev.solsynth.snConnect.commands.SnCommandCompleter
|
||||||
import dev.solsynth.snConnect.listeners.SnChatListener
|
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")!!.setExecutor(SnCommand(this.sn!!, this.economy))
|
||||||
Bukkit.getPluginCommand("solar")!!.tabCompleter = SnCommandCompleter()
|
Bukkit.getPluginCommand("solar")!!.tabCompleter = SnCommandCompleter()
|
||||||
|
|
||||||
|
Bukkit.getPluginCommand("eatrock")!!.setExecutor(BedrockRemoverCommand(this.economy))
|
||||||
|
Bukkit.getPluginCommand("eatrock")!!.tabCompleter = BedrockRemoverCompleter()
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
String.format(
|
String.format(
|
||||||
"Successfully loaded Solar Network Connect connected with %s",
|
"Successfully loaded Solar Network Connect connected with %s",
|
||||||
|
@@ -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<out String>): 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 <money/materials>")
|
||||||
|
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<out String>
|
||||||
|
): MutableList<String> {
|
||||||
|
return when (args.size) {
|
||||||
|
1 -> paymentMethods.filter { it.startsWith(args[0], ignoreCase = true) }.toMutableList()
|
||||||
|
else -> mutableListOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -17,7 +17,16 @@ commands:
|
|||||||
aliases: ['sn']
|
aliases: ['sn']
|
||||||
permission: solar-network.command.sn
|
permission: solar-network.command.sn
|
||||||
permission-message: §cYou don't have the permission -> §6[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<money/materials>
|
||||||
|
aliases: ['eatrock']
|
||||||
|
permission: solar-network.command.eatrock
|
||||||
|
permission-message: §cYou don't have the permission -> §6[solar-network.command.eatrock]
|
||||||
permissions:
|
permissions:
|
||||||
solar-network.command.sn:
|
solar-network.command.sn:
|
||||||
description: Permission of uses Solar Network Command
|
description: Permission of uses Solar Network Command
|
||||||
default: true
|
default: true
|
||||||
|
solar-network.command.eatrock:
|
||||||
|
description: Permission to remove bedrock with payment
|
||||||
|
default: op
|
||||||
|
Reference in New Issue
Block a user