Advertisement
Guest User

Untitled

a guest
Jun 28th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.19 KB | None | 0 0
  1. package io.github.eirikh1996.movecraftspace.expansion.dynmap
  2.  
  3. import io.github.eirikh1996.movecraftspace.expansion.Expansion
  4. import io.github.eirikh1996.movecraftspace.expansion.ExpansionManager
  5. import io.github.eirikh1996.movecraftspace.expansion.ExpansionState
  6. import io.github.eirikh1996.movecraftspace.expansion.hyperspace.HyperspaceExpansion
  7. import io.github.eirikh1996.movecraftspace.expansion.hyperspace.managers.HyperspaceManager
  8. import io.github.eirikh1996.movecraftspace.objects.PlanetCollection
  9. import io.github.eirikh1996.movecraftspace.objects.StarCollection
  10. import org.bukkit.Bukkit
  11. import org.bukkit.Location
  12. import org.bukkit.entity.Player
  13. import org.bukkit.scheduler.BukkitRunnable
  14. import org.dynmap.DynmapCommonAPI
  15. import org.dynmap.markers.CircleMarker
  16. import org.dynmap.markers.Marker
  17. import org.dynmap.markers.MarkerAPI
  18.  
  19. class DynmapExpansion : Expansion() {
  20. val orbitMarkerByID = HashMap<String, CircleMarker>()
  21. val planetMarkerByID = HashMap<String, Marker>()
  22. val beaconMarkerByID = HashMap<String, Marker>()
  23. val starMarkerByID = HashMap<String, Marker>()
  24.  
  25. var hyperspaceExpansion: HyperspaceExpansion? = null
  26. override fun allowedArea(p: Player, loc: Location): Boolean {
  27. return true
  28. }
  29.  
  30. override fun enable() {
  31. val dynmap = Bukkit.getPluginManager().getPlugin("dynmap")
  32. if (dynmap !is DynmapCommonAPI || !dynmap.isEnabled) {
  33. logger.severe("Dynmap is required, but was not found or disabled")
  34. state = ExpansionState.DISABLED
  35. return
  36. }
  37. val hsExpansion = ExpansionManager.getExpansion("HyperspaceExpansion")
  38. if (hsExpansion is HyperspaceExpansion && hsExpansion.state == ExpansionState.ENABLED) {
  39. hyperspaceExpansion = hsExpansion
  40. }
  41.  
  42. object : BukkitRunnable() {
  43. val pMarkers = dynmap.markerAPI.getMarkerSet("planets")
  44. val planetMarkers = if (pMarkers == null) {
  45. dynmap.markerAPI.createMarkerSet("planets", "Planets", dynmap.markerAPI.markerIcons, false)
  46. } else {
  47. pMarkers
  48. }
  49. val oMarkers = dynmap.markerAPI.getMarkerSet("orbits")
  50. val orbitMarkers = if (oMarkers == null) {
  51. dynmap.markerAPI.createMarkerSet("orbits", "Orbits", dynmap.markerAPI.markerIcons, false)
  52. } else {
  53. oMarkers
  54. }
  55. val sMarkers = dynmap.markerAPI.getMarkerSet("stars")
  56. val starMarkers = if (sMarkers == null) {
  57. dynmap.markerAPI.createMarkerSet("stars", "Stars", dynmap.markerAPI.markerIcons, false)
  58. } else {
  59. sMarkers
  60. }
  61. val bMarkers = dynmap.markerAPI.getMarkerSet("hyperspace beacons")
  62. val beaconMarkers = if (bMarkers == null) {
  63. dynmap.markerAPI.createMarkerSet("hyperspace beacons", "Hyperspace beacons", dynmap.markerAPI.markerIcons, false)
  64. } else {
  65. bMarkers
  66. }
  67. override fun run() {
  68. for (planet in PlanetCollection) {
  69. val star = StarCollection.closestStar(planet.orbitCenter.toLocation(planet.space))!!
  70. val orbitMarkerID = star.name + "_" + planet.destination.name + "_orbit_" + planet.space.name
  71. val orbitRadius = planet.center.distance(planet.orbitCenter).toDouble()
  72. val orbitMarker = if (!orbitMarkerByID.containsKey(orbitMarkerID)) {
  73. val tempOrbitMarker = orbitMarkers.findCircleMarker(orbitMarkerID)
  74. if (tempOrbitMarker == null) {
  75. orbitMarkers.createCircleMarker(orbitMarkerID, orbitMarkerID, false, planet.space.name,
  76. planet.orbitCenter.x.toDouble(),
  77. planet.orbitCenter.y.toDouble(),
  78. planet.orbitCenter.z.toDouble(), orbitRadius, orbitRadius, false)
  79. } else {
  80. tempOrbitMarker.setCenter(planet.space.name,
  81. planet.orbitCenter.x.toDouble(), planet.orbitCenter.y.toDouble(), planet.orbitCenter.z.toDouble()
  82. )
  83. tempOrbitMarker.setRadius(orbitRadius, orbitRadius)
  84. tempOrbitMarker
  85. }
  86. } else {
  87. val tempOrbitMarker = orbitMarkerByID.get(orbitMarkerID)!!
  88. tempOrbitMarker.setCenter(planet.space.name,
  89. planet.orbitCenter.x.toDouble(), planet.orbitCenter.y.toDouble(), planet.orbitCenter.z.toDouble()
  90. )
  91. tempOrbitMarker.setRadius(orbitRadius, orbitRadius)
  92. tempOrbitMarker
  93. }
  94. orbitMarker.setFillStyle(0.0, 16711680)
  95. val planetMarkerID = planet.destination.name + "_planet_" + planet.space.name
  96. val markerIcon = dynmap.markerAPI.getMarkerIcon("world")
  97. val planetMarker = if (!planetMarkerByID.containsKey(planetMarkerID)) {
  98. val tempPlanetMarker = planetMarkers.findMarker(planetMarkerID)
  99. if (tempPlanetMarker == null) {
  100. planetMarkers.createMarker(planetMarkerID, planet.destination.name, planet.space.name,
  101. planet.center.x.toDouble(),
  102. planet.center.y.toDouble(), planet.center.z.toDouble(), markerIcon, false)
  103. } else {
  104. tempPlanetMarker.setLocation(planet.space.name,
  105. planet.center.x.toDouble(), planet.center.y.toDouble(), planet.center.z.toDouble()
  106. )
  107. tempPlanetMarker.setMarkerIcon(markerIcon)
  108. tempPlanetMarker
  109. }
  110. } else {
  111. val tempPlanetMarker = planetMarkerByID.get(planetMarkerID)!!
  112. tempPlanetMarker.setLocation(planet.space.name,
  113. planet.center.x.toDouble(), planet.center.y.toDouble(), planet.center.z.toDouble()
  114. )
  115. tempPlanetMarker.setMarkerIcon(markerIcon)
  116. tempPlanetMarker
  117. }
  118. if (planetMarker != null && !planetMarkerByID.containsKey(planetMarkerID)) {
  119. planetMarkerByID.put(planetMarkerID, planetMarker)
  120. }
  121. if (orbitMarker != null && !orbitMarkerByID.containsKey(orbitMarkerID)) {
  122. orbitMarkerByID.put(orbitMarkerID, orbitMarker)
  123. }
  124. }
  125. for (star in StarCollection) {
  126.  
  127. val starMarkerID = star.name + "_" + star.space.name
  128. val starMarkerIcon = dynmap.markerAPI.getMarkerIcon("sun")
  129. val starMarker = if (!starMarkerByID.containsKey(starMarkerID)) {
  130. val tempStarMarker = starMarkers.findMarker(starMarkerID)
  131. if (tempStarMarker == null) {
  132. starMarkers.createMarker(starMarkerID, star.name, star.space.name,
  133. star.loc.x.toDouble(), star.loc.y.toDouble(),
  134. star.loc.z.toDouble(), starMarkerIcon, false)
  135. } else {
  136. tempStarMarker.setLocation(star.space.name, star.loc.x.toDouble(),
  137. star.loc.y.toDouble(), star.loc.z.toDouble()
  138. )
  139. tempStarMarker.setMarkerIcon(starMarkerIcon)
  140. tempStarMarker
  141. }
  142. } else {
  143. val tempStarMarker = starMarkerByID.get(starMarkerID)!!
  144. tempStarMarker.setLocation(star.space.name, star.loc.x.toDouble(), star.loc.y.toDouble(),
  145. star.loc.z.toDouble()
  146. )
  147. tempStarMarker.setMarkerIcon(starMarkerIcon)
  148. tempStarMarker
  149. }
  150. if (starMarker != null && !starMarkerByID.containsKey(starMarkerID)) {
  151. starMarkerByID.put(starMarkerID, starMarker)
  152. }
  153. }
  154. for (planetMarker in planetMarkerByID.keys) {
  155. val marker = planetMarkerByID[planetMarker]!!
  156. if (PlanetCollection.getPlanetByName(marker.label) != null)
  157. continue
  158. planetMarkerByID.remove(planetMarker)
  159. marker.deleteMarker()
  160. }
  161. for (orbitMarker in orbitMarkerByID.keys) {
  162. val planetName = orbitMarker.split("_")[1]
  163. if (PlanetCollection.getPlanetByName(planetName) != null) {
  164. continue
  165. }
  166. orbitMarkerByID.remove(orbitMarker)!!.deleteMarker()
  167. }
  168. for (starMarker in starMarkerByID.keys) {
  169. val marker = starMarkerByID[starMarker]!!
  170. if (StarCollection.getStarByName(marker.label) != null)
  171. continue
  172. starMarkerByID.remove(starMarker)
  173. marker.deleteMarker()
  174.  
  175. }
  176. if (hyperspaceExpansion == null) {
  177. return
  178. }
  179. for (hsBeacon in HyperspaceManager.beaconLocations) {
  180. val beaconMarker = dynmap.markerAPI.getMarkerIcon("portal")
  181. val originBeaconMarkerID = hsBeacon.originName + "_" + hsBeacon.destinationName
  182. val originMarker = if (!beaconMarkerByID.containsKey(originBeaconMarkerID)) {
  183. val tempOriginBeaconMarker = beaconMarkers.findMarker(originBeaconMarkerID)
  184. if (tempOriginBeaconMarker == null) {
  185. beaconMarkers.createMarker(
  186. originBeaconMarkerID,
  187. originBeaconMarkerID,
  188. hsBeacon.origin.world!!.name,
  189. hsBeacon.origin.x,
  190. hsBeacon.origin.y,
  191. hsBeacon.origin.z,
  192. beaconMarker,
  193. false)
  194. } else {
  195. tempOriginBeaconMarker.setLocation(
  196. hsBeacon.origin.world!!.name,
  197. hsBeacon.origin.x,
  198. hsBeacon.origin.y,
  199. hsBeacon.origin.z
  200. )
  201. tempOriginBeaconMarker.setMarkerIcon(beaconMarker)
  202. tempOriginBeaconMarker
  203. }
  204. } else {
  205. val tempOriginBeaconMarker = beaconMarkerByID[originBeaconMarkerID]!!
  206. tempOriginBeaconMarker.setLocation(
  207. hsBeacon.origin.world!!.name,
  208. hsBeacon.origin.x,
  209. hsBeacon.origin.y,
  210. hsBeacon.origin.z
  211. )
  212. tempOriginBeaconMarker.setMarkerIcon(beaconMarker)
  213. tempOriginBeaconMarker
  214. }
  215. if (originMarker != null && !beaconMarkerByID.containsKey(originBeaconMarkerID)) {
  216. beaconMarkerByID.put(originBeaconMarkerID, originMarker)
  217. }
  218. val destinationBeaconMarkerID = hsBeacon.destinationName + "_" + hsBeacon.originName
  219. val destinationMarker = if (!beaconMarkerByID.containsKey(destinationBeaconMarkerID)) {
  220. val tempDestinationBeaconMarker = beaconMarkers.findMarker(destinationBeaconMarkerID)
  221. if (tempDestinationBeaconMarker == null) {
  222. beaconMarkers.createMarker(
  223. destinationBeaconMarkerID,
  224. destinationBeaconMarkerID,
  225. hsBeacon.destination.world!!.name,
  226. hsBeacon.destination.x,
  227. hsBeacon.destination.y,
  228. hsBeacon.destination.z,
  229. beaconMarker,
  230. false)
  231. } else {
  232. tempDestinationBeaconMarker.setLocation(
  233. hsBeacon.destination.world!!.name,
  234. hsBeacon.destination.x,
  235. hsBeacon.destination.y,
  236. hsBeacon.destination.z
  237. )
  238. tempDestinationBeaconMarker.setMarkerIcon(beaconMarker)
  239. tempDestinationBeaconMarker
  240. }
  241. } else {
  242. val tempDestinationBeaconMarker = beaconMarkerByID[destinationBeaconMarkerID]!!
  243. tempDestinationBeaconMarker.setLocation(
  244. hsBeacon.destination.world!!.name,
  245. hsBeacon.destination.x,
  246. hsBeacon.destination.y,
  247. hsBeacon.destination.z
  248. )
  249. tempDestinationBeaconMarker.setMarkerIcon(beaconMarker)
  250. tempDestinationBeaconMarker
  251. }
  252. if (destinationMarker != null && !beaconMarkerByID.containsKey(destinationBeaconMarkerID)) {
  253. beaconMarkerByID.put(destinationBeaconMarkerID, destinationMarker)
  254. }
  255. }
  256.  
  257. }
  258.  
  259.  
  260. }.runTaskTimerAsynchronously(plugin, 0, 200)
  261. }
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement