summaryrefslogtreecommitdiff
path: root/src/main/kotlin/io/dico/parcels2/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/command')
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/AbstractParcelCommands.kt4
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusLocal.kt56
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsAdmin.kt10
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt9
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt10
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsParcelOptions.kt61
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt (renamed from src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusGlobal.kt)66
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesLocal.kt90
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt19
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/ParcelCommandReceivers.kt41
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt36
-rw-r--r--src/main/kotlin/io/dico/parcels2/command/ParcelTarget.kt16
12 files changed, 242 insertions, 176 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/command/AbstractParcelCommands.kt b/src/main/kotlin/io/dico/parcels2/command/AbstractParcelCommands.kt
index 2339309..0c0b47f 100644
--- a/src/main/kotlin/io/dico/parcels2/command/AbstractParcelCommands.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/AbstractParcelCommands.kt
@@ -4,7 +4,7 @@ import io.dico.dicore.command.*
import io.dico.parcels2.ParcelWorld
import io.dico.parcels2.ParcelsPlugin
import io.dico.parcels2.PlayerProfile
-import io.dico.parcels2.util.ext.hasAdminManage
+import io.dico.parcels2.util.ext.hasPermAdminManage
import io.dico.parcels2.util.ext.parcelLimit
import org.bukkit.entity.Player
import org.bukkit.plugin.Plugin
@@ -26,7 +26,7 @@ abstract class AbstractParcelCommands(val plugin: ParcelsPlugin) : ICommandRecei
}
protected suspend fun checkParcelLimit(player: Player, world: ParcelWorld) {
- if (player.hasAdminManage) return
+ if (player.hasPermAdminManage) return
val numOwnedParcels = plugin.storage.getOwnedParcels(PlayerProfile(player)).await()
.filter { it.worldId.equals(world.id) }.size
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusLocal.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusLocal.kt
deleted file mode 100644
index 223e504..0000000
--- a/src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusLocal.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-package io.dico.parcels2.command
-
-import io.dico.dicore.command.Validate
-import io.dico.dicore.command.annotation.Cmd
-import io.dico.dicore.command.annotation.Desc
-import io.dico.parcels2.ParcelsPlugin
-import io.dico.parcels2.util.ext.hasAdminManage
-import org.bukkit.OfflinePlayer
-import org.bukkit.entity.Player
-
-class CommandsAddedStatusLocal(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
-
- @Cmd("allow", aliases = ["add", "permit"])
- @Desc("Allows a player to build on this parcel",
- shortVersion = "allows a player to build on this parcel")
- @ParcelRequire(owner = true)
- fun ParcelScope.cmdAllow(sender: Player, player: OfflinePlayer): Any? {
- Validate.isTrue(parcel.owner != null || sender.hasAdminManage, "This parcel is unowned")
- Validate.isTrue(!parcel.owner!!.matches(player), "The target already owns the parcel")
- Validate.isTrue(parcel.allow(player), "${player.name} is already allowed to build on this parcel")
- return "${player.name} is now allowed to build on this parcel"
- }
-
- @Cmd("disallow", aliases = ["remove", "forbid"])
- @Desc("Disallows a player to build on this parcel,",
- "they won't be allowed to anymore",
- shortVersion = "disallows a player to build on this parcel")
- @ParcelRequire(owner = true)
- fun ParcelScope.cmdDisallow(sender: Player, player: OfflinePlayer): Any? {
- Validate.isTrue(parcel.disallow(player), "${player.name} is not currently allowed to build on this parcel")
- return "${player.name} is not allowed to build on this parcel anymore"
- }
-
- @Cmd("ban", aliases = ["deny"])
- @Desc("Bans a player from this parcel,",
- "making them unable to enter",
- shortVersion = "bans a player from this parcel")
- @ParcelRequire(owner = true)
- fun ParcelScope.cmdBan(sender: Player, player: OfflinePlayer): Any? {
- Validate.isTrue(parcel.owner != null || sender.hasAdminManage, "This parcel is unowned")
- Validate.isTrue(!parcel.owner!!.matches(player), "The owner cannot be banned from the parcel")
- Validate.isTrue(parcel.ban(player), "${player.name} is already banned from this parcel")
- return "${player.name} is now banned from this parcel"
- }
-
- @Cmd("unban", aliases = ["undeny"])
- @Desc("Unbans a player from this parcel,",
- "they will be able to enter it again",
- shortVersion = "unbans a player from this parcel")
- @ParcelRequire(owner = true)
- fun ParcelScope.cmdUnban(sender: Player, player: OfflinePlayer): Any? {
- Validate.isTrue(parcel.unban(player), "${player.name} is not currently banned from this parcel")
- return "${player.name} is not banned from this parcel anymore"
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsAdmin.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsAdmin.kt
index 35ede71..0b155f2 100644
--- a/src/main/kotlin/io/dico/parcels2/command/CommandsAdmin.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/CommandsAdmin.kt
@@ -5,11 +5,12 @@ import io.dico.dicore.command.annotation.Cmd
import io.dico.dicore.command.annotation.Flag
import io.dico.parcels2.ParcelsPlugin
import io.dico.parcels2.PlayerProfile
+import io.dico.parcels2.Privilege
class CommandsAdmin(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
@Cmd("setowner")
- @ParcelRequire(admin = true)
+ @RequireParcelPrivilege(Privilege.ADMIN)
fun ParcelScope.cmdSetowner(target: PlayerProfile): Any? {
parcel.owner = target
@@ -18,14 +19,14 @@ class CommandsAdmin(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
}
@Cmd("dispose")
- @ParcelRequire(admin = true)
+ @RequireParcelPrivilege(Privilege.ADMIN)
fun ParcelScope.cmdDispose(): Any? {
parcel.dispose()
return "Data of (${parcel.id.idString}) has been disposed"
}
@Cmd("reset")
- @ParcelRequire(admin = true)
+ @RequireParcelPrivilege(Privilege.ADMIN)
fun ParcelScope.cmdReset(context: ExecutionContext, @Flag sure: Boolean): Any? {
if (!sure) return areYouSureMessage(context)
parcel.dispose()
@@ -34,9 +35,10 @@ class CommandsAdmin(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
}
@Cmd("swap")
+ @RequireParcelPrivilege(Privilege.ADMIN)
fun ParcelScope.cmdSwap(context: ExecutionContext, @Flag sure: Boolean): Any? {
if (!sure) return areYouSureMessage(context)
- TODO()
+ TODO("implement swap")
}
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt
index 3ae17f2..b646450 100644
--- a/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/CommandsDebug.kt
@@ -5,6 +5,7 @@ import io.dico.dicore.command.EMessageType
import io.dico.dicore.command.ExecutionContext
import io.dico.dicore.command.annotation.Cmd
import io.dico.parcels2.ParcelsPlugin
+import io.dico.parcels2.Privilege
import io.dico.parcels2.blockvisitor.RegionTraverser
import io.dico.parcels2.doBlockOperation
import org.bukkit.Bukkit
@@ -30,7 +31,7 @@ class CommandsDebug(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
}
@Cmd("make_mess")
- @ParcelRequire(owner = true)
+ @RequireParcelPrivilege(Privilege.OWNER)
fun ParcelScope.cmdMakeMess(context: ExecutionContext) {
val server = plugin.server
val blockDatas = arrayOf(
@@ -47,8 +48,10 @@ class CommandsDebug(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
world.blockManager.doBlockOperation(parcel.id, traverser = RegionTraverser.upward) { block ->
block.blockData = blockDatas[random.nextInt(7)]
}.onProgressUpdate(1000, 1000) { progress, elapsedTime ->
- context.sendMessage(EMessageType.INFORMATIVE, "Mess progress: %.02f%%, %.2fs elapsed"
- .format(progress * 100, elapsedTime / 1000.0))
+ context.sendMessage(
+ EMessageType.INFORMATIVE, "Mess progress: %.02f%%, %.2fs elapsed"
+ .format(progress * 100, elapsedTime / 1000.0)
+ )
}
}
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt
index eef07fd..33825fb 100644
--- a/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt
@@ -9,8 +9,8 @@ import io.dico.dicore.command.annotation.RequireParameters
import io.dico.parcels2.ParcelsPlugin
import io.dico.parcels2.PlayerProfile
import io.dico.parcels2.command.ParcelTarget.Kind
-import io.dico.parcels2.util.ext.hasAdminManage
import io.dico.parcels2.util.ext.hasParcelHomeOthers
+import io.dico.parcels2.util.ext.hasPermAdminManage
import io.dico.parcels2.util.ext.uuid
import org.bukkit.block.Biome
import org.bukkit.entity.Player
@@ -99,7 +99,7 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
)
suspend fun ParcelScope.cmdClaim(player: Player): Any? {
checkConnected("be claimed")
- parcel.owner.takeIf { !player.hasAdminManage }?.let {
+ parcel.owner.takeIf { !player.hasPermAdminManage }?.let {
error(if (it.matches(player)) "You already own this parcel" else "This parcel is not available")
}
@@ -110,14 +110,14 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
@Cmd("unclaim")
@Desc("Unclaims this parcel")
- @ParcelRequire(owner = true)
+ @RequireParcelPrivilege(Privilege.OWNER)
fun ParcelScope.cmdUnclaim(player: Player): Any? {
parcel.dispose()
return "Your parcel has been disposed"
}
@Cmd("clear")
- @ParcelRequire(owner = true)
+ @RequireParcelPrivilege(Privilege.OWNER)
fun ParcelScope.cmdClear(context: ExecutionContext, @Flag sure: Boolean): Any? {
if (!sure) return areYouSureMessage(context)
@@ -126,7 +126,7 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
}
@Cmd("setbiome")
- @ParcelRequire(owner = true)
+ @RequireParcelPrivilege(Privilege.OWNER)
fun ParcelScope.cmdSetbiome(context: ExecutionContext, biome: Biome): Any? {
Validate.isTrue(!parcel.hasBlockVisitors, "A process is already running in this parcel")
world.blockManager.setBiome(parcel.id, biome)
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsParcelOptions.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsParcelOptions.kt
deleted file mode 100644
index b46e972..0000000
--- a/src/main/kotlin/io/dico/parcels2/command/CommandsParcelOptions.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-package io.dico.parcels2.command
-
-import io.dico.dicore.command.CommandBuilder
-import io.dico.dicore.command.Validate
-import io.dico.dicore.command.annotation.Cmd
-import io.dico.dicore.command.annotation.Desc
-import io.dico.dicore.command.annotation.RequireParameters
-import io.dico.parcels2.Parcel
-import io.dico.parcels2.ParcelsPlugin
-import org.bukkit.entity.Player
-import kotlin.reflect.KMutableProperty
-
-class CommandsParcelOptions(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
- /* TODO options
- @Cmd("inputs")
- @Desc("Sets whether players who are not allowed to",
- "build here can use levers, buttons,",
- "pressure plates, tripwire or redstone ore",
- shortVersion = "allows using inputs")
- @RequireParameters(0)
- fun ParcelScope.cmdInputs(player: Player, enabled: Boolean?): Any? {
- return runOptionCommand(player, Parcel::allowInteractInputs, enabled, "using levers, buttons, etc.")
- }
-
- @Cmd("inventory")
- @Desc("Sets whether players who are not allowed to",
- "build here can interact with inventories",
- shortVersion = "allows editing inventories")
- @RequireParameters(0)
- fun ParcelScope.cmdInventory(player: Player, enabled: Boolean?): Any? {
- return runOptionCommand(player, Parcel::allowInteractInventory, enabled, "interaction with inventories")
- }*/
-
- private inline val Boolean.enabledWord get() = if (this) "enabled" else "disabled"
- private fun ParcelScope.runOptionCommand(player: Player,
- property: KMutableProperty<Boolean>,
- enabled: Boolean?,
- desc: String): Any? {
- checkConnected("have their options changed")
- val current = property.getter.call(parcel)
- if (enabled == null) {
- val word = if (current) "" else "not "
- return "This parcel does ${word}allow $desc"
- }
-
- checkCanManage(player, "change its options")
- Validate.isTrue(current != enabled, "That option was already ${enabled.enabledWord}")
- property.setter.call(parcel, enabled)
- return "That option is now ${enabled.enabledWord}"
- }
-
- companion object {
- private const val descShort = "changes interaction options for this parcel"
- private val desc = arrayOf("Sets whether players who are not allowed to", "build here can interact with certain things.")
-
- fun setGroupDescription(builder: CommandBuilder) {
- builder.setGroupDescription(descShort, *desc)
- }
- }
-
-} \ No newline at end of file
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusGlobal.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt
index eae6da2..91b8272 100644
--- a/src/main/kotlin/io/dico/parcels2/command/CommandsAddedStatusGlobal.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt
@@ -3,47 +3,72 @@ package io.dico.parcels2.command
import io.dico.dicore.command.Validate
import io.dico.dicore.command.annotation.Cmd
import io.dico.dicore.command.annotation.Desc
-import io.dico.parcels2.GlobalAddedData
-import io.dico.parcels2.GlobalAddedDataManager
-import io.dico.parcels2.PlayerProfile
+import io.dico.parcels2.GlobalPrivileges
+import io.dico.parcels2.GlobalPrivilegesManager
import io.dico.parcels2.ParcelsPlugin
+import io.dico.parcels2.PlayerProfile
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
-class CommandsAddedStatusGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
- private inline val data get() = plugin.globalAddedData
+class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
+ private inline val data get() = plugin.globalPrivileges
@Suppress("NOTHING_TO_INLINE")
- private inline operator fun GlobalAddedDataManager.get(player: OfflinePlayer): GlobalAddedData = data[PlayerProfile(player)]
+ private inline operator fun GlobalPrivilegesManager.get(player: OfflinePlayer): GlobalPrivileges = this[PlayerProfile(player)]
+
+ @Cmd("entrust")
+ @Desc(
+ "Allows a player to manage this parcel",
+ shortVersion = "allows a player to manage this parcel"
+ )
+ fun cmdEntrust(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(player != sender, "The target cannot be yourself")
+ Validate.isTrue(data[sender].allowManage(player), "${player.name} is already allowed to manage globally")
+ return "${player.name} is now allowed to manage globally"
+ }
+
+ @Cmd("distrust")
+ @Desc(
+ "Disallows a player to manage globally,",
+ "they will still be able to build",
+ shortVersion = "disallows a player to manage globally"
+ )
+ fun cmdDistrust(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(data[sender].disallowManage(player), "${player.name} is not currently allowed to manage globally")
+ return "${player.name} is not allowed to manage globally anymore"
+ }
@Cmd("allow", aliases = ["add", "permit"])
- @Desc("Globally allows a player to build on all",
+ @Desc(
+ "Globally allows a player to build on all",
"the parcels that you own.",
- shortVersion = "globally allows a player to build on your parcels")
- @ParcelRequire(owner = true)
+ shortVersion = "globally allows a player to build on your parcels"
+ )
fun cmdAllow(sender: Player, player: OfflinePlayer): Any? {
Validate.isTrue(player != sender, "The target cannot be yourself")
- Validate.isTrue(data[sender].allow(player), "${player.name} is already allowed globally")
+ Validate.isTrue(data[sender].allowBuild(player), "${player.name} is already allowed globally")
return "${player.name} is now allowed to build on all your parcels"
}
@Cmd("disallow", aliases = ["remove", "forbid"])
- @Desc("Globally disallows a player to build on",
+ @Desc(
+ "Globally disallows a player to build on",
"the parcels that you own.",
"If the player is allowed to build on specific",
"parcels, they can still build there.",
- shortVersion = "globally disallows a player to build on your parcels")
- @ParcelRequire(owner = true)
+ shortVersion = "globally disallows a player to build on your parcels"
+ )
fun cmdDisallow(sender: Player, player: OfflinePlayer): Any? {
Validate.isTrue(player != sender, "The target cannot be yourself")
- Validate.isTrue(data[sender].disallow(player), "${player.name} is not currently allowed globally")
+ Validate.isTrue(data[sender].disallowBuild(player), "${player.name} is not currently allowed globally")
return "${player.name} is not allowed to build on all your parcels anymore"
}
@Cmd("ban", aliases = ["deny"])
- @Desc("Globally bans a player from all the parcels",
+ @Desc(
+ "Globally bans a player from all the parcels",
"that you own, making them unable to enter.",
- shortVersion = "globally bans a player from your parcels")
- @ParcelRequire(owner = true)
+ shortVersion = "globally bans a player from your parcels"
+ )
fun cmdBan(sender: Player, player: OfflinePlayer): Any? {
Validate.isTrue(player != sender, "The target cannot be yourself")
Validate.isTrue(data[sender].ban(player), "${player.name} is already banned from all your parcels")
@@ -51,12 +76,13 @@ class CommandsAddedStatusGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(
}
@Cmd("unban", aliases = ["undeny"])
- @Desc("Globally unbans a player from all the parcels",
+ @Desc(
+ "Globally unbans a player from all the parcels",
"that you own, they can enter again.",
"If the player is banned from specific parcels,",
"they will still be banned there.",
- shortVersion = "globally unbans a player from your parcels")
- @ParcelRequire(owner = true)
+ shortVersion = "globally unbans a player from your parcels"
+ )
fun cmdUnban(sender: Player, player: OfflinePlayer): Any? {
Validate.isTrue(data[sender].unban(player), "${player.name} is not currently banned from all your parcels")
return "${player.name} is not banned from all your parcels anymore"
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesLocal.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesLocal.kt
new file mode 100644
index 0000000..16b99af
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesLocal.kt
@@ -0,0 +1,90 @@
+package io.dico.parcels2.command
+
+import io.dico.dicore.command.Validate
+import io.dico.dicore.command.annotation.Cmd
+import io.dico.dicore.command.annotation.Desc
+import io.dico.parcels2.ParcelsPlugin
+import io.dico.parcels2.Privilege
+import io.dico.parcels2.util.ext.hasPermAdminManage
+import org.bukkit.OfflinePlayer
+import org.bukkit.entity.Player
+
+class CommandsPrivilegesLocal(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
+
+ @Cmd("entrust")
+ @Desc(
+ "Allows a player to manage this parcel",
+ shortVersion = "allows a player to manage this parcel"
+ )
+ @RequireParcelPrivilege(Privilege.OWNER)
+ fun ParcelScope.cmdEntrust(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(parcel.owner != null || sender.hasPermAdminManage, "This parcel is unowned")
+ Validate.isTrue(!parcel.owner!!.matches(player), "The target already owns the parcel")
+ Validate.isTrue(parcel.allowManage(player), "${player.name} is already allowed to manage this parcel")
+ return "${player.name} is now allowed to manage this parcel"
+ }
+
+ @Cmd("distrust")
+ @Desc(
+ "Disallows a player to manage this parcel,",
+ "they will still be able to build",
+ shortVersion = "disallows a player to manage this parcel"
+ )
+ @RequireParcelPrivilege(Privilege.OWNER)
+ fun ParcelScope.cmdDistrust(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(parcel.disallowManage(player), "${player.name} is not currently allowed to manage this parcel")
+ return "${player.name} is not allowed to manage this parcel anymore"
+ }
+
+ @Cmd("allow", aliases = ["add", "permit"])
+ @Desc(
+ "Allows a player to build on this parcel",
+ shortVersion = "allows a player to build on this parcel"
+ )
+ @RequireParcelPrivilege(Privilege.CAN_MANAGE)
+ fun ParcelScope.cmdAllow(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(parcel.owner != null || sender.hasPermAdminManage, "This parcel is unowned")
+ Validate.isTrue(!parcel.owner!!.matches(player), "The target already owns the parcel")
+ Validate.isTrue(parcel.allowBuild(player), "${player.name} is already allowed to build on this parcel")
+ return "${player.name} is now allowed to build on this parcel"
+ }
+
+ @Cmd("disallow", aliases = ["remove", "forbid"])
+ @Desc(
+ "Disallows a player to build on this parcel,",
+ "they won't be allowed to anymore",
+ shortVersion = "disallows a player to build on this parcel"
+ )
+ @RequireParcelPrivilege(Privilege.CAN_MANAGE)
+ fun ParcelScope.cmdDisallow(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(parcel.disallowBuild(player), "${player.name} is not currently allowed to build on this parcel")
+ return "${player.name} is not allowed to build on this parcel anymore"
+ }
+
+ @Cmd("ban", aliases = ["deny"])
+ @Desc(
+ "Bans a player from this parcel,",
+ "making them unable to enter",
+ shortVersion = "bans a player from this parcel"
+ )
+ @RequireParcelPrivilege(Privilege.CAN_MANAGE)
+ fun ParcelScope.cmdBan(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(parcel.owner != null || sender.hasPermAdminManage, "This parcel is unowned")
+ Validate.isTrue(!parcel.owner!!.matches(player), "The owner cannot be banned from the parcel")
+ Validate.isTrue(parcel.ban(player), "${player.name} is already banned from this parcel")
+ return "${player.name} is now banned from this parcel"
+ }
+
+ @Cmd("unban", aliases = ["undeny"])
+ @Desc(
+ "Unbans a player from this parcel,",
+ "they will be able to enter it again",
+ shortVersion = "unbans a player from this parcel"
+ )
+ @RequireParcelPrivilege(Privilege.CAN_MANAGE)
+ fun ParcelScope.cmdUnban(sender: Player, player: OfflinePlayer): Any? {
+ Validate.isTrue(parcel.unban(player), "${player.name} is not currently banned from this parcel")
+ return "${player.name} is not banned from this parcel anymore"
+ }
+
+} \ 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 b9dfe1e..1eddf97 100644
--- a/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/ParcelCommandBuilder.kt
@@ -4,6 +4,7 @@ import io.dico.dicore.command.CommandBuilder
import io.dico.dicore.command.ICommandAddress
import io.dico.dicore.command.ICommandDispatcher
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
+import io.dico.parcels2.Interactables
import io.dico.parcels2.ParcelsPlugin
import io.dico.parcels2.logger
import java.util.LinkedList
@@ -20,15 +21,25 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher =
group("parcel", "plot", "plots", "p") {
addRequiredPermission("parcels.command")
registerCommands(CommandsGeneral(plugin))
- registerCommands(CommandsAddedStatusLocal(plugin))
+ registerCommands(CommandsPrivilegesLocal(plugin))
group("option", "opt", "o") {
- CommandsParcelOptions.setGroupDescription(this)
- registerCommands(CommandsParcelOptions(plugin))
+ 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(CommandsAddedStatusGlobal(plugin))
+ registerCommands(CommandsPrivilegesGlobal(plugin))
}
group("admin", "a") {
diff --git a/src/main/kotlin/io/dico/parcels2/command/ParcelCommandReceivers.kt b/src/main/kotlin/io/dico/parcels2/command/ParcelCommandReceivers.kt
index 488148d..443adfb 100644
--- a/src/main/kotlin/io/dico/parcels2/command/ParcelCommandReceivers.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/ParcelCommandReceivers.kt
@@ -7,7 +7,9 @@ import io.dico.dicore.command.Validate
import io.dico.parcels2.Parcel
import io.dico.parcels2.ParcelProvider
import io.dico.parcels2.ParcelWorld
-import io.dico.parcels2.util.ext.hasAdminManage
+import io.dico.parcels2.Privilege
+import io.dico.parcels2.Privilege.*
+import io.dico.parcels2.util.ext.hasPermAdminManage
import io.dico.parcels2.util.ext.uuid
import org.bukkit.entity.Player
import java.lang.reflect.Method
@@ -18,44 +20,55 @@ import kotlin.reflect.jvm.kotlinFunction
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
-annotation class ParcelRequire(val admin: Boolean = false, val owner: Boolean = false)
+annotation class RequireParcelPrivilege(val privilege: Privilege)
+/*
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class SuspensionTimeout(val millis: Int)
+*/
open class WorldScope(val world: ParcelWorld) : ICommandReceiver
open class ParcelScope(val parcel: Parcel) : WorldScope(parcel.world) {
- fun checkCanManage(player: Player, action: String) = Validate.isTrue(player.hasAdminManage || parcel.isOwner(player.uuid),
- "You must own this parcel to $action")
+ fun checkCanManage(player: Player, action: String) = Validate.isTrue(
+ player.hasPermAdminManage || parcel.hasPrivilegeToManage(player),
+ "You must own this parcel to $action"
+ )
}
fun getParcelCommandReceiver(parcelProvider: ParcelProvider, context: ExecutionContext, method: Method, cmdName: String): ICommandReceiver {
val player = context.sender as Player
val function = method.kotlinFunction!!
val receiverType = function.extensionReceiverParameter!!.type
- val require = function.findAnnotation<ParcelRequire>()
- val admin = require?.admin == true
- val owner = require?.owner == true
+ val require = function.findAnnotation<RequireParcelPrivilege>()
return when (receiverType.jvmErasure) {
- ParcelScope::class -> ParcelScope(parcelProvider.getParcelRequired(player, admin, owner))
- WorldScope::class -> WorldScope(parcelProvider.getWorldRequired(player, admin))
+ ParcelScope::class -> ParcelScope(parcelProvider.getParcelRequired(player, require?.privilege))
+ WorldScope::class -> WorldScope(parcelProvider.getWorldRequired(player, require?.privilege == ADMIN))
else -> throw InternalError("Invalid command receiver type")
}
}
fun ParcelProvider.getWorldRequired(player: Player, admin: Boolean = false): ParcelWorld {
- if (admin) Validate.isTrue(player.hasAdminManage, "You must have admin rights to use that command")
+ if (admin) Validate.isTrue(player.hasPermAdminManage, "You must have admin rights to use that command")
return getWorld(player.world)
?: throw CommandException("You must be in a parcel world to use that command")
}
-fun ParcelProvider.getParcelRequired(player: Player, admin: Boolean = false, own: Boolean = false): Parcel {
- val parcel = getWorldRequired(player, admin = admin).getParcelAt(player)
+fun ParcelProvider.getParcelRequired(player: Player, privilege: Privilege? = null): Parcel {
+ val parcel = getWorldRequired(player, admin = privilege == ADMIN).getParcelAt(player)
?: throw CommandException("You must be in a parcel to use that command")
- if (own) Validate.isTrue(parcel.isOwner(player.uuid) || player.hasAdminManage,
- "You must own this parcel to use that command")
+
+ if (!player.hasPermAdminManage) {
+ @Suppress("NON_EXHAUSTIVE_WHEN")
+ when (privilege) {
+ OWNER ->
+ Validate.isTrue(parcel.isOwner(player.uuid), "You must own this parcel to use that command")
+ CAN_MANAGE ->
+ Validate.isTrue(parcel.hasPrivilegeToManage(player), "You must have management privileges on this parcel to use that command")
+ }
+ }
+
return parcel
}
diff --git a/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt b/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt
new file mode 100644
index 0000000..feba76e
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt
@@ -0,0 +1,36 @@
+package io.dico.parcels2.command
+
+import io.dico.dicore.command.Command
+import io.dico.dicore.command.CommandException
+import io.dico.dicore.command.ExecutionContext
+import io.dico.dicore.command.IContextFilter
+import io.dico.dicore.command.parameter.type.ParameterTypes
+import io.dico.parcels2.Interactables
+import io.dico.parcels2.ParcelProvider
+import org.bukkit.command.CommandSender
+import org.bukkit.entity.Player
+
+class ParcelOptionsInteractCommand(val parcelProvider: ParcelProvider) : Command() {
+
+ init {
+ addContextFilter(IContextFilter.PLAYER_ONLY)
+ addParameter("allowed", "allowed", ParameterTypes.BOOLEAN)
+ }
+
+ override fun execute(sender: CommandSender, context: ExecutionContext): String? {
+ val parcel = parcelProvider.getParcelRequired(sender as Player, owner = true)
+ val interactableClassName = context.address.mainKey
+ val allowed: Boolean = context.get("allowed")
+ val change = parcel.interactableConfig.setInteractable(Interactables[interactableClassName], allowed)
+
+ return when {
+ allowed && change -> "Other players can now interact with $interactableClassName"
+ allowed && !change -> err("Other players could already interact with $interactableClassName")
+ change -> "Other players can not interact with $interactableClassName anymore"
+ else -> err("Other players were not allowed to interact with $interactableClassName")
+ }
+ }
+
+}
+
+private fun err(message: String): Nothing = throw CommandException(message) \ No newline at end of file
diff --git a/src/main/kotlin/io/dico/parcels2/command/ParcelTarget.kt b/src/main/kotlin/io/dico/parcels2/command/ParcelTarget.kt
index abf7d40..956da94 100644
--- a/src/main/kotlin/io/dico/parcels2/command/ParcelTarget.kt
+++ b/src/main/kotlin/io/dico/parcels2/command/ParcelTarget.kt
@@ -8,7 +8,7 @@ import io.dico.parcels2.*
import io.dico.parcels2.storage.Storage
import io.dico.parcels2.util.Vec2i
import io.dico.parcels2.util.ext.floor
-import kotlinx.coroutines.CoroutineStart.*
+import kotlinx.coroutines.CoroutineStart.UNDISPATCHED
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import org.bukkit.command.CommandSender
@@ -26,12 +26,14 @@ sealed class ParcelTarget(val world: ParcelWorld, val parsedKind: Int, val isDef
val isPath: Boolean get() = id == null
}
- class ByOwner(world: ParcelWorld,
- owner: PlayerProfile,
- val index: Int,
- parsedKind: Int,
- isDefault: Boolean,
- val onResolveFailure: (() -> Unit)? = null) : ParcelTarget(world, parsedKind, isDefault) {
+ class ByOwner(
+ world: ParcelWorld,
+ owner: PlayerProfile,
+ val index: Int,
+ parsedKind: Int,
+ isDefault: Boolean,
+ val onResolveFailure: (() -> Unit)? = null
+ ) : ParcelTarget(world, parsedKind, isDefault) {
init {
if (index < 0) throw IllegalArgumentException("Invalid parcel home index: $index")
}