Tweak
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package io.dico.parcels2
|
||||
|
||||
import io.dico.parcels2.blockvisitor.RegionTraverser
|
||||
import io.dico.parcels2.blockvisitor.Worker
|
||||
import io.dico.parcels2.blockvisitor.WorkerScope
|
||||
import io.dico.parcels2.blockvisitor.WorktimeLimiter
|
||||
import io.dico.parcels2.blockvisitor.*
|
||||
import io.dico.parcels2.util.Region
|
||||
import io.dico.parcels2.util.Vec2i
|
||||
import io.dico.parcels2.util.get
|
||||
@@ -62,6 +59,8 @@ interface ParcelBlockManager {
|
||||
|
||||
fun clearParcel(parcel: ParcelId): Worker
|
||||
|
||||
fun submitBlockVisitor(parcelId: ParcelId, task: TimeLimitedTask): Worker
|
||||
|
||||
/**
|
||||
* Used to update owner blocks in the corner of the parcel
|
||||
*/
|
||||
@@ -70,7 +69,7 @@ interface ParcelBlockManager {
|
||||
|
||||
inline fun ParcelBlockManager.doBlockOperation(parcel: ParcelId,
|
||||
traverser: RegionTraverser,
|
||||
crossinline operation: suspend WorkerScope.(Block) -> Unit) = worktimeLimiter.submit {
|
||||
crossinline operation: suspend WorkerScope.(Block) -> Unit) = submitBlockVisitor(parcel) {
|
||||
val region = getRegion(parcel)
|
||||
val blockCount = region.blockCount.toDouble()
|
||||
val blocks = traverser.traverseRegion(region)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package io.dico.parcels2.command
|
||||
|
||||
import io.dico.dicore.command.CommandException
|
||||
import io.dico.dicore.command.EMessageType
|
||||
import io.dico.dicore.command.ExecutionContext
|
||||
import io.dico.dicore.command.ICommandReceiver
|
||||
import io.dico.dicore.command.*
|
||||
import io.dico.parcels2.ParcelWorld
|
||||
import io.dico.parcels2.ParcelsPlugin
|
||||
import io.dico.parcels2.PlayerProfile
|
||||
@@ -43,6 +40,7 @@ abstract class AbstractParcelCommands(val plugin: ParcelsPlugin) : ICommandRecei
|
||||
"Run \"/${context.route.joinToString(" ")} -sure\" if you want to go through with this."
|
||||
|
||||
protected fun ParcelScope.clearWithProgressUpdates(context: ExecutionContext, action: String) {
|
||||
Validate.isTrue(!parcel.hasBlockVisitors, "A process is already running in this parcel")
|
||||
world.blockManager.clearParcel(parcel.id)
|
||||
.onProgressUpdate(1000, 1000) { progress, elapsedTime ->
|
||||
val alt = context.getFormat(EMessageType.NUMBER)
|
||||
|
||||
@@ -18,9 +18,11 @@ import org.bukkit.entity.Player
|
||||
class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
|
||||
@Cmd("auto")
|
||||
@Desc("Finds the unclaimed parcel nearest to origin,",
|
||||
@Desc(
|
||||
"Finds the unclaimed parcel nearest to origin,",
|
||||
"and gives it to you",
|
||||
shortVersion = "sets you up with a fresh, unclaimed parcel")
|
||||
shortVersion = "sets you up with a fresh, unclaimed parcel"
|
||||
)
|
||||
suspend fun WorldScope.cmdAuto(player: Player): Any? {
|
||||
checkConnected("be claimed")
|
||||
checkParcelLimit(player, world)
|
||||
@@ -33,32 +35,42 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
}
|
||||
|
||||
@Cmd("info", aliases = ["i"])
|
||||
@Desc("Displays general information",
|
||||
@Desc(
|
||||
"Displays general information",
|
||||
"about the parcel you're on",
|
||||
shortVersion = "displays information about this parcel")
|
||||
shortVersion = "displays information about this parcel"
|
||||
)
|
||||
fun ParcelScope.cmdInfo(player: Player) = parcel.infoString
|
||||
|
||||
@Cmd("home", aliases = ["h"])
|
||||
@Desc("Teleports you to your parcels,",
|
||||
@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")
|
||||
shortVersion = "teleports you to parcels"
|
||||
)
|
||||
@RequireParameters(0)
|
||||
suspend fun cmdHome(player: Player,
|
||||
@Kind(ParcelTarget.OWNER_REAL) target: ParcelTarget): Any? {
|
||||
suspend fun cmdHome(
|
||||
player: Player,
|
||||
@Kind(ParcelTarget.OWNER_REAL) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("tp", aliases = ["teleport"])
|
||||
suspend fun cmdTp(player: Player,
|
||||
@Kind(ParcelTarget.ID) target: ParcelTarget): Any? {
|
||||
suspend fun cmdTp(
|
||||
player: Player,
|
||||
@Kind(ParcelTarget.ID) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("goto")
|
||||
suspend fun cmdGoto(player: Player,
|
||||
@Kind(ParcelTarget.ANY) target: ParcelTarget): Any? {
|
||||
suspend fun cmdGoto(
|
||||
player: Player,
|
||||
@Kind(ParcelTarget.ANY) target: ParcelTarget
|
||||
): Any? {
|
||||
if (target is ParcelTarget.ByOwner) {
|
||||
target.resolveOwner(plugin.storage)
|
||||
if (!target.owner.matches(player) && !player.hasParcelHomeOthers) {
|
||||
@@ -73,14 +85,18 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
}
|
||||
|
||||
@Cmd("goto_fake")
|
||||
suspend fun cmdGotoFake(player: Player,
|
||||
@Kind(ParcelTarget.OWNER_FAKE) target: ParcelTarget): Any? {
|
||||
suspend fun cmdGotoFake(
|
||||
player: Player,
|
||||
@Kind(ParcelTarget.OWNER_FAKE) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("claim")
|
||||
@Desc("If this parcel is unowned, makes you the owner",
|
||||
shortVersion = "claims this parcel")
|
||||
@Desc(
|
||||
"If this parcel is unowned, makes you the owner",
|
||||
shortVersion = "claims this parcel"
|
||||
)
|
||||
suspend fun ParcelScope.cmdClaim(player: Player): Any? {
|
||||
checkConnected("be claimed")
|
||||
parcel.owner.takeIf { !player.hasAdminManage }?.let {
|
||||
|
||||
@@ -227,7 +227,7 @@ class DefaultParcelGenerator(
|
||||
return world.getParcelById(parcelId)
|
||||
}
|
||||
|
||||
private fun submitBlockVisitor(parcelId: ParcelId, task: TimeLimitedTask): Worker {
|
||||
override fun submitBlockVisitor(parcelId: ParcelId, task: TimeLimitedTask): Worker {
|
||||
val parcel = getParcel(parcelId) ?: return worktimeLimiter.submit(task)
|
||||
if (parcel.hasBlockVisitors) throw IllegalArgumentException("This parcel already has a block visitor")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user