diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt b/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt index 78a989e..5395b1c 100644 --- a/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt +++ b/src/main/kotlin/io/dico/parcels2/command/CommandsGeneral.kt @@ -4,20 +4,15 @@ import io.dico.dicore.command.EMessageType 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.Flag import io.dico.dicore.command.annotation.RequireParameters import io.dico.parcels2.ParcelOwner import io.dico.parcels2.ParcelsPlugin -import io.dico.parcels2.blockvisitor.RegionTraversal -import io.dico.parcels2.command.NamedParcelDefaultValue.FIRST_OWNED -import io.dico.parcels2.storage.getParcelBySerializedValue import io.dico.parcels2.util.hasAdminManage import io.dico.parcels2.util.hasParcelHomeOthers import io.dico.parcels2.util.uuid -import org.bukkit.Material import org.bukkit.entity.Player -import java.util.* -//@Suppress("unused") class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) { @Cmd("auto") @@ -26,12 +21,12 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) { shortVersion = "sets you up with a fresh, unclaimed parcel") suspend fun WorldScope.cmdAuto(player: Player): Any? { checkConnected("be claimed") - checkParcelLimit(player) + checkParcelLimit(player, world) val parcel = world.nextEmptyParcel() ?: error("This world is full, please ask an admin to upsize it") parcel.owner = ParcelOwner(uuid = player.uuid) - player.teleport(parcel.homeLocation) + player.teleport(parcel.world.getHomeLocation(parcel.id)) return "Enjoy your new parcel!" } @@ -48,23 +43,22 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) { "more than one parcel", shortVersion = "teleports you to parcels") @RequireParameters(0) - suspend fun cmdHome(player: Player, - @NamedParcelDefault(FIRST_OWNED) target: NamedParcelTarget): Any? { - if (player !== target.player && !player.hasParcelHomeOthers) { + suspend fun cmdHome(player: Player, @ParcelTarget.Kind(ParcelTarget.OWNER_REAL) target: ParcelTarget): Any? { + val ownerTarget = target as ParcelTarget.ByOwner + if (!ownerTarget.owner.matches(player) && !player.hasParcelHomeOthers) { error("You do not have permission to teleport to other people's parcels") } - val ownedParcelsResult = plugin.storage.getOwnedParcels(ParcelOwner(uuid = target.player.uuid)).await() + val ownedParcelsResult = plugin.storage.getOwnedParcels(ownerTarget.owner).await() - val uuid = target.player.uuid val ownedParcels = ownedParcelsResult - .map { worlds.getParcelBySerializedValue(it) } - .filter { it != null && it.world == target.world && it.owner?.uuid == uuid } + .map { worlds.getParcelById(it) } + .filter { it != null && ownerTarget.world == it.world } val targetMatch = ownedParcels.getOrNull(target.index) ?: error("The specified parcel could not be matched") - player.teleport(targetMatch.homeLocation) + player.teleport(targetMatch.world.getHomeLocation(targetMatch.id)) return "" } @@ -77,38 +71,39 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) { error(if (it.matches(player)) "You already own this parcel" else "This parcel is not available") } - checkParcelLimit(player) - parcel.owner = ParcelOwner(uuid = player.uuid, name = player.name) + checkParcelLimit(player, world) + parcel.owner = ParcelOwner(player) return "Enjoy your new parcel!" } + @Cmd("unclaim") + @Desc("Unclaims this parcel") + @ParcelRequire(owner = true) + fun ParcelScope.cmdUnclaim(player: Player): Any? { + parcel.dispose() + return "Your parcel has been disposed" + } + @Cmd("clear") @ParcelRequire(owner = true) - fun ParcelScope.cmdClear(context: ExecutionContext) { - world.generator.clearParcel(parcel) + fun ParcelScope.cmdClear(context: ExecutionContext, @Flag sure: Boolean): Any? { + if (!sure) return "Are you sure? You cannot undo this action!\n" + + "Run \"/${context.rawInput} -sure\" if you want to go through with this." + + world.clearParcel(parcel.id) .onProgressUpdate(1000, 1000) { progress, elapsedTime -> - context.sendMessage(EMessageType.INFORMATIVE, "Clear progress: %.02f%%, %.2fs elapsed" + val alt = context.getFormat(EMessageType.NUMBER) + val main = context.getFormat(EMessageType.INFORMATIVE) + context.sendMessage(EMessageType.INFORMATIVE, false, "Clear progress: $alt%.02f$main%%, $alt%.2f${main}s elapsed" .format(progress * 100, elapsedTime / 1000.0)) } + + return null } - @Cmd("make_mess") - @ParcelRequire(owner = true) - fun ParcelScope.cmdMakeMess(context: ExecutionContext) { - val server = plugin.server - val blockDatas = arrayOf( - server.createBlockData(Material.STICKY_PISTON), - server.createBlockData(Material.GLASS), - server.createBlockData(Material.STONE_SLAB), - server.createBlockData(Material.QUARTZ_BLOCK) - ) - val random = Random() - world.generator.doBlockOperation(parcel, direction = RegionTraversal.UPDARD) { block -> - block.blockData = blockDatas[random.nextInt(4)] - }.onProgressUpdate(1000, 1000) { progress, elapsedTime -> - context.sendMessage(EMessageType.INFORMATIVE, "Mess progress: %.02f%%, %.2fs elapsed" - .format(progress * 100, elapsedTime / 1000.0)) - } + @Cmd("swap") + fun ParcelScope.cmdSwap(context: ExecutionContext, @Flag sure: Boolean): Any? { + TODO() } }
\ No newline at end of file |