mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
made main command logic
This commit is contained in:
parent
880d8e93c7
commit
58b1cb7648
1 changed files with 87 additions and 39 deletions
|
|
@ -1,44 +1,17 @@
|
|||
package xyz.alexcrea.cuanvil.command
|
||||
|
||||
import com.willfp.eco.core.lookup.matches
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||
|
||||
class EditConfigExecutor: CASubCommand() {
|
||||
|
||||
override fun executeCommand(sender: CommandSender,
|
||||
cmd: Command,
|
||||
cmdstr: String,
|
||||
args: Array<out String>): Boolean {
|
||||
if (sender !is HumanEntity) return false
|
||||
|
||||
if (!allowed(sender)) {
|
||||
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
||||
return false
|
||||
}
|
||||
if(PlatformUtil.isFolia){
|
||||
sender.sendMessage("§cIt look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia.")
|
||||
sender.sendMessage("§eIt is may come in a future version.")
|
||||
sender.sendMessage("")
|
||||
sender.sendMessage("§eCurrently you need to edit manually the config or copy from another server (spigot or better)")
|
||||
sender.sendMessage("§eThen /anvilconfigreload after config file is edited")
|
||||
return false
|
||||
}
|
||||
|
||||
if ("gui".equals(cmdstr, ignoreCase = true)) {
|
||||
sender.sendMessage("§c/ca gui has been moved to /ca config")
|
||||
}
|
||||
|
||||
MainConfigGui.getInstance().show(sender)
|
||||
|
||||
return true
|
||||
}
|
||||
class EditConfigExecutor : CASubCommand() {
|
||||
|
||||
override fun allowed(sender: CommandSender): Boolean {
|
||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||
|
|
@ -48,7 +21,79 @@ class EditConfigExecutor: CASubCommand() {
|
|||
return "Gui to edit the plugin's config"
|
||||
}
|
||||
|
||||
private fun allEnchantmentsByName(): Collection<String>{
|
||||
override fun executeCommand(
|
||||
sender: CommandSender,
|
||||
cmd: Command,
|
||||
cmdstr: String,
|
||||
args: Array<out String>
|
||||
): Boolean {
|
||||
if (sender !is HumanEntity) return false
|
||||
|
||||
if (!allowed(sender)) {
|
||||
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
||||
return false
|
||||
}
|
||||
if (PlatformUtil.isFolia) {
|
||||
sender.sendMessage("§cIt look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia.")
|
||||
sender.sendMessage("§eIt is may come in a future version.")
|
||||
sender.sendMessage("")
|
||||
sender.sendMessage("§eCurrently you need to edit manually the config or copy from another server (spigot or better)")
|
||||
sender.sendMessage("§eThen /ca reload after config file is edited")
|
||||
return false
|
||||
}
|
||||
|
||||
if ("gui".equals(cmdstr, ignoreCase = true)) {
|
||||
sender.sendMessage("§c/ca gui has been moved to /ca config")
|
||||
}
|
||||
|
||||
if (args.isEmpty())
|
||||
processOpen(sender)
|
||||
else when (args[0].lowercase()) {
|
||||
"open" -> processOpen(sender)
|
||||
"enchant" -> processEnchant(sender, args)
|
||||
"item" -> processItem(sender)
|
||||
else -> sender.sendMessage("Unknown subcommand \"${args[0]}\"")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun processEnchant(sender: HumanEntity, args: Array<out String>) {
|
||||
val enchantToFilter: Set<CAEnchantment>
|
||||
if (args.size <= 1) {
|
||||
val item = sender.inventory.itemInMainHand
|
||||
|
||||
enchantToFilter = EnchantmentApi.getEnchantments(item).keys
|
||||
if (enchantToFilter.isEmpty()) {
|
||||
sender.sendMessage("No enchantment found in the item you are holding")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
enchantToFilter = HashSet(EnchantmentApi.getListByName(args[1].lowercase()))
|
||||
|
||||
if (enchantToFilter.isEmpty()) {
|
||||
sender.sendMessage("No enchantment found with the name \"${args[1]}\"")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO open enchantments edit gui
|
||||
|
||||
}
|
||||
|
||||
private fun processItem(sender: HumanEntity) {
|
||||
// TODO open item edit gui
|
||||
}
|
||||
|
||||
private fun processOpen(sender: HumanEntity) {
|
||||
MainConfigGui.getInstance().show(sender)
|
||||
}
|
||||
|
||||
// ---------------
|
||||
// Tab completer
|
||||
// ---------------
|
||||
|
||||
private fun allEnchantmentsByName(): Collection<String> {
|
||||
val names = mutableSetOf<String>()
|
||||
for (enchantment in CAEnchantmentRegistry.getInstance().values()) {
|
||||
names.add(enchantment.name)
|
||||
|
|
@ -59,16 +104,19 @@ class EditConfigExecutor: CASubCommand() {
|
|||
}
|
||||
|
||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||
list.addAll(when (args.size) {
|
||||
list.addAll(
|
||||
when (args.size) {
|
||||
1 -> listOf("item", "enchant", "open")
|
||||
2 -> {
|
||||
when(args[0].lowercase()) {
|
||||
when (args[0].lowercase()) {
|
||||
"enchant" -> allEnchantmentsByName()
|
||||
else -> listOf()
|
||||
}
|
||||
}
|
||||
|
||||
else -> listOf()
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue