Add completed command to list completed tasks
Signed-off-by: trivernis <trivernis@protonmail.com>pull/109/head
parent
90f2bbc2af
commit
e545445348
@ -1,2 +1,2 @@
|
||||
kotlin.code.style=official
|
||||
PLUGIN_VERSION=1.3.4
|
||||
PLUGIN_VERSION=1.4.0
|
@ -0,0 +1,44 @@
|
||||
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
|
||||
|
||||
class CmdCompleted(private val plugin: Chunkmaster) : Subcommand {
|
||||
override val name = "completed"
|
||||
|
||||
override fun execute(sender: CommandSender, args: List<String>): Boolean {
|
||||
plugin.sqliteManager.completedGenerationTasks.getCompletedTasks().thenAccept { tasks ->
|
||||
val worlds = tasks.map { it.world }.toHashSet()
|
||||
var response = "\n" + plugin.langManager.getLocalized("COMPLETED_TASKS_HEADER") + "\n\n"
|
||||
|
||||
for (world in worlds) {
|
||||
response += plugin.langManager.getLocalized("COMPLETED_WORLD_HEADER", world) + "\n"
|
||||
|
||||
for (task in tasks.filter { it.world == world }) {
|
||||
response += plugin.langManager.getLocalized(
|
||||
"COMPLETED_TASK_ENTRY",
|
||||
task.id,
|
||||
task.radius,
|
||||
task.center.x,
|
||||
task.center.z,
|
||||
task.shape
|
||||
) + "\n"
|
||||
}
|
||||
response += "\n"
|
||||
}
|
||||
sender.sendMessage(response)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onTabComplete(
|
||||
sender: CommandSender,
|
||||
command: Command,
|
||||
alias: String,
|
||||
args: List<String>
|
||||
): MutableList<String> {
|
||||
return mutableListOf()
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package net.trivernis.chunkmaster.lib.database
|
||||
|
||||
import net.trivernis.chunkmaster.lib.generation.ChunkCoordinates
|
||||
|
||||
data class CompletedGenerationTask (val id: Int, val world: String, val radius: Int, val center: ChunkCoordinates, val shape: String)
|
@ -0,0 +1,68 @@
|
||||
package net.trivernis.chunkmaster.lib.database
|
||||
|
||||
import net.trivernis.chunkmaster.lib.generation.ChunkCoordinates
|
||||
import java.sql.ResultSet
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class CompletedGenerationTasks(private val sqliteManager: SqliteManager) {
|
||||
/**
|
||||
* Returns the list of all completed tasks
|
||||
*/
|
||||
fun getCompletedTasks(): CompletableFuture<List<CompletedGenerationTask>> {
|
||||
val completableFuture = CompletableFuture<List<CompletedGenerationTask>>()
|
||||
|
||||
sqliteManager.executeStatement("SELECT * FROM completed_generation_tasks", HashMap()) { res ->
|
||||
val tasks = ArrayList<CompletedGenerationTask>()
|
||||
|
||||
while (res!!.next()) {
|
||||
tasks.add(mapSqlResponseToWrapperObject(res))
|
||||
}
|
||||
completableFuture.complete(tasks)
|
||||
}
|
||||
return completableFuture
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of completed tasks for a world
|
||||
*/
|
||||
fun getCompletedTasksForWorld(world: String): CompletableFuture<List<CompletedGenerationTask>> {
|
||||
val completableFuture = CompletableFuture<List<CompletedGenerationTask>>()
|
||||
|
||||
sqliteManager.executeStatement("SELECT * FROM completed_generation_tasks WHERE world = ?", hashMapOf(1 to world)) { res ->
|
||||
val tasks = ArrayList<CompletedGenerationTask>()
|
||||
|
||||
while (res!!.next()) {
|
||||
tasks.add(mapSqlResponseToWrapperObject(res))
|
||||
}
|
||||
completableFuture.complete(tasks)
|
||||
}
|
||||
return completableFuture
|
||||
}
|
||||
|
||||
private fun mapSqlResponseToWrapperObject(res: ResultSet): CompletedGenerationTask {
|
||||
val id = res.getInt("id")
|
||||
val world = res.getString("world")
|
||||
val center = ChunkCoordinates(res.getInt("center_x"), res.getInt("center_z"))
|
||||
val radius = res.getInt("completed_radius")
|
||||
val shape = res.getString("shape")
|
||||
return CompletedGenerationTask(id, world, radius, center, shape)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a completed task
|
||||
*/
|
||||
fun addCompletedTask(id: Int, world: String, radius: Int, center: ChunkCoordinates, shape: String): CompletableFuture<Void> {
|
||||
val completableFuture = CompletableFuture<Void>()
|
||||
sqliteManager.executeStatement("INSERT INTO completed_generation_tasks (id, world, completed_radius, center_x, center_z, shape) VALUES (?, ?, ?, ?, ?, ?)", hashMapOf(
|
||||
1 to id,
|
||||
2 to world,
|
||||
3 to radius,
|
||||
4 to center.x,
|
||||
5 to center.z,
|
||||
6 to shape,
|
||||
)) {
|
||||
completableFuture.complete(null)
|
||||
}
|
||||
return completableFuture
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package net.trivernis.chunkmaster.lib.shapes
|
||||
|
||||
import io.kotest.matchers.booleans.shouldBeTrue
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
import io.kotest.matchers.shouldBe
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
class SpiralTest {
|
||||
|
||||
private val spiral = Spiral(center = Pair(0, 0), radius = 2, start = Pair(0, 0))
|
||||
|
||||
@BeforeEach
|
||||
fun init() {
|
||||
spiral.reset()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it generates coordinates`() {
|
||||
spiral.next().shouldBe(Pair(0, 0))
|
||||
spiral.next().shouldBe(Pair(0, 1))
|
||||
spiral.next().shouldBe(Pair(1, 1))
|
||||
spiral.next().shouldBe(Pair(1, 0))
|
||||
spiral.next().shouldBe(Pair(1, -1))
|
||||
spiral.next().shouldBe(Pair(0, -1))
|
||||
spiral.next().shouldBe(Pair(-1, -1))
|
||||
spiral.next().shouldBe(Pair(-1, 0))
|
||||
spiral.next().shouldBe(Pair(-1, 1))
|
||||
spiral.next().shouldBe(Pair(-1, 2))
|
||||
spiral.next().shouldBe(Pair(0, 2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports when reaching the end`() {
|
||||
for (i in 1..25) {
|
||||
spiral.next()
|
||||
}
|
||||
spiral.endReached().shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports the radius`() {
|
||||
for (i in 1..9) {
|
||||
spiral.next()
|
||||
}
|
||||
spiral.currentRadius().shouldBe(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the right edges`() {
|
||||
spiral.getShapeEdgeLocations().shouldContainAll(listOf(Pair(2, 2), Pair(-2, 2), Pair(2, -2), Pair(-2, -2)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the progress`() {
|
||||
spiral.progress(2).shouldBe(0)
|
||||
for (i in 1..8) {
|
||||
spiral.next()
|
||||
}
|
||||
spiral.progress(2).shouldBe(0.5)
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package net.trivernis.chunkmaster.lib.shapes
|
||||
|
||||
import io.kotest.matchers.booleans.shouldBeTrue
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
import io.kotest.matchers.shouldBe
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
class SquareTest {
|
||||
|
||||
private val square = Square(center = Pair(0, 0), radius = 2, start = Pair(0, 0))
|
||||
|
||||
@BeforeEach
|
||||
fun init() {
|
||||
square.reset()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it generates coordinates`() {
|
||||
square.next().shouldBe(Pair(0, 0))
|
||||
square.next().shouldBe(Pair(0, 1))
|
||||
square.next().shouldBe(Pair(1, 1))
|
||||
square.next().shouldBe(Pair(1, 0))
|
||||
square.next().shouldBe(Pair(1, -1))
|
||||
square.next().shouldBe(Pair(0, -1))
|
||||
square.next().shouldBe(Pair(-1, -1))
|
||||
square.next().shouldBe(Pair(-1, 0))
|
||||
square.next().shouldBe(Pair(-1, 1))
|
||||
square.next().shouldBe(Pair(-1, 2))
|
||||
square.next().shouldBe(Pair(0, 2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports when reaching the end`() {
|
||||
for (i in 1..25) {
|
||||
square.next()
|
||||
}
|
||||
square.endReached().shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it reports the radius`() {
|
||||
for (i in 1..9) {
|
||||
square.next()
|
||||
}
|
||||
square.currentRadius().shouldBe(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the right edges`() {
|
||||
square.getShapeEdgeLocations().shouldContainAll(listOf(Pair(2, 2), Pair(-2, 2), Pair(2, -2), Pair(-2, -2)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `it returns the progress`() {
|
||||
square.progress(2).shouldBe(0)
|
||||
for (i in 1..8) {
|
||||
square.next()
|
||||
}
|
||||
square.progress(2).shouldBe(0.5)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue