|
|
@ -4,7 +4,6 @@ import io.papermc.lib.PaperLib
|
|
|
|
import net.trivernis.chunkmaster.Chunkmaster
|
|
|
|
import net.trivernis.chunkmaster.Chunkmaster
|
|
|
|
import net.trivernis.chunkmaster.lib.shapes.Circle
|
|
|
|
import net.trivernis.chunkmaster.lib.shapes.Circle
|
|
|
|
import net.trivernis.chunkmaster.lib.shapes.Spiral
|
|
|
|
import net.trivernis.chunkmaster.lib.shapes.Spiral
|
|
|
|
import org.bukkit.Chunk
|
|
|
|
|
|
|
|
import org.bukkit.Server
|
|
|
|
import org.bukkit.Server
|
|
|
|
import org.bukkit.World
|
|
|
|
import org.bukkit.World
|
|
|
|
|
|
|
|
|
|
|
@ -35,7 +34,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Adds a generation task
|
|
|
|
* Adds a generation task
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
fun addTask(world: World, stopAfter: Int = -1): Int {
|
|
|
|
fun addTask(world: World, radius: Int = -1, shape: String = "square"): Int {
|
|
|
|
val foundTask = allTasks.find { it.generationTask.world == world }
|
|
|
|
val foundTask = allTasks.find { it.generationTask.world == world }
|
|
|
|
if (foundTask == null) {
|
|
|
|
if (foundTask == null) {
|
|
|
|
val centerChunk = if (worldCenters[world.name] == null) {
|
|
|
|
val centerChunk = if (worldCenters[world.name] == null) {
|
|
|
@ -44,12 +43,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
val center = worldCenters[world.name]!!
|
|
|
|
val center = worldCenters[world.name]!!
|
|
|
|
ChunkCoordinates(center.first, center.second)
|
|
|
|
ChunkCoordinates(center.first, center.second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val generationTask = createGenerationTask(world, centerChunk, centerChunk, stopAfter)
|
|
|
|
val generationTask = createGenerationTask(world, centerChunk, centerChunk, radius, shape)
|
|
|
|
|
|
|
|
|
|
|
|
chunkmaster.sqliteManager.executeStatement(
|
|
|
|
chunkmaster.sqliteManager.executeStatement(
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
INSERT INTO generation_tasks (center_x, center_z, last_x, last_z, world, stop_after)
|
|
|
|
INSERT INTO generation_tasks (center_x, center_z, last_x, last_z, world, radius, shape)
|
|
|
|
values (?, ?, ?, ?, ?, ?)
|
|
|
|
values (?, ?, ?, ?, ?, ?, ?)
|
|
|
|
""",
|
|
|
|
""",
|
|
|
|
HashMap(
|
|
|
|
HashMap(
|
|
|
|
mapOf(
|
|
|
|
mapOf(
|
|
|
@ -58,7 +57,8 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
3 to centerChunk.x,
|
|
|
|
3 to centerChunk.x,
|
|
|
|
4 to centerChunk.z,
|
|
|
|
4 to centerChunk.z,
|
|
|
|
5 to world.name,
|
|
|
|
5 to world.name,
|
|
|
|
6 to stopAfter
|
|
|
|
6 to radius,
|
|
|
|
|
|
|
|
7 to shape
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
null
|
|
|
|
null
|
|
|
@ -101,14 +101,15 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
center: ChunkCoordinates,
|
|
|
|
center: ChunkCoordinates,
|
|
|
|
last: ChunkCoordinates,
|
|
|
|
last: ChunkCoordinates,
|
|
|
|
id: Int,
|
|
|
|
id: Int,
|
|
|
|
stopAfter: Int = -1,
|
|
|
|
radius: Int = -1,
|
|
|
|
delay: Long = 200L
|
|
|
|
delay: Long = 200L,
|
|
|
|
|
|
|
|
shape: String = "square"
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if (!paused) {
|
|
|
|
if (!paused) {
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("RESUME_FOR_WORLD", world.name))
|
|
|
|
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("RESUME_FOR_WORLD", world.name))
|
|
|
|
val generationTask = createGenerationTask(world, center, last, stopAfter)
|
|
|
|
val generationTask = createGenerationTask(world, center, last, radius, shape)
|
|
|
|
val task = server.scheduler.runTaskTimer(
|
|
|
|
val task = server.scheduler.runTaskTimer(
|
|
|
|
chunkmaster, generationTask, delay, // 10 sec delay
|
|
|
|
chunkmaster, generationTask, delay,
|
|
|
|
chunkmaster.config.getLong("generation.period")
|
|
|
|
chunkmaster.config.getLong("generation.period")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
@ -163,7 +164,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
if (!server.onlinePlayers.isEmpty()) {
|
|
|
|
if (!server.onlinePlayers.isEmpty()) {
|
|
|
|
this.pauseAll()
|
|
|
|
this.pauseAll()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 600)
|
|
|
|
}, 20)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -199,9 +200,10 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
val world = server.getWorld(res.getString("world"))
|
|
|
|
val world = server.getWorld(res.getString("world"))
|
|
|
|
val center = ChunkCoordinates(res.getInt("center_x"), res.getInt("center_z"))
|
|
|
|
val center = ChunkCoordinates(res.getInt("center_x"), res.getInt("center_z"))
|
|
|
|
val last = ChunkCoordinates(res.getInt("last_x"), res.getInt("last_z"))
|
|
|
|
val last = ChunkCoordinates(res.getInt("last_x"), res.getInt("last_z"))
|
|
|
|
val stopAfter = res.getInt("stop_after")
|
|
|
|
val radius = res.getInt("radius")
|
|
|
|
|
|
|
|
val shape = res.getString("shape")
|
|
|
|
if (this.tasks.find { it.id == id } == null) {
|
|
|
|
if (this.tasks.find { it.id == id } == null) {
|
|
|
|
resumeTask(world!!, center, last, id, stopAfter, 200L + count)
|
|
|
|
resumeTask(world!!, center, last, id, radius, 200L + count, shape)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error: NullPointerException) {
|
|
|
|
} catch (error: NullPointerException) {
|
|
|
|
chunkmaster.logger.severe(chunkmaster.langManager.getLocalized("TASK_LOAD_FAILED", res.getInt("id")))
|
|
|
|
chunkmaster.logger.severe(chunkmaster.langManager.getLocalized("TASK_LOAD_FAILED", res.getInt("id")))
|
|
|
@ -286,12 +288,10 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
for (task in tasks) {
|
|
|
|
for (task in tasks) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
val genTask = task.generationTask
|
|
|
|
val genTask = task.generationTask
|
|
|
|
val speed = task.generationSpeed!!
|
|
|
|
val (speed, chunkSpeed) = task.generationSpeed
|
|
|
|
val percentage = if (genTask.stopAfter > 0) "(${"%.2f".format(
|
|
|
|
val percentage = if (genTask.radius > 0) "(${"%.2f".format(genTask.shape.progress() * 100)}%)" else ""
|
|
|
|
(genTask.count.toDouble() / genTask.stopAfter.toDouble()) * 100
|
|
|
|
val eta = if (genTask.radius > 0 && speed!! > 0) {
|
|
|
|
)}%)" else ""
|
|
|
|
val etaSeconds = (genTask.shape.progress())/speed
|
|
|
|
val eta = if (genTask.stopAfter > 0 && speed > 0) {
|
|
|
|
|
|
|
|
val etaSeconds = (genTask.stopAfter - genTask.count).toDouble()/speed
|
|
|
|
|
|
|
|
val hours: Int = (etaSeconds/3600).toInt()
|
|
|
|
val hours: Int = (etaSeconds/3600).toInt()
|
|
|
|
val minutes: Int = ((etaSeconds % 3600) / 60).toInt()
|
|
|
|
val minutes: Int = ((etaSeconds % 3600) / 60).toInt()
|
|
|
|
val seconds: Int = (etaSeconds % 60).toInt()
|
|
|
|
val seconds: Int = (etaSeconds % 60).toInt()
|
|
|
@ -306,7 +306,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
genTask.count,
|
|
|
|
genTask.count,
|
|
|
|
percentage,
|
|
|
|
percentage,
|
|
|
|
eta,
|
|
|
|
eta,
|
|
|
|
speed,
|
|
|
|
chunkSpeed!!,
|
|
|
|
genTask.lastChunk.x,
|
|
|
|
genTask.lastChunk.x,
|
|
|
|
genTask.lastChunk.z))
|
|
|
|
genTask.lastChunk.z))
|
|
|
|
saveProgressToDatabase(genTask.lastChunkCoords, task.id)
|
|
|
|
saveProgressToDatabase(genTask.lastChunkCoords, task.id)
|
|
|
@ -339,13 +339,19 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
world: World,
|
|
|
|
world: World,
|
|
|
|
center: ChunkCoordinates,
|
|
|
|
center: ChunkCoordinates,
|
|
|
|
start: ChunkCoordinates,
|
|
|
|
start: ChunkCoordinates,
|
|
|
|
stopAfter: Int
|
|
|
|
radius: Int,
|
|
|
|
|
|
|
|
shapeName: String
|
|
|
|
): GenerationTask {
|
|
|
|
): GenerationTask {
|
|
|
|
val shape = Spiral(Pair(center.x, center.z), Pair(center.x, center.z))
|
|
|
|
val shape = when (shapeName) {
|
|
|
|
|
|
|
|
"circle" -> Circle(Pair(center.x, center.z), Pair(center.x, center.z), radius)
|
|
|
|
|
|
|
|
"square" -> Spiral(Pair(center.x, center.z), Pair(center.x, center.z), radius)
|
|
|
|
|
|
|
|
else -> Spiral(Pair(center.x, center.z), Pair(center.x, center.z), radius)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return if (PaperLib.isPaper()) {
|
|
|
|
return if (PaperLib.isPaper()) {
|
|
|
|
GenerationTaskPaper(chunkmaster, world, center, start, stopAfter, shape)
|
|
|
|
GenerationTaskPaper(chunkmaster, world, start, radius, shape)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
GenerationTaskSpigot(chunkmaster, world, center, start, stopAfter, shape)
|
|
|
|
GenerationTaskSpigot(chunkmaster, world, center, start, radius, shape)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|