diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt index 3c83afc..e225cb5 100644 --- a/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt +++ b/src/main/kotlin/io/dico/parcels2/command/CommandsPrivilegesGlobal.kt @@ -1,12 +1,11 @@ +@file:Suppress("NON_EXHAUSTIVE_WHEN") + 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.GlobalPrivileges -import io.dico.parcels2.GlobalPrivilegesManager import io.dico.parcels2.ParcelsPlugin -import io.dico.parcels2.PlayerProfile +import io.dico.parcels2.PrivilegeChangeResult.* import org.bukkit.OfflinePlayer import org.bukkit.entity.Player @@ -19,11 +18,12 @@ class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(p "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" - } + fun cmdEntrust(sender: Player, player: OfflinePlayer): Any? = + when (data[sender].allowManage(player)) { + FAIL_OWNER -> err("The target cannot be yourself") + FAIL -> err("${player.name} is already allowed to manage globally") + SUCCESS -> "${player.name} is now allowed to manage globally" + } @Cmd("distrust") @Desc( @@ -31,10 +31,12 @@ class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(p "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" - } + fun cmdDistrust(sender: Player, player: OfflinePlayer): Any? = + when (data[sender].disallowManage(player)) { + FAIL_OWNER -> err("The target cannot be yourself") + FAIL -> err("${player.name} is not currently allowed to manage globally") + SUCCESS -> "${player.name} is not allowed to manage globally anymore" + } @Cmd("allow", aliases = ["add", "permit"]) @Desc( @@ -42,11 +44,12 @@ class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(p "the parcels that you own.", 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].allowBuild(player), "${player.name} is already allowed globally") - return "${player.name} is now allowed to build on all your parcels" - } + fun cmdAllow(sender: Player, player: OfflinePlayer): Any? = + when (data[sender].allowBuild(player)) { + FAIL_OWNER -> err("The target cannot be yourself") + FAIL -> err("${player.name} is already allowed globally") + SUCCESS -> "${player.name} is now allowed to build on all your parcels" + } @Cmd("disallow", aliases = ["remove", "forbid"]) @Desc( @@ -56,11 +59,12 @@ class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(p "parcels, they can still build there.", 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].disallowBuild(player), "${player.name} is not currently allowed globally") - return "${player.name} is not allowed to build on all your parcels anymore" - } + fun cmdDisallow(sender: Player, player: OfflinePlayer): Any? = + when (data[sender].disallowBuild(player)) { + FAIL_OWNER -> err("The target cannot be yourself") + FAIL -> err("${player.name} is not currently allowed globally") + SUCCESS -> "${player.name} is not allowed to build on all your parcels anymore" + } @Cmd("ban", aliases = ["deny"]) @Desc( @@ -68,11 +72,12 @@ class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(p "that you own, making them unable to enter.", 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") - return "${player.name} is now banned from all your parcels" - } + fun cmdBan(sender: Player, player: OfflinePlayer): Any? = + when (data[sender].ban(player)) { + FAIL_OWNER -> err("The target cannot be yourself") + FAIL -> err("${player.name} is already banned from all your parcels") + SUCCESS -> "${player.name} is now banned from all your parcels" + } @Cmd("unban", aliases = ["undeny"]) @Desc( @@ -82,9 +87,11 @@ class CommandsPrivilegesGlobal(plugin: ParcelsPlugin) : AbstractParcelCommands(p "they will still be banned there.", 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" - } + fun cmdUnban(sender: Player, player: OfflinePlayer): Any? = + when (data[sender].unban(player)) { + FAIL_OWNER -> err("The target cannot be yourself") + FAIL -> err("${player.name} is not currently banned from all your parcels") + SUCCESS -> "${player.name} is not banned from all your parcels anymore" + } }
\ No newline at end of file |