mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Help Command
This commit is contained in:
parent
bc7ed5af85
commit
0440835013
7 changed files with 58 additions and 5 deletions
|
|
@ -6,7 +6,7 @@ import org.bukkit.configuration.file.YamlConfiguration
|
|||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
||||
import xyz.alexcrea.cuanvil.api.event.CAEnchantRegistryReadyEvent
|
||||
import xyz.alexcrea.cuanvil.command.CustomAnvilCmd
|
||||
import xyz.alexcrea.cuanvil.command.CustomAnvilCommand
|
||||
import xyz.alexcrea.cuanvil.command.EditConfigExecutor
|
||||
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
|
|
@ -309,7 +309,7 @@ open class CustomAnvil : JavaPlugin() {
|
|||
command = getCommand(commandConfigName)
|
||||
command?.setExecutor(EditConfigExecutor())
|
||||
|
||||
CustomAnvilCmd(this)
|
||||
CustomAnvilCommand(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,8 @@ abstract class CASubCommand: CommandExecutor {
|
|||
list: MutableList<String>) {
|
||||
}
|
||||
|
||||
open fun description(): String {
|
||||
return "no description"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import org.bukkit.command.TabCompleter
|
|||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
import java.util.ArrayList
|
||||
|
||||
class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||
|
||||
// Name of the generic command
|
||||
companion object {
|
||||
|
|
@ -17,16 +17,20 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
|||
}
|
||||
|
||||
private val editConfigCommand = EditConfigExecutor()
|
||||
private val helpCommand = HelpExecutor()
|
||||
private val commands = ImmutableMap.of(
|
||||
"gui", editConfigCommand,
|
||||
"reload", ReloadExecutor(),
|
||||
"diagnostic", DiagnosticExecutor(),
|
||||
"help", helpCommand,
|
||||
)
|
||||
|
||||
init {
|
||||
val self = plugin.getCommand(genericCommandName)!!
|
||||
self.setExecutor(this)
|
||||
self.tabCompleter = this
|
||||
|
||||
helpCommand.commands = commands
|
||||
}
|
||||
|
||||
override fun onCommand(
|
||||
|
|
@ -68,8 +72,9 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
|||
): MutableList<String> {
|
||||
val result = ArrayList<String>()
|
||||
if(args.size < 2) {
|
||||
for (cmd in commands) {
|
||||
result.add(cmd.key)
|
||||
for ((key, cmd) in commands) {
|
||||
if(!cmd.allowed(sender)) continue
|
||||
result.add(key)
|
||||
}
|
||||
} else {
|
||||
val subcmd = commands[args[0].lowercase()]
|
||||
|
|
@ -204,6 +204,10 @@ class DiagnosticExecutor: CASubCommand() {
|
|||
return this.name + " v" + this.description.version
|
||||
}
|
||||
|
||||
override fun description(): String {
|
||||
return "Basic diagnostic of this plugin"
|
||||
}
|
||||
|
||||
private fun pluginListDiag(sender: CommandSender, stb: StringBuilder) {
|
||||
val enabledPlugins: MutableList<Plugin?> = ArrayList<Plugin?>()
|
||||
val disabledPlugins: MutableList<Plugin?> = ArrayList<Plugin?>()
|
||||
|
|
|
|||
|
|
@ -38,4 +38,8 @@ class EditConfigExecutor: CASubCommand() {
|
|||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||
}
|
||||
|
||||
override fun description(): String {
|
||||
return "Gui to edit the plugin's config"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
32
src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt
Normal file
32
src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package xyz.alexcrea.cuanvil.command
|
||||
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class HelpExecutor: CASubCommand() {
|
||||
|
||||
lateinit var commands: ImmutableMap<String, CASubCommand>
|
||||
|
||||
override fun executeCommand(sender: CommandSender,
|
||||
cmd: Command,
|
||||
cmdstr: String,
|
||||
args: Array<out String>): Boolean {
|
||||
|
||||
val stb = StringBuilder("List of available commands:")
|
||||
for ((key, cmd) in commands) {
|
||||
if(!cmd.allowed(sender)) continue
|
||||
|
||||
stb.append("\n- $key: ").append(cmd.description())
|
||||
}
|
||||
|
||||
sender.sendMessage(stb.toString())
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun description(): String {
|
||||
return "Help command"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -39,6 +39,10 @@ class ReloadExecutor : CASubCommand() {
|
|||
return sender.hasPermission(CustomAnvil.commandReloadPermission)
|
||||
}
|
||||
|
||||
override fun description(): String {
|
||||
return "Reload the configuration of this plugin"
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command, return true if success or false otherwise
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue