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" group "net.trivernis"
version "1.3.1"
version "1.3.2"
sourceCompatibility = 1.8 sourceCompatibility = 1.8

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

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

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

@ -36,6 +36,11 @@ class CmdSetCenter(private val chunkmaster: Chunkmaster) : Subcommand {
centerX = sender.location.chunk.x centerX = sender.location.chunk.x
centerZ = sender.location.chunk.z centerZ = sender.location.chunk.z
} }
args.size == 1 -> {
world = args[0]
centerX = sender.location.chunk.x
centerZ = sender.location.chunk.z
}
args.size == 2 -> { args.size == 2 -> {
world = sender.world.name world = sender.world.name
if (args[0].toIntOrNull() == null || args[1].toIntOrNull() == null) { 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 net.trivernis.chunkmaster.lib.generation.ChunkCoordinates
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import kotlin.math.ceil
class PendingChunks(private val sqliteManager: SqliteManager) { class PendingChunks(private val sqliteManager: SqliteManager) {
private val insertionCount = 300
/** /**
* Returns a list of pending chunks for a taskId * Returns a list of pending chunks for a taskId
*/ */
@ -30,10 +33,25 @@ class PendingChunks(private val sqliteManager: SqliteManager) {
return completableFuture 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 * 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>() val completableFuture = CompletableFuture<Void>()
if (pendingChunks.isEmpty()) { if (pendingChunks.isEmpty()) {
completableFuture.complete(null) completableFuture.complete(null)

@ -292,10 +292,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
private fun reportGenerationProgress(task: RunningTaskEntry) { private fun reportGenerationProgress(task: RunningTaskEntry) {
val genTask = task.generationTask val genTask = task.generationTask
val (speed, chunkSpeed) = task.generationSpeed 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 eta = if (speed!! > 0) {
val remaining = 1 - genTask.shape.progress() val remaining = 1 - progress
val etaSeconds = remaining / speed val etaSeconds = remaining / 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()

@ -18,8 +18,9 @@ class RunningTaskEntry(
get() { get() {
var generationSpeed: Double? = null var generationSpeed: Double? = null
var chunkGenerationSpeed: 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) { if (lastProgress != null) {
val progressDiff = generationTask.shape.progress() - lastProgress!!.second val progressDiff = progress - lastProgress!!.second
val timeDiff = (System.currentTimeMillis() - lastProgress!!.first).toDouble() / 1000 val timeDiff = (System.currentTimeMillis() - lastProgress!!.first).toDouble() / 1000
generationSpeed = progressDiff / timeDiff generationSpeed = progressDiff / timeDiff
} }
@ -28,13 +29,13 @@ class RunningTaskEntry(
val timeDiff = (System.currentTimeMillis() - lastChunkCount!!.first).toDouble() / 1000 val timeDiff = (System.currentTimeMillis() - lastChunkCount!!.first).toDouble() / 1000
chunkGenerationSpeed = chunkDiff / timeDiff chunkGenerationSpeed = chunkDiff / timeDiff
} }
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress()) lastProgress = Pair(System.currentTimeMillis(), progress)
lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count) lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count)
return Pair(generationSpeed, chunkGenerationSpeed) return Pair(generationSpeed, chunkGenerationSpeed)
} }
init { init {
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress()) lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress(null))
lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count) 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)) return (PI * radius.toFloat().pow(2))
} }
override fun progress(): Double { override fun progress(maxRadius: Int?): Double {
// TODO: Radius inner progress // 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 { 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 * Returns the progress of the shape
*/ */
abstract fun progress(): Double abstract fun progress(maxRadius: Int?): Double
/** /**
* The total number of chunks to generate * 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) return (radius * 2).toDouble().pow(2)
} }
override fun progress(): Double { override fun progress(maxRadius: Int?): Double {
return (count / (radius * 2).toDouble().pow(2)).coerceAtMost(1.0) 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 { override fun currentRadius(): Int {

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

Loading…
Cancel
Save