Fix bugs
This commit is contained in:
@@ -4,10 +4,10 @@ import io.dico.dicore.command.CommandException
|
||||
import io.dico.dicore.command.ExecutionContext
|
||||
import io.dico.dicore.command.ICommandReceiver
|
||||
import io.dico.parcels2.ParcelOwner
|
||||
import io.dico.parcels2.ParcelWorld
|
||||
import io.dico.parcels2.ParcelsPlugin
|
||||
import io.dico.parcels2.util.hasAdminManage
|
||||
import io.dico.parcels2.util.parcelLimit
|
||||
import io.dico.parcels2.util.uuid
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.lang.reflect.Method
|
||||
@@ -29,9 +29,10 @@ abstract class AbstractParcelCommands(val plugin: ParcelsPlugin) : ICommandRecei
|
||||
if (!plugin.storage.isConnected) error("Parcels cannot $action right now because of a database error")
|
||||
}
|
||||
|
||||
protected suspend fun checkParcelLimit(player: Player) {
|
||||
protected suspend fun checkParcelLimit(player: Player, world: ParcelWorld) {
|
||||
if (player.hasAdminManage) return
|
||||
val numOwnedParcels = plugin.storage.getNumParcels(ParcelOwner(uuid = player.uuid)).await()
|
||||
val numOwnedParcels = plugin.storage.getOwnedParcels(ParcelOwner(player)).await()
|
||||
.filter { it.world.world == world.world }.size
|
||||
|
||||
val limit = player.parcelLimit
|
||||
if (numOwnedParcels >= limit) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class CommandsAddedStatus(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin
|
||||
shortVersion = "allows a player to build on this parcel")
|
||||
@ParcelRequire(owner = true)
|
||||
fun ParcelScope.cmdAllow(sender: Player, player: OfflinePlayer): Any? {
|
||||
Validate.isTrue(parcel.owner != null && !sender.hasAdminManage, "This parcel is unowned")
|
||||
Validate.isTrue(parcel.owner != null || sender.hasAdminManage, "This parcel is unowned")
|
||||
Validate.isTrue(!parcel.owner!!.matches(player), "The target already owns the parcel")
|
||||
Validate.isTrue(parcel.allow(player), "${player.name} is already allowed to build on this parcel")
|
||||
return "${player.name} is now allowed to build on this parcel"
|
||||
@@ -37,7 +37,7 @@ class CommandsAddedStatus(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin
|
||||
shortVersion = "bans a player from this parcel")
|
||||
@ParcelRequire(owner = true)
|
||||
fun ParcelScope.cmdBan(sender: Player, player: OfflinePlayer): Any? {
|
||||
Validate.isTrue(parcel.owner != null && !sender.hasAdminManage, "This parcel is unowned")
|
||||
Validate.isTrue(parcel.owner != null || sender.hasAdminManage, "This parcel is unowned")
|
||||
Validate.isTrue(!parcel.owner!!.matches(player), "The owner cannot be banned from the parcel")
|
||||
Validate.isTrue(parcel.ban(player), "${player.name} is already banned from this parcel")
|
||||
return "${player.name} is now banned from this parcel"
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
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.annotation.Cmd
|
||||
import io.dico.parcels2.ParcelsPlugin
|
||||
import io.dico.parcels2.blockvisitor.RegionTraversal
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
import java.util.*
|
||||
|
||||
class CommandsDebug(val plugin: ParcelsPlugin) {
|
||||
class CommandsDebug(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
|
||||
@Cmd("reloadoptions")
|
||||
fun reloadOptions() {
|
||||
@@ -23,4 +28,23 @@ class CommandsDebug(val plugin: ParcelsPlugin) {
|
||||
return "Teleported you to $worldName spawn"
|
||||
}
|
||||
|
||||
@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.UPWARD) { 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))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,16 +8,12 @@ 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.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,7 +22,7 @@ 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")
|
||||
@@ -58,7 +54,7 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
|
||||
val ownedParcels = ownedParcelsResult
|
||||
.map { worlds.getParcelBySerializedValue(it) }
|
||||
.filter { it != null && ownerTarget.world == it.world && ownerTarget.owner == it.owner }
|
||||
.filter { it != null && ownerTarget.world == it.world }
|
||||
|
||||
val targetMatch = ownedParcels.getOrNull(target.index)
|
||||
?: error("The specified parcel could not be matched")
|
||||
@@ -76,11 +72,19 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
error(if (it.matches(player)) "You already own this parcel" else "This parcel is not available")
|
||||
}
|
||||
|
||||
checkParcelLimit(player)
|
||||
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, @Flag sure: Boolean): Any? {
|
||||
@@ -101,23 +105,4 @@ class CommandsGeneral(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
TODO()
|
||||
}
|
||||
|
||||
@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))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
|
||||
return CommandBuilder()
|
||||
.setChatController(ParcelsChatController())
|
||||
.addParameterType(false, ParcelParameterType(plugin.worlds))
|
||||
.addParameterType(true, ParcelHomeParameterType(plugin.worlds))
|
||||
.addParameterType(true, ParcelTarget.PType(plugin.worlds))
|
||||
|
||||
.group("parcel", "plot", "plots", "p")
|
||||
.registerCommands(CommandsGeneral(plugin))
|
||||
|
||||
Reference in New Issue
Block a user