diff options
author | Dico <dico.karssiens@gmail.com> | 2018-09-26 09:58:37 +0100 |
---|---|---|
committer | Dico <dico.karssiens@gmail.com> | 2018-09-26 09:58:37 +0100 |
commit | e7dcf7ecc9d448e3a07ef22843ef058d72dcb225 (patch) | |
tree | 6d6a081e8e39265a739094bb2eb013457ebf18e6 /src | |
parent | 520ae530d2de076fa9e87da7f04fcf78e080f4de (diff) |
Tweaks to command permissions
Diffstat (limited to 'src')
3 files changed, 47 insertions, 42 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt index b6c7acd..60518af 100644 --- a/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt +++ b/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt @@ -13,6 +13,7 @@ import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.block.BlockFace import org.bukkit.block.data.Directional +import org.bukkit.command.CommandSender import org.bukkit.entity.Player import java.util.Random @@ -86,7 +87,12 @@ class CommandsDebug(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) { fun cmdForceVisitors(): Any? { val workers = plugin.workDispatcher.workers plugin.workDispatcher.completeAllTasks() - return "Task count: ${workers.size}" + return "Completed task count: ${workers.size}" + } + + @Cmd("hasperm") + fun cmdHasperm(sender: CommandSender, target: Player, permission: String): Any? { + return target.hasPermission(permission).toString() } }
\ No newline at end of file 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 } diff --git a/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt b/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt index 2923173..8ba2d93 100644 --- a/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt +++ b/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt @@ -15,6 +15,7 @@ class ParcelOptionsInteractCommand(val parcelProvider: ParcelProvider) : Command init { addContextFilter(IContextFilter.PLAYER_ONLY) + addContextFilter(IContextFilter.INHERIT_PERMISSIONS) addParameter("allowed", "allowed", ParameterTypes.BOOLEAN) } |