Merge pull request #95 from Trivernis/develop

Bug Fixes
pull/105/head v1.3.2
Trivernis 4 years ago committed by GitHub
commit a0f6f4832f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,7 +22,8 @@ idea {
}
group "net.trivernis"
version "1.3.1"
version "1.3.2"
sourceCompatibility = 1.8

@ -9,6 +9,8 @@ import org.bstats.bukkit.Metrics
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitTask
import org.dynmap.DynmapAPI
import java.lang.IllegalStateException
import java.lang.NullPointerException
class Chunkmaster : JavaPlugin() {
lateinit var sqliteManager: SqliteManager
@ -103,11 +105,15 @@ class Chunkmaster : JavaPlugin() {
}
private fun getDynmap(): DynmapAPI? {
val dynmap = server.pluginManager.getPlugin("dynmap")
return if (dynmap != null && dynmap is DynmapAPI) {
logger.info(langManager.getLocalized("PLUGIN_DETECTED", "dynmap", dynmap.dynmapVersion))
dynmap
} else {
return try {
val dynmap = server.pluginManager.getPlugin("dynmap")
if (dynmap != null && dynmap is DynmapAPI) {
logger.info(langManager.getLocalized("PLUGIN_DETECTED", "dynmap", dynmap.dynmapVersion))
dynmap
} else {
null
}
} catch (e: IllegalStateException) {
null
}
}

@ -41,8 +41,10 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server
if (chunkmaster.generationManager.tasks.isNotEmpty()) {
chunkmaster.logger.info(chunkmaster.langManager.getLocalized("PAUSE_PLAYER_JOIN"))
}
playerPaused = chunkmaster.generationManager.paused
chunkmaster.generationManager.pauseAll()
if (!chunkmaster.generationManager.paused) {
playerPaused = chunkmaster.generationManager.paused
chunkmaster.generationManager.pauseAll()
}
}
}
}

