diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/command/ParcelCommands.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/command/ParcelCommands.kt | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/command/ParcelCommands.kt b/src/main/kotlin/io/dico/parcels2/command/ParcelCommands.kt index 016ad22..6cc5e02 100644 --- a/src/main/kotlin/io/dico/parcels2/command/ParcelCommands.kt +++ b/src/main/kotlin/io/dico/parcels2/command/ParcelCommands.kt @@ -4,12 +4,16 @@ import io.dico.dicore.command.CommandException import io.dico.dicore.command.ExecutionContext 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.ParcelOwner import io.dico.parcels2.ParcelsPlugin +import io.dico.parcels2.storage.getParcelBySerializedValue +import io.dico.parcels2.util.hasParcelHomeOthers import io.dico.parcels2.util.parcelLimit import io.dico.parcels2.util.uuid import org.bukkit.entity.Player +@Suppress("unused") class ParcelCommands(override val plugin: ParcelsPlugin) : HasWorlds, HasPlugin { override val worlds = plugin.worlds @@ -35,7 +39,7 @@ class ParcelCommands(override val plugin: ParcelsPlugin) : HasWorlds, HasPlugin val parcel = world.nextEmptyParcel() ?: error("This world is full, please ask an admin to upsize it") parcel.owner = ParcelOwner(uuid = player.uuid) - player.teleport(world.generator.getHomeLocation(parcel)) + player.teleport(parcel.homeLocation) "Enjoy your new parcel!" } } @@ -47,5 +51,32 @@ class ParcelCommands(override val plugin: ParcelsPlugin) : HasWorlds, HasPlugin shortVersion = "displays information about this parcel") fun cmdInfo(player: Player) = requireInParcel(player) { parcel.infoString } + @Cmd("home", aliases = ["h"]) + @Desc("Teleports you to your parcels,", + "unless another player was specified.", + "You can specify an index number if you have", + "more than one parcel", + shortVersion = "teleports you to parcels") + @RequireParameters(0) + fun cmdHome(player: Player, context: ExecutionContext, target: NamedParcelTarget) { + if (player !== target.player && !player.hasParcelHomeOthers) { + error("You do not have permission to teleport to other people's parcels") + } + + return delegateCommandAsync(context) { + val ownedParcelsResult = plugin.storage.getOwnedParcels(ParcelOwner(uuid = target.player.uuid)).await() + awaitSynchronousTask { + val uuid = target.player.uuid + val ownedParcels = ownedParcelsResult + .map { worlds.getParcelBySerializedValue(it) } + .filter { it != null && it.world == target.world && it.owner?.uuid == uuid } + + val targetMatch = ownedParcels.getOrNull(target.index) + ?: error("The specified parcel could not be matched") + + player.teleport(targetMatch.homeLocation) + } + } + } }
\ No newline at end of file |