diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/command/ParcelOptionsInteractCommand.kt | 36 |
1 files changed, 36 insertions, 0 deletions
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 |