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
1d59f033b8
commit
4942f3c0d2
1 changed files with 69 additions and 21 deletions
|
|
@ -1,28 +1,39 @@
|
||||||
package xyz.alexcrea.cuanvil.command
|
package xyz.alexcrea.cuanvil.command
|
||||||
|
|
||||||
import com.willfp.eco.core.lookup.matches
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||||
|
|
||||||
class EditConfigExecutor: CASubCommand() {
|
class EditConfigExecutor : CASubCommand() {
|
||||||
|
|
||||||
override fun executeCommand(sender: CommandSender,
|
override fun allowed(sender: CommandSender): Boolean {
|
||||||
cmd: Command,
|
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||||
cmdstr: String,
|
}
|
||||||
args: Array<out String>): Boolean {
|
|
||||||
|
override fun description(): String {
|
||||||
|
return "Gui to edit the plugin's config"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun executeCommand(
|
||||||
|
sender: CommandSender,
|
||||||
|
cmd: Command,
|
||||||
|
cmdstr: String,
|
||||||
|
args: Array<out String>
|
||||||
|
): Boolean {
|
||||||
if (sender !is HumanEntity) return false
|
if (sender !is HumanEntity) return false
|
||||||
|
|
||||||
if (!allowed(sender)) {
|
if (!allowed(sender)) {
|
||||||
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(PlatformUtil.isFolia){
|
if (PlatformUtil.isFolia) {
|
||||||
sender.sendMessage("§cIt look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia.")
|
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("§eIt is may come in a future version.")
|
||||||
sender.sendMessage("")
|
sender.sendMessage("")
|
||||||
|
|
@ -35,20 +46,54 @@ class EditConfigExecutor: CASubCommand() {
|
||||||
sender.sendMessage("§c/ca gui has been moved to /ca config")
|
sender.sendMessage("§c/ca gui has been moved to /ca config")
|
||||||
}
|
}
|
||||||
|
|
||||||
MainConfigGui.getInstance().show(sender)
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun allowed(sender: CommandSender): Boolean {
|
private fun processEnchant(sender: HumanEntity, args: Array<out String>) {
|
||||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
private fun processItem(sender: HumanEntity) {
|
||||||
return "Gui to edit the plugin's config"
|
// TODO open item edit gui
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun allEnchantmentsByName(): Collection<String>{
|
private fun processOpen(sender: HumanEntity) {
|
||||||
|
MainConfigGui.getInstance().show(sender)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------
|
||||||
|
// Tab completer
|
||||||
|
// ---------------
|
||||||
|
|
||||||
|
private fun allEnchantmentsByName(): Collection<String> {
|
||||||
val names = mutableSetOf<String>()
|
val names = mutableSetOf<String>()
|
||||||
for (enchantment in CAEnchantmentRegistry.getInstance().values()) {
|
for (enchantment in CAEnchantmentRegistry.getInstance().values()) {
|
||||||
names.add(enchantment.name)
|
names.add(enchantment.name)
|
||||||
|
|
@ -59,16 +104,19 @@ class EditConfigExecutor: CASubCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||||
list.addAll(when (args.size) {
|
list.addAll(
|
||||||
1 -> listOf("item", "enchant", "open")
|
when (args.size) {
|
||||||
2 -> {
|
1 -> listOf("item", "enchant", "open")
|
||||||
when(args[0].lowercase()) {
|
2 -> {
|
||||||
"enchant" -> allEnchantmentsByName()
|
when (args[0].lowercase()) {
|
||||||
else -> listOf()
|
"enchant" -> allEnchantmentsByName()
|
||||||
|
else -> listOf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else -> listOf()
|
||||||
}
|
}
|
||||||
else -> listOf()
|
)
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue