summaryrefslogtreecommitdiff
path: root/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt')
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt80
1 files changed, 39 insertions, 41 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt b/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt
index 1f1e4a7..7be112d 100644
--- a/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt
@@ -9,54 +9,52 @@ import java.util.LinkedList
import java.util.Queue
@Suppress("UsePropertyAccessSyntax")
-fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher =
- with(CommandBuilder()) {
- val parcelsAddress = SpecialCommandAddress()
-
- setChatController(ParcelsChatController())
- addParameterType(false, ParcelParameterType(plugin.parcelProvider))
- addParameterType(false, ProfileParameterType())
- addParameterType(true, ParcelTarget.PType(plugin.parcelProvider, parcelsAddress))
-
- group(parcelsAddress, "parcel", "plot", "plots", "p") {
- addRequiredPermission("parcels.command")
- registerCommands(CommandsGeneral(plugin, parcelsAddress))
- registerCommands(CommandsPrivilegesLocal(plugin))
-
- group("option", "opt", "o") {
- setGroupDescription(
- "changes interaction options for this parcel",
- "Sets whether players who are not allowed to",
- "build here can interact with certain things."
- )
-
- group("interact", "i") {
- val command = ParcelOptionsInteractCommand(plugin.parcelProvider)
- Interactables.classesById.forEach {
- addSubCommand(it.name, command)
- }
+fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher = CommandBuilder().apply {
+ val parcelsAddress = SpecialCommandAddress()
+
+ setChatController(ParcelsChatController())
+ addParameterType(false, ParcelParameterType(plugin.parcelProvider))
+ addParameterType(false, ProfileParameterType())
+ addParameterType(true, ParcelTarget.PType(plugin.parcelProvider, parcelsAddress))
+
+ group(parcelsAddress, "parcel", "plot", "plots", "p") {
+ addContextFilter(IContextFilter.inheritablePermission("parcels.command"))
+ registerCommands(CommandsGeneral(plugin, parcelsAddress))
+ registerCommands(CommandsPrivilegesLocal(plugin))
+
+ group("option", "opt", "o") {
+ setGroupDescription(
+ "changes interaction options for this parcel",
+ "Sets whether players who are not allowed to",
+ "build here can interact with certain things."
+ )
+
+ group("interact", "i") {
+ val command = ParcelOptionsInteractCommand(plugin.parcelProvider)
+ Interactables.classesById.forEach {
+ addSubCommand(it.name, command)
}
}
+ }
- group("global", "g") {
- registerCommands(CommandsPrivilegesGlobal(plugin))
- }
+ group("global", "g") {
+ registerCommands(CommandsPrivilegesGlobal(plugin))
+ }
- group("admin", "a") {
- registerCommands(CommandsAdmin(plugin))
- }
+ group("admin", "a") {
+ registerCommands(CommandsAdmin(plugin))
+ }
- if (!logger.isDebugEnabled) return@group
+ if (!logger.isDebugEnabled) return@group
- group("debug", "d") {
- registerCommands(CommandsDebug(plugin))
- }
+ group("debug", "d") {
+ registerCommands(CommandsDebug(plugin))
}
-
- generateHelpAndSyntaxCommands()
- getDispatcher()
}
+ generateHelpAndSyntaxCommands(parcelsAddress)
+}.getDispatcher()
+
inline fun CommandBuilder.group(name: String, vararg aliases: String, config: CommandBuilder.() -> Unit) {
group(name, *aliases)
config()
@@ -69,8 +67,8 @@ inline fun CommandBuilder.group(address: ICommandAddress, name: String, vararg a
parent()
}
-private fun CommandBuilder.generateHelpAndSyntaxCommands(): CommandBuilder {
- generateCommands(dispatcher as ICommandAddress, "help", "syntax")
+private fun CommandBuilder.generateHelpAndSyntaxCommands(root: ICommandAddress): CommandBuilder {
+ generateCommands(root, "help", "syntax")
return this
}