Add command to set and get the center
- Add getCenter command to get the center of the world used for generation - Add setCenter to set the world center for generation tasks. If there is already a task running for the world the center for that task will not be affected. - Fix SQL problem with multiple queries at the same time creating new connections - Add translations for new commands - Add Examples to Readme - Add new table to safe world centers - Add query to Generation manager to get the center of the world for new generation taskspull/29/head
parent
bdac496ce2
commit
832b1c4b55
@ -0,0 +1,65 @@
|
|||||||
|
package net.trivernis.chunkmaster.commands
|
||||||
|
|
||||||
|
import net.trivernis.chunkmaster.Chunkmaster
|
||||||
|
import net.trivernis.chunkmaster.lib.Subcommand
|
||||||
|
import org.bukkit.command.Command
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
|
class CmdGetCenter(private val chunkmaster: Chunkmaster): Subcommand {
|
||||||
|
override val name = "getCenter";
|
||||||
|
|
||||||
|
override fun onTabComplete(
|
||||||
|
sender: CommandSender,
|
||||||
|
command: Command,
|
||||||
|
alias: String,
|
||||||
|
args: List<String>
|
||||||
|
): MutableList<String> {
|
||||||
|
if (args.size == 1) {
|
||||||
|
return sender.server.worlds.filter { it.name.indexOf(args[0]) == 0 }
|
||||||
|
.map {it.name}.toMutableList()
|
||||||
|
}
|
||||||
|
return emptyList<String>().toMutableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun execute(sender: CommandSender, args: List<String>): Boolean {
|
||||||
|
val worldName: String = if (sender is Player) {
|
||||||
|
if (args.isNotEmpty()) {
|
||||||
|
args[0]
|
||||||
|
} else {
|
||||||
|
sender.world.name;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("WORLD_NAME_REQUIRED"))
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
args[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (chunkmaster.generationManager.worldCenters.isEmpty()) {
|
||||||
|
chunkmaster.generationManager.loadWorldCenters() {
|
||||||
|
sendCenterInfo(sender, worldName)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
sendCenterInfo(sender, worldName)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the center information
|
||||||
|
*/
|
||||||
|
private fun sendCenterInfo(sender: CommandSender, worldName: String) {
|
||||||
|
var center = chunkmaster.generationManager.worldCenters[worldName]
|
||||||
|
if (center == null) {
|
||||||
|
val world = sender.server.worlds.find { it.name == worldName }
|
||||||
|
if (world == null) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("WORLD_NOT_FOUND", worldName))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
center = Pair(world.spawnLocation.chunk.x, world.spawnLocation.chunk.z)
|
||||||
|
}
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("CENTER_INFO", worldName, center.first, center.second))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package net.trivernis.chunkmaster.commands
|
||||||
|
|
||||||
|
import net.trivernis.chunkmaster.Chunkmaster
|
||||||
|
import net.trivernis.chunkmaster.lib.Subcommand
|
||||||
|
import org.bukkit.command.Command
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
|
class CmdSetCenter(private val chunkmaster: Chunkmaster): Subcommand {
|
||||||
|
override val name = "setCenter";
|
||||||
|
|
||||||
|
override fun onTabComplete(
|
||||||
|
sender: CommandSender,
|
||||||
|
command: Command,
|
||||||
|
alias: String,
|
||||||
|
args: List<String>
|
||||||
|
): MutableList<String> {
|
||||||
|
if (args.size == 1) {
|
||||||
|
if (args[0].toIntOrNull() == null) {
|
||||||
|
return sender.server.worlds.filter { it.name.indexOf(args[0]) == 0 }
|
||||||
|
.map {it.name}.toMutableList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emptyList<String>().toMutableList();
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun execute(sender: CommandSender, args: List<String>): Boolean {
|
||||||
|
val world: String
|
||||||
|
val centerX: Int
|
||||||
|
val centerZ: Int
|
||||||
|
|
||||||
|
if (args.size < 2) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("TOO_FEW_ARGUMENTS"))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (sender is Player) {
|
||||||
|
if (args.size == 2) {
|
||||||
|
world = sender.world.name
|
||||||
|
if (args[0].toIntOrNull() == null || args[1].toIntOrNull() == null) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("COORD_INVALID", args[0], args[1]))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
centerX = args[0].toInt()
|
||||||
|
centerZ = args[1].toInt()
|
||||||
|
} else {
|
||||||
|
if (!validateThreeArgs(sender, args)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
world = args[0]
|
||||||
|
centerX = args[1].toInt()
|
||||||
|
centerZ = args[2].toInt()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (args.size < 3) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("TOO_FEW_ARGUMENTS"))
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
if (!validateThreeArgs(sender, args)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
world = args[0]
|
||||||
|
centerX = args[1].toInt()
|
||||||
|
centerZ = args[2].toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chunkmaster.generationManager.updateWorldCenter(world, Pair(centerX, centerZ))
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("CENTER_UPDATED", world, centerX, centerZ))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the command values with three arguments
|
||||||
|
*/
|
||||||
|
private fun validateThreeArgs(sender: CommandSender, args: List<String>): Boolean {
|
||||||
|
return if (sender.server.worlds.none { it.name == args[0] }) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("WORLD_NOT_FOUND", args[0]))
|
||||||
|
false
|
||||||
|
} else if (args[1].toIntOrNull() == null || args[2].toIntOrNull() == null) {
|
||||||
|
sender.sendMessage(chunkmaster.langManager.getLocalized("COORD_INVALID", args[1], args[2]))
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue