Archived
0

Tweaks to command permissions

This commit is contained in:
Dico
2018-09-26 09:58:37 +01:00
parent 520ae530d2
commit e7dcf7ecc9
7 changed files with 221 additions and 177 deletions

View File

@@ -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()
}
}

View File

@@ -9,54 +9,52 @@ import java.util.LinkedList
import java.util.Queue
@Suppress("UsePropertyAccessSyntax")
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher =
with(CommandBuilder()) {
val parcelsAddress = SpecialCommandAddress()
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))
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(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("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("interact", "i") {
val command = ParcelOptionsInteractCommand(plugin.parcelProvider)
Interactables.classesById.forEach {
addSubCommand(it.name, command)
}
}
group("global", "g") {
registerCommands(CommandsPrivilegesGlobal(plugin))
}
group("admin", "a") {
registerCommands(CommandsAdmin(plugin))
}
if (!logger.isDebugEnabled) return@group
group("debug", "d") {
registerCommands(CommandsDebug(plugin))
}
}
generateHelpAndSyntaxCommands()
getDispatcher()
group("global", "g") {
registerCommands(CommandsPrivilegesGlobal(plugin))
}
group("admin", "a") {
registerCommands(CommandsAdmin(plugin))
}
if (!logger.isDebugEnabled) return@group
group("debug", "d") {
registerCommands(CommandsDebug(plugin))
}
}
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
}

View File

@@ -15,6 +15,7 @@ class ParcelOptionsInteractCommand(val parcelProvider: ParcelProvider) : Command
init {
addContextFilter(IContextFilter.PLAYER_ONLY)
addContextFilter(IContextFilter.INHERIT_PERMISSIONS)
addParameter("allowed", "allowed", ParameterTypes.BOOLEAN)
}