Change group for Chunkmaster dynmap markers

- Change the group to "Chunkmaster" to be able to disable all of those markers.
- Add a marker that displays the last chunk that has been generated and refreshes
every 30 seconds.
pull/55/head
trivernis 5 years ago
parent d967dfd06d
commit 53aec18a06

@ -9,7 +9,6 @@ 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 org.dynmap.DynmapCommonAPI
import java.lang.Exception import java.lang.Exception
class Chunkmaster: JavaPlugin() { class Chunkmaster: JavaPlugin() {

@ -1,4 +1,30 @@
package net.trivernis.chunkmaster.lib.dynmap package net.trivernis.chunkmaster.lib.dynmap
class DynmapApiWrapper { import org.dynmap.DynmapAPI
class DynmapApiWrapper(private val dynmapAPI: DynmapAPI) {
/**
* Returns a marker set by name
*/
fun getMarkerSet(name: String): ExtendedMarkerSet? {
val set = dynmapAPI.markerAPI?.getMarkerSet(name)
return if (set != null) {
ExtendedMarkerSet(set)
} else {
null
}
}
fun getCreateMarkerSet(id: String, name: String): ExtendedMarkerSet? {
var set = dynmapAPI.markerAPI?.getMarkerSet(id)
if (set == null) {
set = dynmapAPI.markerAPI?.createMarkerSet(id, name, null, true)
}
return if (set != null) {
ExtendedMarkerSet(set)
} else {
null
}
}
} }

@ -0,0 +1,63 @@
package net.trivernis.chunkmaster.lib.dynmap
import org.bukkit.Location
import org.dynmap.markers.AreaMarker
import org.dynmap.markers.Marker
import org.dynmap.markers.MarkerSet
class ExtendedMarkerSet(private val markerSet: MarkerSet) {
/**
* Creates or updates an area marker depending on if it exists
* @param id - the unique id of the area marker
* @param label - the label that is displayed when clicking on the marker
* @param l1 - the top left corner
* @param l2 - the bottom right corner
*/
fun creUpdateAreMarker(id: String, label: String, l1: Location, l2: Location, style: MarkerStyle?): AreaMarker {
var marker = markerSet.findAreaMarker(id)
if (marker != null) {
marker.setCornerLocations(
doubleArrayOf(l1.x, l2.x),
doubleArrayOf(l1.z, l2.z)
)
} else {
marker = markerSet.createAreaMarker(
id,
label,
false,
l1.world.name,
doubleArrayOf(l1.x, l2.x),
doubleArrayOf(l1.z, l2.z),
true
)
}
if (style != null) {
marker.boostFlag = style.boostFlag
if (style.lineStyle != null) {
marker.setLineStyle(style.lineStyle.weight, style.lineStyle.opacity, style.lineStyle.color)
}
if (style.fillStyle != null) {
marker.setFillStyle(style.fillStyle.opacity, style.fillStyle.color)
}
}
return marker
}
/**
* Returns the area marker for an id
* @param id - the id of the marker
*/
fun findAreaMarker(id: String): AreaMarker? {
return markerSet.findAreaMarker(id)
}
/**
* Deletes an area marker
* @param id - the id of the marker
*/
fun deleteAreaMarker(id: String) {
val marker = this.findAreaMarker(id)
marker?.deleteMarker()
}
}

@ -0,0 +1,3 @@
package net.trivernis.chunkmaster.lib.dynmap
data class FillStyle(val opacity: Double, val color: Int)

@ -0,0 +1,3 @@
package net.trivernis.chunkmaster.lib.dynmap
data class LineStyle(val weight: Int, val opacity: Double, val color: Int)

@ -0,0 +1,5 @@
package net.trivernis.chunkmaster.lib.dynmap
import org.dynmap.markers.MarkerIcon
data class MarkerStyle(val icon: MarkerIcon?, val lineStyle: LineStyle?, val fillStyle: FillStyle?, val boostFlag: Boolean = false)

@ -308,6 +308,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
genTask.lastChunk.x, genTask.lastChunk.x,
genTask.lastChunk.z)) genTask.lastChunk.z))
saveProgressToDatabase(genTask.lastChunkCoords, task.id) saveProgressToDatabase(genTask.lastChunkCoords, task.id)
genTask.updateLastChunkMarker()
} catch (error: Exception) { } catch (error: Exception) {
chunkmaster.logger.warning(chunkmaster.langManager.getLocalized("TASK_SAVE_FAILED", error.toString())) chunkmaster.logger.warning(chunkmaster.langManager.getLocalized("TASK_SAVE_FAILED", error.toString()))
} }

