Archived
0

Work on commands a bit more

This commit is contained in:
Dico200
2018-07-27 23:20:44 +01:00
parent a9c19ff5cf
commit 2a726e1b61
14 changed files with 240 additions and 245 deletions

View File

@@ -6,6 +6,7 @@ import io.dico.dicore.command.parameter.type.ParameterConfig
import io.dico.dicore.command.parameter.type.ParameterType
import io.dico.parcels2.ParcelWorld
import io.dico.parcels2.Worlds
import io.dico.parcels2.util.isValid
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.command.CommandSender
@@ -42,7 +43,7 @@ class ParcelHomeParameterType(val worlds: Worlds) : ParameterType<NamedParcelTar
@Suppress("UsePropertyAccessSyntax")
private fun getOfflinePlayer(input: String, parameter: Parameter<*, *>) = Bukkit.getOfflinePlayer(input)
?.takeIf { it.isOnline() || it.hasPlayedBefore() }
?.takeIf { it.isValid }
?: invalidInput(parameter, "do not know who $input is")
override fun parse(parameter: Parameter<NamedParcelTarget, NamedParcelDefaultValue>,

View File

@@ -1,8 +1,10 @@
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.hasAdminManage
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
@@ -13,7 +15,10 @@ class ParcelAddCommands(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin)
shortVersion = "allows a player to build on this parcel")
@ParcelRequire(owner = true)
fun ParcelScope.cmdAllow(sender: Player, player: OfflinePlayer): Any? {
TODO()
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"])
@@ -22,7 +27,8 @@ class ParcelAddCommands(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin)
shortVersion = "disallows a player to build on this parcel")
@ParcelRequire(owner = true)
fun ParcelScope.cmdDisallow(sender: Player, player: OfflinePlayer): Any? {
TODO()
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"])
@@ -31,7 +37,10 @@ class ParcelAddCommands(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin)
shortVersion = "bans a player from this parcel")
@ParcelRequire(owner = true)
fun ParcelScope.cmdBan(sender: Player, player: OfflinePlayer): Any? {
TODO()
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"])
@@ -40,7 +49,8 @@ class ParcelAddCommands(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin)
shortVersion = "unbans a player from this parcel")
@ParcelRequire(owner = true)
fun ParcelScope.cmdUnban(sender: Player, player: OfflinePlayer): Any? {
TODO()
Validate.isTrue(parcel.unban(player), "${player.name} is not currently banned from this parcel")
return "${player.name} is not banned from this parcel anymore"
}
}

View File

@@ -0,0 +1,7 @@
package io.dico.parcels2.command
import io.dico.parcels2.ParcelsPlugin
class ParcelAdminCommands(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
}

View File

@@ -9,6 +9,7 @@ import io.dico.parcels2.logger
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
//@formatter:off
return CommandBuilder()
.setChatController(ParcelsChatController())
.addParameterType(false, ParcelParameterType(plugin.worlds))
.addParameterType(true, ParcelHomeParameterType(plugin.worlds))
@@ -21,6 +22,10 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
.registerCommands(ParcelOptionCommands(plugin))
.parent()
.group("admin", "a")
.registerCommands(ParcelAdminCommands(plugin))
.parent()
.putDebugCommands(plugin)
.parent()

View File

@@ -0,0 +1,9 @@
package io.dico.parcels2.command
import io.dico.dicore.command.chat.AbstractChatController
class ParcelsChatController : AbstractChatController() {
}