Perform some fixes
This commit is contained in:
@@ -238,14 +238,14 @@ public class RootCommandAddress extends ModifiableCommandAddress implements ICom
|
||||
try {
|
||||
ICommandAddress target = getCommandTarget(context, buffer);
|
||||
|
||||
List<String> out;
|
||||
if (target.hasCommand()) {
|
||||
List<String> out = Collections.emptyList();
|
||||
/*if (target.hasCommand()) {
|
||||
context.setCommand(target.getCommand());
|
||||
target.getCommand().initializeAndFilterContext(context);
|
||||
out = target.getCommand().tabComplete(sender, context, location);
|
||||
} else {
|
||||
out = Collections.emptyList();
|
||||
}
|
||||
}*/
|
||||
|
||||
int cursor = buffer.getCursor();
|
||||
String input;
|
||||
|
||||
@@ -1,142 +1,143 @@
|
||||
package io.dico.parcels2.command
|
||||
|
||||
import io.dico.dicore.command.ExecutionContext
|
||||
import io.dico.dicore.command.Validate
|
||||
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.ParcelsPlugin
|
||||
import io.dico.parcels2.PlayerProfile
|
||||
import io.dico.parcels2.Privilege
|
||||
import io.dico.parcels2.command.ParcelTarget.TargetKind
|
||||
import io.dico.parcels2.util.ext.hasParcelHomeOthers
|
||||
import io.dico.parcels2.util.ext.hasPermAdminManage
|
||||
import io.dico.parcels2.util.ext.uuid
|
||||
import org.bukkit.block.Biome
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class CommandsGeneral(plugin: ParcelsPlugin, parent: SpecialCommandAddress) : AbstractParcelCommands(plugin) {
|
||||
|
||||
@Cmd("auto")
|
||||
@Desc(
|
||||
"Finds the unclaimed parcel nearest to origin,",
|
||||
"and gives it to you",
|
||||
shortVersion = "sets you up with a fresh, unclaimed parcel"
|
||||
)
|
||||
suspend fun WorldScope.cmdAuto(player: Player): Any? {
|
||||
checkConnected("be claimed")
|
||||
checkParcelLimit(player, world)
|
||||
|
||||
val parcel = world.nextEmptyParcel()
|
||||
?: err("This world is full, please ask an admin to upsize it")
|
||||
parcel.owner = PlayerProfile(uuid = player.uuid)
|
||||
player.teleport(parcel.homeLocation)
|
||||
return "Enjoy your new parcel!"
|
||||
}
|
||||
|
||||
@Cmd("info", aliases = ["i"])
|
||||
@Desc(
|
||||
"Displays general information",
|
||||
"about the parcel you're on",
|
||||
shortVersion = "displays information about this parcel"
|
||||
)
|
||||
fun ParcelScope.cmdInfo(player: Player) = parcel.infoString
|
||||
|
||||
init {
|
||||
parent.addSpeciallyTreatedKeys("home", "h")
|
||||
}
|
||||
|
||||
@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)
|
||||
suspend fun cmdHome(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.OWNER_REAL) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("tp", aliases = ["teleport"])
|
||||
suspend fun cmdTp(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.ID) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("goto")
|
||||
suspend fun cmdGoto(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.ANY) target: ParcelTarget
|
||||
): Any? {
|
||||
if (target is ParcelTarget.ByOwner) {
|
||||
target.resolveOwner(plugin.storage)
|
||||
if (!target.owner.matches(player) && !player.hasParcelHomeOthers) {
|
||||
err("You do not have permission to teleport to other people's parcels")
|
||||
}
|
||||
}
|
||||
|
||||
val match = target.getParcelSuspend(plugin.storage)
|
||||
?: err("The specified parcel could not be matched")
|
||||
player.teleport(match.homeLocation)
|
||||
return null
|
||||
}
|
||||
|
||||
@Cmd("goto_fake")
|
||||
suspend fun cmdGotoFake(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.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"
|
||||
)
|
||||
suspend fun ParcelScope.cmdClaim(player: Player): Any? {
|
||||
checkConnected("be claimed")
|
||||
parcel.owner.takeIf { !player.hasPermAdminManage }?.let {
|
||||
err(if (it.matches(player)) "You already own this parcel" else "This parcel is not available")
|
||||
}
|
||||
|
||||
checkParcelLimit(player, world)
|
||||
parcel.owner = PlayerProfile(player)
|
||||
return "Enjoy your new parcel!"
|
||||
}
|
||||
|
||||
@Cmd("unclaim")
|
||||
@Desc("Unclaims this parcel")
|
||||
@RequireParcelPrivilege(Privilege.OWNER)
|
||||
fun ParcelScope.cmdUnclaim(player: Player): Any? {
|
||||
checkConnected("be unclaimed")
|
||||
parcel.dispose()
|
||||
return "Your parcel has been disposed"
|
||||
}
|
||||
|
||||
@Cmd("clear")
|
||||
@RequireParcelPrivilege(Privilege.OWNER)
|
||||
fun ParcelScope.cmdClear(context: ExecutionContext, @Flag sure: Boolean): Any? {
|
||||
Validate.isTrue(!parcel.hasBlockVisitors, "A process is already running in this parcel")
|
||||
if (!sure) return areYouSureMessage(context)
|
||||
world.blockManager.clearParcel(parcel.id)?.reportProgressUpdates(context, "Clear")
|
||||
return null
|
||||
}
|
||||
|
||||
@Cmd("setbiome")
|
||||
@RequireParcelPrivilege(Privilege.OWNER)
|
||||
fun ParcelScope.cmdSetbiome(context: ExecutionContext, biome: Biome): Any? {
|
||||
Validate.isTrue(!parcel.hasBlockVisitors, "A process is already running in this parcel")
|
||||
world.blockManager.setBiome(parcel.id, biome)?.reportProgressUpdates(context, "Biome change")
|
||||
return null
|
||||
}
|
||||
|
||||
package io.dico.parcels2.command
|
||||
|
||||
import io.dico.dicore.command.ExecutionContext
|
||||
import io.dico.dicore.command.Validate
|
||||
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.ParcelsPlugin
|
||||
import io.dico.parcels2.PlayerProfile
|
||||
import io.dico.parcels2.Privilege
|
||||
import io.dico.parcels2.command.ParcelTarget.TargetKind
|
||||
import io.dico.parcels2.util.ext.hasParcelHomeOthers
|
||||
import io.dico.parcels2.util.ext.hasPermAdminManage
|
||||
import io.dico.parcels2.util.ext.uuid
|
||||
import org.bukkit.block.Biome
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class CommandsGeneral(plugin: ParcelsPlugin, parent: SpecialCommandAddress) : AbstractParcelCommands(plugin) {
|
||||
|
||||
@Cmd("auto")
|
||||
@Desc(
|
||||
"Finds the unclaimed parcel nearest to origin,",
|
||||
"and gives it to you",
|
||||
shortVersion = "sets you up with a fresh, unclaimed parcel"
|
||||
)
|
||||
suspend fun WorldScope.cmdAuto(player: Player): Any? {
|
||||
checkConnected("be claimed")
|
||||
checkParcelLimit(player, world)
|
||||
|
||||
val parcel = world.nextEmptyParcel()
|
||||
?: err("This world is full, please ask an admin to upsize it")
|
||||
parcel.owner = PlayerProfile(uuid = player.uuid)
|
||||
player.teleport(parcel.homeLocation)
|
||||
return "Enjoy your new parcel!"
|
||||
}
|
||||
|
||||
@Cmd("info", aliases = ["i"])
|
||||
@Desc(
|
||||
"Displays general information",
|
||||
"about the parcel you're on",
|
||||
shortVersion = "displays information about this parcel"
|
||||
)
|
||||
fun ParcelScope.cmdInfo(player: Player) = parcel.infoString
|
||||
|
||||
init {
|
||||
parent.addSpeciallyTreatedKeys("home", "h")
|
||||
}
|
||||
|
||||
@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)
|
||||
suspend fun cmdHome(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.OWNER_REAL) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("tp", aliases = ["teleport"])
|
||||
suspend fun cmdTp(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.ID) target: ParcelTarget
|
||||
): Any? {
|
||||
return cmdGoto(player, target)
|
||||
}
|
||||
|
||||
@Cmd("goto")
|
||||
suspend fun cmdGoto(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.ANY) target: ParcelTarget
|
||||
): Any? {
|
||||
if (target is ParcelTarget.ByOwner) {
|
||||
target.resolveOwner(plugin.storage)
|
||||
if (!target.owner.matches(player) && !player.hasParcelHomeOthers) {
|
||||
err("You do not have permission to teleport to other people's parcels")
|
||||
}
|
||||
}
|
||||
|
||||
val match = target.getParcelSuspend(plugin.storage)
|
||||
?: err("The specified parcel could not be matched")
|
||||
player.teleport(match.homeLocation)
|
||||
return null
|
||||
}
|
||||
|
||||
@Cmd("goto_fake")
|
||||
suspend fun cmdGotoFake(
|
||||
player: Player,
|
||||
@TargetKind(TargetKind.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"
|
||||
)
|
||||
suspend fun ParcelScope.cmdClaim(player: Player): Any? {
|
||||
checkConnected("be claimed")
|
||||
parcel.owner.takeIf { !player.hasPermAdminManage }?.let {
|
||||
err(if (it.matches(player)) "You already own this parcel" else "This parcel is not available")
|
||||
}
|
||||
|
||||
checkParcelLimit(player, world)
|
||||
parcel.owner = PlayerProfile(player)
|
||||
return "Enjoy your new parcel!"
|
||||
}
|
||||
|
||||
/*
|
||||
@Cmd("unclaim")
|
||||
@Desc("Unclaims this parcel")
|
||||
@RequireParcelPrivilege(Privilege.OWNER)
|
||||
fun ParcelScope.cmdUnclaim(player: Player): Any? {
|
||||
checkConnected("be unclaimed")
|
||||
parcel.dispose()
|
||||
return "Your parcel has been disposed"
|
||||
}*/
|
||||
|
||||
@Cmd("clear")
|
||||
@RequireParcelPrivilege(Privilege.OWNER)
|
||||
fun ParcelScope.cmdClear(context: ExecutionContext, @Flag sure: Boolean): Any? {
|
||||
Validate.isTrue(!parcel.hasBlockVisitors, "A process is already running in this parcel")
|
||||
if (!sure) return areYouSureMessage(context)
|
||||
world.blockManager.clearParcel(parcel.id)?.reportProgressUpdates(context, "Clear")
|
||||
return null
|
||||
}
|
||||
|
||||
@Cmd("setbiome")
|
||||
@RequireParcelPrivilege(Privilege.OWNER)
|
||||
fun ParcelScope.cmdSetbiome(context: ExecutionContext, biome: Biome): Any? {
|
||||
Validate.isTrue(!parcel.hasBlockVisitors, "A process is already running in this parcel")
|
||||
world.blockManager.setBiome(parcel.id, biome)?.reportProgressUpdates(context, "Biome change")
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -106,7 +106,8 @@ sealed class ParcelTarget(val world: ParcelWorld, val parsedKind: Int, val isDef
|
||||
parcelProvider.getWorld(player.world)
|
||||
?: invalidInput(parameter, "You cannot omit the world if you're not in a parcel world")
|
||||
} else {
|
||||
parcelProvider.getWorld(worldString) ?: invalidInput(parameter, "$worldString is not a parcel world")
|
||||
parcelProvider.getWorld(worldString)
|
||||
?: invalidInput(parameter, "$worldString is not a parcel world")
|
||||
}
|
||||
|
||||
val kind = parameter.paramInfo ?: DEFAULT_KIND
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
package io.dico.parcels2.defaultimpl
|
||||
|
||||
import io.dico.parcels2.Parcel
|
||||
import io.dico.parcels2.ParcelContainer
|
||||
import io.dico.parcels2.ParcelId
|
||||
import io.dico.parcels2.ParcelWorld
|
||||
|
||||
class DefaultParcelContainer(val world: ParcelWorld) : ParcelContainer {
|
||||
private var parcels: Array<Array<Parcel>>
|
||||
|
||||
init {
|
||||
parcels = initArray(world.options.axisLimit, world)
|
||||
}
|
||||
|
||||
fun resizeIfSizeChanged() {
|
||||
if (parcels.size != world.options.axisLimit * 2 + 1) {
|
||||
resize(world.options.axisLimit)
|
||||
}
|
||||
}
|
||||
|
||||
fun resize(axisLimit: Int) {
|
||||
parcels = initArray(axisLimit, world, this)
|
||||
}
|
||||
|
||||
fun initArray(axisLimit: Int, world: ParcelWorld, cur: DefaultParcelContainer? = null): Array<Array<Parcel>> {
|
||||
val arraySize = 2 * axisLimit + 1
|
||||
return Array(arraySize) {
|
||||
val x = it - axisLimit
|
||||
Array(arraySize) {
|
||||
val z = it - axisLimit
|
||||
cur?.getParcelById(x, z) ?: ParcelImpl(world, x, z)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getParcelById(x: Int, z: Int): Parcel? {
|
||||
return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit)
|
||||
}
|
||||
|
||||
override fun getParcelById(id: ParcelId): Parcel? {
|
||||
if (!world.id.equals(id.worldId)) throw IllegalArgumentException()
|
||||
return when (id) {
|
||||
is Parcel -> id
|
||||
else -> getParcelById(id.x, id.z)
|
||||
}
|
||||
}
|
||||
|
||||
override fun nextEmptyParcel(): Parcel? {
|
||||
return walkInCircle().find { it.owner == null }
|
||||
}
|
||||
|
||||
private fun walkInCircle(): Iterable<Parcel> = Iterable {
|
||||
iterator {
|
||||
val center = world.options.axisLimit
|
||||
yield(parcels[center][center])
|
||||
for (radius in 0..center) {
|
||||
var x = center - radius;
|
||||
var z = center - radius
|
||||
repeat(radius * 2) { yield(parcels[x++][z]) }
|
||||
repeat(radius * 2) { yield(parcels[x][z++]) }
|
||||
repeat(radius * 2) { yield(parcels[x--][z]) }
|
||||
repeat(radius * 2) { yield(parcels[x][z--]) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllParcels(): Iterator<Parcel> = iterator {
|
||||
for (array in parcels) {
|
||||
yieldAll(array.iterator())
|
||||
}
|
||||
}
|
||||
|
||||
package io.dico.parcels2.defaultimpl
|
||||
|
||||
import io.dico.parcels2.Parcel
|
||||
import io.dico.parcels2.ParcelContainer
|
||||
import io.dico.parcels2.ParcelId
|
||||
import io.dico.parcels2.ParcelWorld
|
||||
|
||||
class DefaultParcelContainer(val world: ParcelWorld) : ParcelContainer {
|
||||
private var parcels: Array<Array<Parcel>>
|
||||
|
||||
init {
|
||||
parcels = initArray(world.options.axisLimit, world)
|
||||
}
|
||||
|
||||
fun resizeIfSizeChanged() {
|
||||
if (parcels.size != world.options.axisLimit * 2 + 1) {
|
||||
resize(world.options.axisLimit)
|
||||
}
|
||||
}
|
||||
|
||||
fun resize(axisLimit: Int) {
|
||||
parcels = initArray(axisLimit, world, this)
|
||||
}
|
||||
|
||||
fun initArray(axisLimit: Int, world: ParcelWorld, cur: DefaultParcelContainer? = null): Array<Array<Parcel>> {
|
||||
val arraySize = 2 * axisLimit + 1
|
||||
return Array(arraySize) {
|
||||
val x = it - axisLimit
|
||||
Array(arraySize) {
|
||||
val z = it - axisLimit
|
||||
cur?.getParcelById(x, z) ?: ParcelImpl(world, x, z)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getParcelById(x: Int, z: Int): Parcel? {
|
||||
return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit)
|
||||
}
|
||||
|
||||
override fun getParcelById(id: ParcelId): Parcel? {
|
||||
if (!world.id.equals(id.worldId)) throw IllegalArgumentException()
|
||||
return when (id) {
|
||||
is Parcel -> id
|
||||
else -> getParcelById(id.x, id.z)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun nextEmptyParcel(): Parcel? {
|
||||
return walkInCircle().find { it.owner == null }
|
||||
}
|
||||
|
||||
private fun walkInCircle(): Iterable<Parcel> = Iterable {
|
||||
iterator {
|
||||
val center = world.options.axisLimit
|
||||
yield(parcels[center][center])
|
||||
for (radius in 0..center) {
|
||||
var x = center - radius;
|
||||
var z = center - radius
|
||||
repeat(radius * 2) { yield(parcels[x++][z]) }
|
||||
repeat(radius * 2) { yield(parcels[x][z++]) }
|
||||
repeat(radius * 2) { yield(parcels[x--][z]) }
|
||||
repeat(radius * 2) { yield(parcels[x][z--]) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllParcels(): Iterator<Parcel> = iterator {
|
||||
for (array in parcels) {
|
||||
yieldAll(array.iterator())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +1,75 @@
|
||||
@file:Suppress("CanBePrimaryConstructorProperty", "UsePropertyAccessSyntax")
|
||||
|
||||
package io.dico.parcels2.defaultimpl
|
||||
|
||||
import io.dico.parcels2.*
|
||||
import io.dico.parcels2.options.RuntimeWorldOptions
|
||||
import io.dico.parcels2.storage.Storage
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.bukkit.GameRule
|
||||
import org.bukkit.World
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
class ParcelWorldImpl(
|
||||
val plugin: ParcelsPlugin,
|
||||
override val world: World,
|
||||
override val generator: ParcelGenerator,
|
||||
override var options: RuntimeWorldOptions,
|
||||
containerFactory: ParcelContainerFactory
|
||||
) : ParcelWorld, ParcelWorldId, ParcelContainer, ParcelLocator {
|
||||
override val id: ParcelWorldId get() = this
|
||||
override val uid: UUID? get() = world.uid
|
||||
|
||||
override val storage get() = plugin.storage
|
||||
override val globalPrivileges get() = plugin.globalPrivileges
|
||||
|
||||
init {
|
||||
if (generator.world != world) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
override val name: String = world.name!!
|
||||
override val container: ParcelContainer = containerFactory(this)
|
||||
override val locator: ParcelLocator
|
||||
override val blockManager: ParcelBlockManager
|
||||
|
||||
init {
|
||||
val (locator, blockManager) = generator.makeParcelLocatorAndBlockManager(plugin.parcelProvider, container, plugin, plugin.jobDispatcher)
|
||||
this.locator = locator
|
||||
this.blockManager = blockManager
|
||||
enforceOptions()
|
||||
}
|
||||
|
||||
fun enforceOptions() {
|
||||
if (options.dayTime) {
|
||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false)
|
||||
world.setTime(6000)
|
||||
}
|
||||
|
||||
if (options.noWeather) {
|
||||
world.setStorm(false)
|
||||
world.setThundering(false)
|
||||
world.weatherDuration = Int.MAX_VALUE
|
||||
}
|
||||
|
||||
world.setGameRule(GameRule.DO_TILE_DROPS, options.doTileDrops)
|
||||
}
|
||||
|
||||
// Accessed by ParcelProviderImpl
|
||||
override var creationTime: DateTime? = null
|
||||
|
||||
|
||||
override fun getParcelAt(x: Int, z: Int): Parcel? = locator.getParcelAt(x, z)
|
||||
|
||||
override fun getParcelIdAt(x: Int, z: Int): ParcelId? = locator.getParcelIdAt(x, z)
|
||||
|
||||
override fun getParcelById(x: Int, z: Int): Parcel? = container.getParcelById(x, z)
|
||||
|
||||
override fun getParcelById(id: ParcelId): Parcel? = container.getParcelById(id)
|
||||
|
||||
override fun nextEmptyParcel(): Parcel? = container.nextEmptyParcel()
|
||||
|
||||
override fun toString() = parcelWorldIdToString()
|
||||
}
|
||||
@file:Suppress("CanBePrimaryConstructorProperty", "UsePropertyAccessSyntax")
|
||||
|
||||
package io.dico.parcels2.defaultimpl
|
||||
|
||||
import io.dico.parcels2.*
|
||||
import io.dico.parcels2.options.RuntimeWorldOptions
|
||||
import io.dico.parcels2.storage.Storage
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.bukkit.GameRule
|
||||
import org.bukkit.World
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
class ParcelWorldImpl(
|
||||
val plugin: ParcelsPlugin,
|
||||
override val world: World,
|
||||
override val generator: ParcelGenerator,
|
||||
override var options: RuntimeWorldOptions,
|
||||
containerFactory: ParcelContainerFactory
|
||||
) : ParcelWorld, ParcelWorldId, ParcelContainer, ParcelLocator {
|
||||
override val id: ParcelWorldId get() = this
|
||||
override val uid: UUID? get() = world.uid
|
||||
|
||||
override val storage get() = plugin.storage
|
||||
override val globalPrivileges get() = plugin.globalPrivileges
|
||||
|
||||
init {
|
||||
if (generator.world != world) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
override val name: String = world.name!!
|
||||
override val container: ParcelContainer = containerFactory(this)
|
||||
override val locator: ParcelLocator
|
||||
override val blockManager: ParcelBlockManager
|
||||
|
||||
init {
|
||||
val (locator, blockManager) = generator.makeParcelLocatorAndBlockManager(plugin.parcelProvider, container, plugin, plugin.jobDispatcher)
|
||||
this.locator = locator
|
||||
this.blockManager = blockManager
|
||||
enforceOptions()
|
||||
}
|
||||
|
||||
fun enforceOptions() {
|
||||
if (options.dayTime) {
|
||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false)
|
||||
world.setTime(6000)
|
||||
}
|
||||
|
||||
if (options.noWeather) {
|
||||
world.setStorm(false)
|
||||
world.setThundering(false)
|
||||
world.weatherDuration = Int.MAX_VALUE
|
||||
}
|
||||
|
||||
world.setGameRule(GameRule.DO_TILE_DROPS, options.doTileDrops)
|
||||
}
|
||||
|
||||
// Accessed by ParcelProviderImpl
|
||||
override var creationTime: DateTime? = null
|
||||
|
||||
|
||||
override fun getParcelAt(x: Int, z: Int): Parcel? = locator.getParcelAt(x, z)
|
||||
|
||||
override fun getParcelIdAt(x: Int, z: Int): ParcelId? = locator.getParcelIdAt(x, z)
|
||||
|
||||
override fun getParcelById(x: Int, z: Int): Parcel? = container.getParcelById(x, z)
|
||||
|
||||
override fun getParcelById(id: ParcelId): Parcel? = container.getParcelById(id)
|
||||
|
||||
override suspend fun nextEmptyParcel(): Parcel? = container.nextEmptyParcel()
|
||||
|
||||
override fun toString() = parcelWorldIdToString()
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,79 +1,78 @@
|
||||
package io.dico.parcels2.listener
|
||||
|
||||
import com.sk89q.worldedit.EditSession.Stage.BEFORE_REORDER
|
||||
import com.sk89q.worldedit.Vector
|
||||
import com.sk89q.worldedit.Vector2D
|
||||
import com.sk89q.worldedit.WorldEdit
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent
|
||||
import com.sk89q.worldedit.extent.Extent
|
||||
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority.VERY_EARLY
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder
|
||||
import io.dico.parcels2.ParcelWorld
|
||||
import io.dico.parcels2.ParcelsPlugin
|
||||
import io.dico.parcels2.canBuildFast
|
||||
import io.dico.parcels2.util.ext.hasPermBuildAnywhere
|
||||
import io.dico.parcels2.util.ext.sendParcelMessage
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class WorldEditListener(val parcels: ParcelsPlugin, val worldEdit: WorldEdit) {
|
||||
|
||||
@Subscribe(priority = VERY_EARLY)
|
||||
fun onEditSession(event: EditSessionEvent) {
|
||||
val worldName = event.world?.name ?: return
|
||||
val world = parcels.parcelProvider.getWorld(worldName) ?: return
|
||||
if (event.stage == BEFORE_REORDER) return
|
||||
|
||||
val actor = event.actor
|
||||
if (actor == null || !actor.isPlayer) return
|
||||
|
||||
val player = parcels.server.getPlayer(actor.uniqueId)
|
||||
if (player.hasPermBuildAnywhere) return
|
||||
|
||||
event.extent = ParcelsExtent(event.extent, world, player)
|
||||
}
|
||||
|
||||
private class ParcelsExtent(extent: Extent,
|
||||
val world: ParcelWorld,
|
||||
val player: Player) : AbstractDelegateExtent(extent) {
|
||||
private var messageSent = false
|
||||
|
||||
private fun canBuild(x: Int, z: Int): Boolean {
|
||||
world.getParcelAt(x, z)?.let { parcel ->
|
||||
if (parcel.canBuildFast(player)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if (!messageSent) {
|
||||
messageSent = true
|
||||
player.sendParcelMessage(except = true, message = "You can't use WorldEdit there")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun setBlock(location: Vector, block: BlockStateHolder<*>): Boolean {
|
||||
return canBuild(location.blockX, location.blockZ) && super.setBlock(location, block)
|
||||
}
|
||||
|
||||
override fun setBiome(coord: Vector2D, biome: BaseBiome): Boolean {
|
||||
return canBuild(coord.blockX, coord.blockZ) && super.setBiome(coord, biome)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun register(parcels: ParcelsPlugin, worldEditPlugin: Plugin) {
|
||||
if (worldEditPlugin !is WorldEditPlugin) return
|
||||
val worldEdit = worldEditPlugin.worldEdit
|
||||
val listener = WorldEditListener(parcels, worldEdit)
|
||||
worldEdit.eventBus.register(listener)
|
||||
}
|
||||
}
|
||||
|
||||
package io.dico.parcels2.listener
|
||||
|
||||
import com.sk89q.worldedit.EditSession.Stage.BEFORE_REORDER
|
||||
import com.sk89q.worldedit.WorldEdit
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent
|
||||
import com.sk89q.worldedit.extent.Extent
|
||||
import com.sk89q.worldedit.math.BlockVector2
|
||||
import com.sk89q.worldedit.math.BlockVector3
|
||||
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority.VERY_EARLY
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder
|
||||
import io.dico.parcels2.ParcelWorld
|
||||
import io.dico.parcels2.ParcelsPlugin
|
||||
import io.dico.parcels2.canBuildFast
|
||||
import io.dico.parcels2.util.ext.hasPermBuildAnywhere
|
||||
import io.dico.parcels2.util.ext.sendParcelMessage
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class WorldEditListener(val parcels: ParcelsPlugin, val worldEdit: WorldEdit) {
|
||||
|
||||
@Subscribe(priority = VERY_EARLY)
|
||||
fun onEditSession(event: EditSessionEvent) {
|
||||
val worldName = event.world?.name ?: return
|
||||
val world = parcels.parcelProvider.getWorld(worldName) ?: return
|
||||
if (event.stage == BEFORE_REORDER) return
|
||||
|
||||
val actor = event.actor
|
||||
if (actor == null || !actor.isPlayer) return
|
||||
|
||||
val player = parcels.server.getPlayer(actor.uniqueId)
|
||||
if (player.hasPermBuildAnywhere) return
|
||||
|
||||
event.extent = ParcelsExtent(event.extent, world, player)
|
||||
}
|
||||
|
||||
private class ParcelsExtent(extent: Extent,
|
||||
val world: ParcelWorld,
|
||||
val player: Player) : AbstractDelegateExtent(extent) {
|
||||
private var messageSent = false
|
||||
|
||||
private fun canBuild(x: Int, z: Int): Boolean {
|
||||
world.getParcelAt(x, z)?.let { parcel ->
|
||||
if (parcel.canBuildFast(player)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if (!messageSent) {
|
||||
messageSent = true
|
||||
player.sendParcelMessage(except = true, message = "You can't use WorldEdit there")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun setBiome(coord: BlockVector2, biome: BaseBiome): Boolean {
|
||||
return canBuild(coord.blockX, coord.blockZ) && super.setBiome(coord, biome)
|
||||
}
|
||||
|
||||
override fun <T : BlockStateHolder<T>> setBlock(location: BlockVector3, block: T): Boolean {
|
||||
return canBuild(location.blockX, location.blockZ) && super.setBlock(location, block)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun register(parcels: ParcelsPlugin, worldEditPlugin: Plugin) {
|
||||
if (worldEditPlugin !is WorldEditPlugin) return
|
||||
val worldEdit = worldEditPlugin.worldEdit
|
||||
val listener = WorldEditListener(parcels, worldEdit)
|
||||
worldEdit.eventBus.register(listener)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
@file:Suppress("RedundantLambdaArrow")
|
||||
|
||||
package io.dico.parcels2.util
|
||||
|
||||
import org.bukkit.plugin.Plugin
|
||||
@@ -8,11 +10,10 @@ interface PluginAware {
|
||||
}
|
||||
|
||||
inline fun PluginAware.schedule(delay: Int = 0, crossinline task: () -> Unit): BukkitTask {
|
||||
return plugin.server.scheduler.runTaskLater(plugin, { task() }, delay.toLong())
|
||||
return plugin.server.scheduler.runTaskLater(plugin, { -> task() }, delay.toLong())
|
||||
}
|
||||
|
||||
inline fun PluginAware.scheduleRepeating(interval: Int, delay: Int = 0, crossinline task: () -> Unit): BukkitTask {
|
||||
return plugin.server.scheduler.runTaskTimer(plugin, { task() }, delay.toLong(), interval.toLong())
|
||||
return plugin.server.scheduler.runTaskTimer(plugin, { -> task() }, delay.toLong(), interval.toLong())
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package io.dico.parcels2.util
|
||||
|
||||
fun doParallel() {
|
||||
|
||||
val array = IntArray(1000)
|
||||
IntRange(0, 1000).chunked()
|
||||
|
||||
|
||||
}
|
||||
20
todo.md
20
todo.md
@@ -88,16 +88,16 @@ After testing on Redstoner
|
||||
-
|
||||
|
||||
~~Clear (and swap) entities on /p clear etc~~
|
||||
Fix command lag
|
||||
Chorus fruit can grow outside plots
|
||||
Vines can grow outside plots
|
||||
Ghasts, bats, phantoms and magma cubes can be spawned with eggs
|
||||
ParcelTarget doesn't report a world that wasn't found correctly
|
||||
Jumping on turtle eggs is considered as interacting with pressure plates
|
||||
~~Fix command lag~~
|
||||
Chorus fruit can grow outside plots -- not detectable?
|
||||
~~Vines can grow outside plots~~
|
||||
~~Ghasts, bats, phantoms and magma cubes can be spawned with eggs~~
|
||||
ParcelTarget doesn't report a world that wasn't found correctly -- ??
|
||||
~~Jumping on turtle eggs is considered as interacting with pressure plates~~
|
||||
Setbiome internal error when progress reporting is attached
|
||||
Unclaim doesn't clear the plot. It probably should.
|
||||
Players can shoot boats and minecarts.
|
||||
You can use disabled items by rightclicking air.
|
||||
Tab complete isn't working correctly.
|
||||
~~Unclaim doesn't clear the plot. It probably should.~~ removed
|
||||
Players can shoot boats and minecarts. -- ??
|
||||
~~You can use disabled items by rightclicking air.~~
|
||||
Tab complete isn't working correctly. -- disabled much of it now
|
||||
~~Bed use in nether and end might not have to be blocked.~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user