Add permission info
This commit is contained in:
@@ -76,7 +76,7 @@ public class RootCommandAddress extends ModifiableCommandAddress implements ICom
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void debugChildren(ModifiableCommandAddress address) {
|
public static void debugChildren(ModifiableCommandAddress address) {
|
||||||
Collection<String> keys = address.getChildrenMainKeys();
|
Collection<String> keys = address.getChildrenMainKeys();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
ChildCommandAddress child = address.getChild(key);
|
ChildCommandAddress child = address.getChild(key);
|
||||||
|
|||||||
71
permissions.md
Normal file
71
permissions.md
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# Permission Nodes
|
||||||
|
|
||||||
|
Node|Description
|
||||||
|
---|---
|
||||||
|
parcels.command.home | Access to `/p home` and aliases (example 1)
|
||||||
|
parcels.command.option.interact.gates | Access to `/p option interact gates` and aliases (example 2)
|
||||||
|
parcels.admin.bypass.ban | Ability to enter plots that listed a player as banned
|
||||||
|
parcels.admin.bypass.build | Ability to build anywhere
|
||||||
|
parcels.admin.bypass.gamemode | Be exempt from the world-specific gamemode enforcement
|
||||||
|
parcels.command.home.others | Ability to use `/p home` for plots other than your own
|
||||||
|
parcels.admin.manage | Admin rights. Required for staff commands and operations.
|
||||||
|
|
||||||
|
## All Commands
|
||||||
|
|
||||||
|
* parcel
|
||||||
|
* parcel goto
|
||||||
|
* parcel clear
|
||||||
|
* parcel goto_fake
|
||||||
|
* parcel claim
|
||||||
|
* parcel auto
|
||||||
|
* parcel tp
|
||||||
|
* parcel home
|
||||||
|
* parcel info
|
||||||
|
* parcel setbiome
|
||||||
|
* parcel ban
|
||||||
|
* parcel disallow
|
||||||
|
* parcel distrust
|
||||||
|
* parcel allow
|
||||||
|
* parcel unban
|
||||||
|
* parcel entrust
|
||||||
|
* parcel option
|
||||||
|
* parcel option interact
|
||||||
|
* parcel option interact buttons
|
||||||
|
* parcel option interact levers
|
||||||
|
* parcel option interact pressure_plates
|
||||||
|
* parcel option interact redstone
|
||||||
|
* parcel option interact containers
|
||||||
|
* parcel option interact gates
|
||||||
|
* parcel global
|
||||||
|
* parcel global ban
|
||||||
|
* parcel global disallow
|
||||||
|
* parcel global distrust
|
||||||
|
* parcel global allow
|
||||||
|
* parcel global unban
|
||||||
|
* parcel global entrust
|
||||||
|
* parcel global list
|
||||||
|
* parcel admin
|
||||||
|
* parcel admin swap
|
||||||
|
* parcel admin reset
|
||||||
|
* parcel admin setowner
|
||||||
|
* parcel admin dispose
|
||||||
|
* parcel admin update_all_owner_signs
|
||||||
|
* parcel admin global
|
||||||
|
* parcel admin global ban
|
||||||
|
* parcel admin global disallow
|
||||||
|
* parcel admin global distrust
|
||||||
|
* parcel admin global allow
|
||||||
|
* parcel admin global unban
|
||||||
|
* parcel admin global entrust
|
||||||
|
* parcel admin global list
|
||||||
|
* parcel debug
|
||||||
|
* parcel debug permissions
|
||||||
|
* parcel debug reloadoptions
|
||||||
|
* parcel debug privilege
|
||||||
|
* parcel debug complete_jobs
|
||||||
|
* parcel debug jobs
|
||||||
|
* parcel debug tpworld
|
||||||
|
* parcel debug make_mess
|
||||||
|
* parcel debug hasperm
|
||||||
|
* parcel debug message
|
||||||
|
* parcel debug directionality
|
||||||
@@ -1,137 +1,139 @@
|
|||||||
package io.dico.parcels2.command
|
package io.dico.parcels2.command
|
||||||
|
|
||||||
import io.dico.dicore.command.*
|
import io.dico.dicore.command.*
|
||||||
import io.dico.dicore.command.parameter.ArgumentBuffer
|
import io.dico.dicore.command.parameter.ArgumentBuffer
|
||||||
import io.dico.dicore.command.predef.DefaultGroupCommand
|
import io.dico.dicore.command.predef.DefaultGroupCommand
|
||||||
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
|
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
|
||||||
import io.dico.parcels2.Interactables
|
import io.dico.parcels2.Interactables
|
||||||
import io.dico.parcels2.ParcelsPlugin
|
import io.dico.parcels2.ParcelsPlugin
|
||||||
import io.dico.parcels2.logger
|
import io.dico.parcels2.logger
|
||||||
import io.dico.parcels2.util.ext.hasPermAdminManage
|
import io.dico.parcels2.util.ext.hasPermAdminManage
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.Queue
|
import java.util.Queue
|
||||||
|
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher = CommandBuilder().apply {
|
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher = CommandBuilder().apply {
|
||||||
val parcelsAddress = SpecialCommandAddress()
|
val parcelsAddress = SpecialCommandAddress()
|
||||||
|
|
||||||
setChatHandler(ParcelsChatHandler())
|
setChatHandler(ParcelsChatHandler())
|
||||||
addParameterType(false, ParcelParameterType(plugin.parcelProvider))
|
addParameterType(false, ParcelParameterType(plugin.parcelProvider))
|
||||||
addParameterType(false, ProfileParameterType())
|
addParameterType(false, ProfileParameterType())
|
||||||
addParameterType(true, ParcelTarget.PType(plugin.parcelProvider, parcelsAddress))
|
addParameterType(true, ParcelTarget.PType(plugin.parcelProvider, parcelsAddress))
|
||||||
|
|
||||||
group(parcelsAddress, "parcel", "plot", "plots", "p") {
|
group(parcelsAddress, "parcel", "plot", "plots", "p") {
|
||||||
addContextFilter(IContextFilter.inheritablePermission("parcels.command"))
|
addContextFilter(IContextFilter.inheritablePermission("parcels.command"))
|
||||||
registerCommands(CommandsGeneral(plugin, parcelsAddress))
|
registerCommands(CommandsGeneral(plugin, parcelsAddress))
|
||||||
registerCommands(CommandsPrivilegesLocal(plugin))
|
registerCommands(CommandsPrivilegesLocal(plugin))
|
||||||
|
|
||||||
group("option", "opt", "o") {
|
group("option", "opt", "o") {
|
||||||
setGroupDescription(
|
setGroupDescription(
|
||||||
"changes interaction options for this parcel",
|
"changes interaction options for this parcel",
|
||||||
"Sets whether players who are not allowed to",
|
"Sets whether players who are not allowed to",
|
||||||
"build here can interact with certain things."
|
"build here can interact with certain things."
|
||||||
)
|
)
|
||||||
|
|
||||||
group("interact", "i") {
|
group("interact", "i") {
|
||||||
val command = ParcelOptionsInteractCommand(plugin)
|
val command = ParcelOptionsInteractCommand(plugin)
|
||||||
Interactables.classesById.forEach {
|
Interactables.classesById.forEach {
|
||||||
addSubCommand(it.name, command)
|
addSubCommand(it.name, command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val adminPrivilegesGlobal = CommandsAdminPrivilegesGlobal(plugin)
|
val adminPrivilegesGlobal = CommandsAdminPrivilegesGlobal(plugin)
|
||||||
|
|
||||||
group("global", "g") {
|
group("global", "g") {
|
||||||
registerCommands(CommandsPrivilegesGlobal(plugin, adminVersion = adminPrivilegesGlobal))
|
registerCommands(CommandsPrivilegesGlobal(plugin, adminVersion = adminPrivilegesGlobal))
|
||||||
}
|
}
|
||||||
|
|
||||||
group("admin", "a") {
|
group("admin", "a") {
|
||||||
setCommand(AdminGroupCommand())
|
setCommand(AdminGroupCommand())
|
||||||
registerCommands(CommandsAdmin(plugin))
|
registerCommands(CommandsAdmin(plugin))
|
||||||
|
|
||||||
group("global", "g") {
|
group("global", "g") {
|
||||||
registerCommands(adminPrivilegesGlobal)
|
registerCommands(adminPrivilegesGlobal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!logger.isDebugEnabled) return@group
|
if (!logger.isDebugEnabled) return@group
|
||||||
|
|
||||||
group("debug", "d") {
|
group("debug", "d") {
|
||||||
registerCommands(CommandsDebug(plugin))
|
registerCommands(CommandsDebug(plugin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateHelpAndSyntaxCommands(parcelsAddress)
|
generateHelpAndSyntaxCommands(parcelsAddress)
|
||||||
}.getDispatcher()
|
}.getDispatcher().also {
|
||||||
|
RootCommandAddress.debugChildren(it as ModifiableCommandAddress)
|
||||||
private inline fun CommandBuilder.group(name: String, vararg aliases: String, config: CommandBuilder.() -> Unit) {
|
}
|
||||||
group(name, *aliases)
|
|
||||||
config()
|
private inline fun CommandBuilder.group(name: String, vararg aliases: String, config: CommandBuilder.() -> Unit) {
|
||||||
parent()
|
group(name, *aliases)
|
||||||
}
|
config()
|
||||||
|
parent()
|
||||||
private inline fun CommandBuilder.group(address: ICommandAddress, name: String, vararg aliases: String, config: CommandBuilder.() -> Unit) {
|
}
|
||||||
group(address, name, *aliases)
|
|
||||||
config()
|
private inline fun CommandBuilder.group(address: ICommandAddress, name: String, vararg aliases: String, config: CommandBuilder.() -> Unit) {
|
||||||
parent()
|
group(address, name, *aliases)
|
||||||
}
|
config()
|
||||||
|
parent()
|
||||||
private fun CommandBuilder.generateHelpAndSyntaxCommands(root: ICommandAddress): CommandBuilder {
|
}
|
||||||
generateCommands(root, "help", "syntax")
|
|
||||||
return this
|
private fun CommandBuilder.generateHelpAndSyntaxCommands(root: ICommandAddress): CommandBuilder {
|
||||||
}
|
generateCommands(root, "help", "syntax")
|
||||||
|
return this
|
||||||
private fun generateCommands(address: ICommandAddress, vararg names: String) {
|
}
|
||||||
val addresses: Queue<ICommandAddress> = LinkedList()
|
|
||||||
addresses.offer(address)
|
private fun generateCommands(address: ICommandAddress, vararg names: String) {
|
||||||
|
val addresses: Queue<ICommandAddress> = LinkedList()
|
||||||
while (addresses.isNotEmpty()) {
|
addresses.offer(address)
|
||||||
val cur = addresses.poll()
|
|
||||||
cur.childrenMainKeys.mapTo(addresses) { cur.getChild(it) }
|
while (addresses.isNotEmpty()) {
|
||||||
if (cur.hasCommand()) {
|
val cur = addresses.poll()
|
||||||
ReflectiveRegistration.generateCommands(cur, names)
|
cur.childrenMainKeys.mapTo(addresses) { cur.getChild(it) }
|
||||||
}
|
if (cur.hasCommand()) {
|
||||||
}
|
ReflectiveRegistration.generateCommands(cur, names)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
class SpecialCommandAddress : ChildCommandAddress() {
|
}
|
||||||
private val speciallyTreatedKeys = mutableListOf<String>()
|
|
||||||
|
class SpecialCommandAddress : ChildCommandAddress() {
|
||||||
// Used to allow /p h:1 syntax, which is the same as what PlotMe uses.
|
private val speciallyTreatedKeys = mutableListOf<String>()
|
||||||
var speciallyParsedIndex: Int? = null; private set
|
|
||||||
|
// Used to allow /p h:1 syntax, which is the same as what PlotMe uses.
|
||||||
fun addSpeciallyTreatedKeys(vararg keys: String) {
|
var speciallyParsedIndex: Int? = null; private set
|
||||||
for (key in keys) {
|
|
||||||
speciallyTreatedKeys.add(key + ":")
|
fun addSpeciallyTreatedKeys(vararg keys: String) {
|
||||||
}
|
for (key in keys) {
|
||||||
}
|
speciallyTreatedKeys.add(key + ":")
|
||||||
|
}
|
||||||
// h:1
|
}
|
||||||
@Throws(CommandException::class)
|
|
||||||
override fun getChild(context: ExecutionContext, buffer: ArgumentBuffer): ChildCommandAddress? {
|
// h:1
|
||||||
speciallyParsedIndex = null
|
@Throws(CommandException::class)
|
||||||
|
override fun getChild(context: ExecutionContext, buffer: ArgumentBuffer): ChildCommandAddress? {
|
||||||
val key = buffer.next() ?: return null
|
speciallyParsedIndex = null
|
||||||
for (specialKey in speciallyTreatedKeys) {
|
|
||||||
if (key.startsWith(specialKey)) {
|
val key = buffer.next() ?: return null
|
||||||
val result = getChild(specialKey.substring(0, specialKey.length - 1))
|
for (specialKey in speciallyTreatedKeys) {
|
||||||
?: return null
|
if (key.startsWith(specialKey)) {
|
||||||
|
val result = getChild(specialKey.substring(0, specialKey.length - 1))
|
||||||
val text = key.substring(specialKey.length)
|
?: return null
|
||||||
val num = text.toIntOrNull() ?: throw CommandException("$text is not a number")
|
|
||||||
speciallyParsedIndex = num
|
val text = key.substring(specialKey.length)
|
||||||
|
val num = text.toIntOrNull() ?: throw CommandException("$text is not a number")
|
||||||
return result
|
speciallyParsedIndex = num
|
||||||
}
|
|
||||||
}
|
return result
|
||||||
|
}
|
||||||
return super.getChild(key)
|
}
|
||||||
}
|
|
||||||
|
return super.getChild(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AdminGroupCommand : DefaultGroupCommand() {
|
}
|
||||||
override fun isVisibleTo(sender: CommandSender) = sender.hasPermAdminManage
|
|
||||||
}
|
private class AdminGroupCommand : DefaultGroupCommand() {
|
||||||
|
override fun isVisibleTo(sender: CommandSender) = sender.hasPermAdminManage
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user