@ -6,6 +6,7 @@ import net.trivernis.chunkmaster.lib.generation.taskentry.TaskEntry
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import kotlin.math.ceil
import kotlin.math.pow
class CmdList(private val chunkmaster: Chunkmaster) : Subcommand {
override val name = "list"
@ -49,14 +50,13 @@ class CmdList(private val chunkmaster: Chunkmaster) : Subcommand {
*/
private fun getGenerationEntry(task: TaskEntry): String {
val genTask = task.generationTask
val percentage = if (genTask.radius > 0)
" (%.1f".format(genTask.shape.progress() * 100) + "%)."
else
""
val progress = genTask.shape.progress(if (genTask.radius < 0) (genTask.world.worldBorder.size / 32).toInt() else null)
val percentage = " (%.1f".format(progress * 100) + "%)."
val count = if (genTask.radius > 0) {
"${genTask.count} / ${ceil(genTask.shape.total()).toInt()}"
} else {
genTask.count.toString()
"${genTask.count} / worldborder"
}
return "\n" + chunkmaster.langManager.getLocalized(
"TASKS_ENTRY",

@ -36,6 +36,11 @@ class CmdSetCenter(private val chunkmaster: Chunkmaster) : Subcommand {
centerX = sender.location.chunk.x
centerZ = sender.location.chunk.z
}
args.size == 1 -> {
world = args[0]
centerX = sender.location.chunk.x
centerZ = sender.location.chunk.z
}
args.size == 2 -> {
world = sender.world.name
if (args[0].toIntOrNull() == null || args[1].toIntOrNull() == null) {

@ -2,8 +2,11 @@ package net.trivernis.chunkmaster.lib.database
import net.trivernis.chunkmaster.lib.generation.ChunkCoordinates
import java.util.concurrent.CompletableFuture
import kotlin.math.ceil
class PendingChunks(private val sqliteManager: SqliteManager) {
private val insertionCount = 300
/**
* Returns a list of pending chunks for a taskId
*/
@ -30,10 +33,25 @@ class PendingChunks(private val sqliteManager: SqliteManager) {
return completableFuture
}
fun addPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> {
val futures = ArrayList<CompletableFuture<Void>>()
val statementCount = ceil(pendingChunks.size.toDouble() / insertionCount).toInt()
for (i in 0 until statementCount) {
futures.add(insertPendingChunks(taskId, pendingChunks.subList(i * insertionCount, ((i * insertionCount) + insertionCount).coerceAtMost(pendingChunks.size))))
}
if (futures.size > 0) {
return CompletableFuture.allOf(*futures.toTypedArray())
} else {
return CompletableFuture.supplyAsync { null }
}
}
/**
* Adds pending chunks for a taskid
*/
fun addPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> {
private fun insertPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> {
val completableFuture = CompletableFuture<Void>()
if (pendingChunks.isEmpty()) {
completableFuture.complete(null)

@ -292,10 +292,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
private fun reportGenerationProgress(task: RunningTaskEntry) {
val genTask = task.generationTask
val (speed, chunkSpeed) = task.generationSpeed
val percentage = if (genTask.radius > 0) "(${"%.2f".format(genTask.shape.progress() * 100)}%)" else ""
val progress = genTask.shape.progress(if (genTask.radius < 0) (genTask.world.worldBorder.size / 32).toInt() else null)
val percentage =
"(${"%.2f".format(progress * 100)}%)"
val eta = if (genTask.radius > 0 && speed!! > 0) {
val remaining = 1 - genTask.shape.progress()
val eta = if (speed!! > 0) {
val remaining = 1 - progress
val etaSeconds = remaining / speed
val hours: Int = (etaSeconds / 3600).toInt()
val minutes: Int = ((etaSeconds % 3600) / 60).toInt()

@ -18,8 +18,9 @@ class RunningTaskEntry(
get() {
var generationSpeed: Double? = null
var chunkGenerationSpeed: Double? = null
val progress = generationTask.shape.progress(if (generationTask.radius < 0) (generationTask.world.worldBorder.size / 32).toInt() else null)
if (lastProgress != null) {
val progressDiff = generationTask.shape.progress() - lastProgress!!.second
val progressDiff = progress - lastProgress!!.second
val timeDiff = (System.currentTimeMillis() - lastProgress!!.first).toDouble() / 1000
generationSpeed = progressDiff / timeDiff
}
@ -28,13 +29,13 @@ class RunningTaskEntry(
val timeDiff = (System.currentTimeMillis() - lastChunkCount!!.first).toDouble() / 1000
chunkGenerationSpeed = chunkDiff / timeDiff
}
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress())
lastProgress = Pair(System.currentTimeMillis(), progress)
lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count)
return Pair(generationSpeed, chunkGenerationSpeed)
}
init {
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress())
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress(null))
lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count)
}

@ -20,9 +20,13 @@ class Circle(center: Pair<Int, Int>, start: Pair<Int, Int>, radius: Int) : Shape
return (PI * radius.toFloat().pow(2))
}
override fun progress(): Double {
override fun progress(maxRadius: Int?): Double {
// TODO: Radius inner progress
return (count / (PI * radius.toFloat().pow(2))).coerceAtMost(1.0)
return if (maxRadius != null) {
(count / (PI * maxRadius.toFloat().pow(2))).coerceAtMost(1.0)
} else {
(count / (PI * radius.toFloat().pow(2))).coerceAtMost(1.0)
}
}
override fun currentRadius(): Int {

@ -19,7 +19,7 @@ abstract class Shape(protected val center: Pair<Int, Int>, start: Pair<Int, Int>
/**
* Returns the progress of the shape
*/
abstract fun progress(): Double
abstract fun progress(maxRadius: Int?): Double
/**
* The total number of chunks to generate

@ -18,8 +18,12 @@ class Spiral(center: Pair<Int, Int>, start: Pair<Int, Int>, radius: Int) : Shape
return (radius * 2).toDouble().pow(2)
}
override fun progress(): Double {
return (count / (radius * 2).toDouble().pow(2)).coerceAtMost(1.0)
override fun progress(maxRadius: Int?): Double {
return if (maxRadius != null) {
(count / (maxRadius * 2).toDouble().pow(2)).coerceAtMost(1.0)
} else {
(count / (radius * 2).toDouble().pow(2)).coerceAtMost(1.0)
}
}
override fun currentRadius(): Int {

@ -1,6 +1,6 @@
main: net.trivernis.chunkmaster.Chunkmaster
name: Chunkmaster
version: '1.3.1'
version: '1.3.2'
description: Automated world pregeneration.
author: Trivernis
website: trivernis.net

Loading…
Cancel
Save