commit
9c5f486414
@ -0,0 +1,13 @@
|
||||
image: openjdk
|
||||
|
||||
matrix:
|
||||
- env: SCRIPT=shadowJar
|
||||
|
||||
install:
|
||||
- gradle dependencies
|
||||
|
||||
script:
|
||||
- if [[ "SCRIPT" ]]; then gradle $SCRIPT; fi
|
||||
|
||||
cache:
|
||||
- .gradle
|
@ -0,0 +1,30 @@
|
||||
package net.trivernis.chunkmaster.lib.dynmap
|
||||
|
||||
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,95 @@
|
||||
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
|
||||
import org.dynmap.markers.PolyLineMarker
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
fun creUpdatePolyLineMarker(id: String, label: String, edges: List<Location>, style: MarkerStyle?): PolyLineMarker? {
|
||||
var marker = markerSet.findPolyLineMarker(id)
|
||||
val xList = edges.map { it.x }
|
||||
val yList = edges.map { it.y }
|
||||
val zList = edges.map { it.z }
|
||||
if (marker != null) {
|
||||
marker.setCornerLocations(xList.toDoubleArray(), yList.toDoubleArray(), zList.toDoubleArray())
|
||||
} else {
|
||||
marker = markerSet.createPolyLineMarker(id, label, false, edges.first().world.name, xList.toDoubleArray(), yList.toDoubleArray(), zList.toDoubleArray(), true)
|
||||
}
|
||||
if (style != null) {
|
||||
if (style.lineStyle != null) {
|
||||
marker.setLineStyle(style.lineStyle.weight, style.lineStyle.opacity, style.lineStyle.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)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the polylinemarker for an id
|
||||
*/
|
||||
fun findPolyLineMarker(id: String): PolyLineMarker? {
|
||||
return markerSet.findPolyLineMarker(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an area marker
|
||||
* @param id - the id of the marker
|
||||
*/
|
||||
fun deleteAreaMarker(id: String) {
|
||||
val marker = this.findAreaMarker(id)
|
||||
marker?.deleteMarker()
|
||||
}
|
||||
|
||||
fun deletePolyLineMarker(id: String) {
|
||||
val marker = this.findPolyLineMarker(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)
|
@ -0,0 +1,130 @@
|
||||
package net.trivernis.chunkmaster.lib.shapes
|
||||
|
||||
import net.trivernis.chunkmaster.lib.dynmap.ExtendedMarkerSet
|
||||
import net.trivernis.chunkmaster.lib.dynmap.MarkerStyle
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class Circle(center: Pair<Int, Int>, start: Pair<Int, Int>, radius: Int): Shape(center, start, radius) {
|
||||
private var r = 0
|
||||
private var coords = Stack<Pair<Int, Int>>()
|
||||
private var previousCoords = HashSet<Pair<Int, Int>>()
|
||||
|
||||
override fun endReached(): Boolean {
|
||||
if ((radius + 1) in 1..r) return true
|
||||
return radius > 0 && coords.isEmpty() && r >= radius
|
||||
}
|
||||
|
||||
override fun progress(): Double {
|
||||
return (PI * r.toFloat().pow(2))/(PI* radius.toFloat().pow(2))
|
||||
}
|
||||
|
||||
override fun currentRadius(): Int {
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the edge locations of the shape to be used
|
||||
* with dynmap markers
|
||||
*/
|
||||
override fun getShapeEdgeLocations(): List<Pair<Int, Int>> {
|
||||
val locations = this.getCircleCoordinates(this.radius)
|
||||
locations.add(locations.first())
|
||||
return locations.map{ Pair(it.first + center.first, it.second + center.second) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next coordinate of the circle until the end is reached
|
||||
*/
|
||||
override fun next(): Pair<Int, Int> {
|
||||
if (endReached()) {
|
||||
return currentPos
|
||||
}
|
||||
if (count == 0 && currentPos != center) {
|
||||
val tmpCircle = Circle(center, center, radius)
|
||||
while (tmpCircle.next() != currentPos);
|
||||
this.count = tmpCircle.count
|
||||
this.r = tmpCircle.r
|
||||
}
|
||||
if (count == 0) {
|
||||
count++
|
||||
return center
|
||||
}
|
||||
if (coords.isEmpty()) {
|
||||
r++
|
||||
val tmpCoords = HashSet<Pair<Int, Int>>()
|
||||
tmpCoords.addAll(getCircleCoordinates((r*2)-1).map { Pair(it.first / 2, it.second / 2) })
|
||||
tmpCoords.addAll(getCircleCoordinates(r))
|
||||
tmpCoords.removeAll(previousCoords)
|
||||
previousCoords.clear()
|
||||
coords.addAll(tmpCoords)
|
||||
previousCoords.addAll(tmpCoords)
|
||||
}
|
||||
count++
|
||||
val coord = coords.pop()
|
||||
currentPos = Pair(coord.first + center.first, coord.second + center.second)
|
||||
return currentPos
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int coordinates for a circle
|
||||
* Some coordinates might already be present in the list
|
||||
* @param r - the radius
|
||||
*/
|
||||
private fun getCircleCoordinates(r: Int): ArrayList<Pair<Int, Int>> {
|
||||
val coords = ArrayList<Pair<Int, Int>>()
|
||||
val segCoords = getSegment(r)
|
||||
coords.addAll(segCoords.reversed())
|
||||
for (step in 1..7) {
|
||||
val tmpSeg = ArrayList<Pair<Int, Int>>()
|
||||
for (pos in segCoords) {
|
||||
val coord = when (step) {
|
||||
1 -> Pair(pos.first, -pos.second)
|
||||
2 ->Pair(pos.second, -pos.first)
|
||||
3 -> Pair(-pos.second, -pos.first)
|
||||
4 -> Pair(-pos.first, -pos.second)
|
||||
5 -> Pair(-pos.first, pos.second)
|
||||
6 -> Pair(-pos.second, pos.first)
|
||||
7 -> Pair(pos.second, pos.first)
|
||||
else -> pos
|
||||
}
|
||||
if (coord !in coords) {
|
||||
tmpSeg.add(coord)
|
||||
}
|
||||
}
|
||||
if (step % 2 == 0) {
|
||||
coords.addAll(tmpSeg.reversed())
|
||||
} else {
|
||||
coords.addAll(tmpSeg)
|
||||
}
|
||||
}
|
||||
|
||||
return coords
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int coordinates for a circles segment
|
||||
* @param r - the radius
|
||||
*/
|
||||
private fun getSegment(r: Int): ArrayList<Pair<Int, Int>> {
|
||||
var d = -r
|
||||
var x = r
|
||||
var y = 0
|
||||
val coords = ArrayList<Pair<Int, Int>>()
|
||||
while (y <= x) {
|
||||
coords.add(Pair(x, y))
|
||||
d += 2 * y + 1
|
||||
y += 1
|
||||
if (d > 0) {
|
||||
x -= 1
|
||||
d -= 2 * x
|
||||
}
|
||||
}
|
||||
return coords
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.trivernis.chunkmaster.lib.shapes
|
||||
|
||||
import net.trivernis.chunkmaster.lib.dynmap.ExtendedMarkerSet
|
||||
import net.trivernis.chunkmaster.lib.dynmap.MarkerStyle
|
||||
import javax.xml.stream.Location
|
||||
|
||||
abstract class Shape(protected val center: Pair<Int, Int>, start: Pair<Int, Int>, radius: Int) {
|
||||
protected var currentPos = start
|
||||
protected var radius = radius
|
||||
private set
|
||||
var count = 0
|
||||
|
||||
/**
|
||||
* Returns the next value
|
||||
*/
|
||||
abstract fun next(): Pair<Int, Int>
|
||||
|
||||
/**
|
||||
* If the shape can provide a next value
|
||||
*/
|
||||
abstract fun endReached(): Boolean
|
||||
|
||||
/**
|
||||
* Returns the progress of the shape
|
||||
*/
|
||||
abstract fun progress(): Double
|
||||
|
||||
/**
|
||||
* Returns the current radius
|
||||
*/
|
||||
abstract fun currentRadius(): Int
|
||||
|
||||
/**
|
||||
* returns a poly marker for the shape
|
||||
*/
|
||||
abstract fun getShapeEdgeLocations(): List<Pair<Int, Int>>
|
||||
}
|
Loading…
Reference in New Issue