@ -2,8 +2,8 @@ package net.trivernis.chunkmaster.lib.generation
import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.Chunkmaster
import net.trivernis.chunkmaster.lib.Spiral import net.trivernis.chunkmaster.lib.Spiral
import net.trivernis.chunkmaster.lib.dynmap.*
import org.bukkit.Chunk import org.bukkit.Chunk
import org.bukkit.Location
import org.bukkit.World import org.bukkit.World
import kotlin.math.* import kotlin.math.*
@ -27,13 +27,22 @@ abstract class GenerationTask(plugin: Chunkmaster, private val centerChunk: Chun
protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold") protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold")
protected val maxLoadedChunks = plugin.config.getInt("generation.max-loaded-chunks") protected val maxLoadedChunks = plugin.config.getInt("generation.max-loaded-chunks")
protected val chunksPerStep = plugin.config.getInt("generation.chunks-per-step") protected val chunksPerStep = plugin.config.getInt("generation.chunks-per-step")
protected val dynmapIntegration = plugin.config.getBoolean("dynmap")
protected val dynmap = plugin.dynmapApi
protected var endReachedCallback: ((GenerationTask) -> Unit)? = null
private set
private val markerId = "chunkmaster_genarea" private var endReachedCallback: ((GenerationTask) -> Unit)? = null
private val markerName = "Chunkmaster Generation Area"
private val dynmapIntegration = plugin.config.getBoolean("dynmap")
private val dynmap = plugin.dynmapApi
private val markerSet: ExtendedMarkerSet? = if (dynmap != null) {
DynmapApiWrapper(dynmap).getCreateMarkerSet("chunkmaster", "Chunkmaster")
} else {
null
}
private val markerAreaStyle = MarkerStyle(null, LineStyle(2, 1.0, 0x0022FF), FillStyle(.0, 0))
private val markerAreaId = "chunkmaster_genarea"
private val markerAreaName = "Chunkmaster Generation Area"
private val markerLastStyle = MarkerStyle(null, LineStyle(2, 1.0, 0x0077FF), FillStyle(.0, 0))
private val markerLastId = "chunkmaster_lastchunk"
private val markerLastName = "Chunkmaster Last Chunk"
private val ignoreWorldborder = plugin.config.getBoolean("generation.ignore-worldborder") private val ignoreWorldborder = plugin.config.getBoolean("generation.ignore-worldborder")
abstract override fun run() abstract override fun run()
@ -83,38 +92,42 @@ abstract class GenerationTask(plugin: Chunkmaster, private val centerChunk: Chun
/** /**
* Updates the dynmap marker for the generation radius * Updates the dynmap marker for the generation radius
*/ */
protected fun updateDynmapMarker(clear: Boolean = false) { protected fun updateGenerationAreaMarker(clear: Boolean = false) {
val markerSet = dynmap?.markerAPI?.getMarkerSet("markers")
var marker = markerSet?.findAreaMarker(markerId)
if (clear) { if (clear) {
marker?.deleteMarker() markerSet?.deleteAreaMarker(markerAreaId)
} else if (dynmapIntegration && stopAfter > 0) { } else if (dynmapIntegration && stopAfter > 0) {
val (topLeft, bottomRight) = this.getAreaCorners() val (topLeft, bottomRight) = this.getAreaCorners()
if (marker != null) { markerSet?.creUpdateAreMarker(
marker.setCornerLocations( markerAreaId,
doubleArrayOf((topLeft.x * 16).toDouble(), (bottomRight.x * 16).toDouble()), markerAreaName,
doubleArrayOf((topLeft.z * 16).toDouble(), (bottomRight.z * 16).toDouble()) topLeft.getCenterLocation(world),
) bottomRight.getCenterLocation(world),
} else { markerAreaStyle
marker = markerSet?.createAreaMarker( )
markerId, }
markerName, }
false,
world.name, /**
doubleArrayOf((topLeft.x * 16).toDouble(), (bottomRight.x * 16).toDouble()), * Updates the dynmap marker for the generation radius
doubleArrayOf((topLeft.z * 16).toDouble(), (bottomRight.z * 16).toDouble()), */
true fun updateLastChunkMarker(clear: Boolean = false) {
) if (clear) {
} markerSet?.deleteAreaMarker(markerLastId)
marker?.setFillStyle(.0, 0) } else if (dynmapIntegration) {
marker?.setLineStyle(2, 1.0, 0x0000FF) markerSet?.creUpdateAreMarker(
markerLastId,
markerLastName,
this.lastChunk.getBlock(0, 0, 0).location,
this.lastChunk.getBlock(15, 0, 15).location,
markerLastStyle
)
} }
} }
/** /**
* Returns an approximation of cornders of the generation area * Returns an approximation of cornders of the generation area
*/ */
protected fun getAreaCorners(): Pair<ChunkCoordinates, ChunkCoordinates> { private fun getAreaCorners(): Pair<ChunkCoordinates, ChunkCoordinates> {
val width = sqrt(stopAfter.toFloat()) val width = sqrt(stopAfter.toFloat())
return Pair( return Pair(
ChunkCoordinates(centerChunk.x - floor(width/2).toInt(), centerChunk.z - floor(width/2).toInt()), ChunkCoordinates(centerChunk.x - floor(width/2).toInt(), centerChunk.z - floor(width/2).toInt()),
@ -128,7 +141,8 @@ abstract class GenerationTask(plugin: Chunkmaster, private val centerChunk: Chun
protected fun setEndReached() { protected fun setEndReached() {
endReached = true endReached = true
endReachedCallback?.invoke(this) endReachedCallback?.invoke(this)
updateDynmapMarker(true) updateGenerationAreaMarker(true)
updateLastChunkMarker(true)
if (dynmapIntegration) { if (dynmapIntegration) {
val (topLeft, bottomRight) = this.getAreaCorners() val (topLeft, bottomRight) = this.getAreaCorners()
dynmap?.triggerRenderOfVolume(topLeft.getCenterLocation(world), bottomRight.getCenterLocation(world)) dynmap?.triggerRenderOfVolume(topLeft.getCenterLocation(world), bottomRight.getCenterLocation(world))

@ -20,7 +20,7 @@ class GenerationTaskPaper(
override var endReached: Boolean = false override var endReached: Boolean = false
init { init {
updateDynmapMarker() updateGenerationAreaMarker()
} }
/** /**
@ -70,7 +70,8 @@ class GenerationTaskPaper(
* This unloads all chunks that were generated but not unloaded yet. * This unloads all chunks that were generated but not unloaded yet.
*/ */
override fun cancel() { override fun cancel() {
updateDynmapMarker(true) updateGenerationAreaMarker(true)
updateLastChunkMarker(true)
unloadAllChunks() unloadAllChunks()
} }

@ -16,7 +16,7 @@ class GenerationTaskSpigot(
override var endReached: Boolean = false override var endReached: Boolean = false
init { init {
updateDynmapMarker() updateGenerationAreaMarker()
} }
/** /**
@ -67,6 +67,7 @@ class GenerationTaskSpigot(
} }
} }
} }
updateDynmapMarker(true) updateGenerationAreaMarker(true)
updateLastChunkMarker(true)
} }
} }
Loading…
Cancel
Save