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