-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove Pl3xMap (it just disappeared from GH and Modrinth??)"
This reverts commit 55e018a.
- Loading branch information
Showing
11 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
waypoints/src/main/kotlin/de/md5lukas/waypoints/config/integrations/Pl3xMapConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.md5lukas.waypoints.config.integrations | ||
|
||
import de.md5lukas.konfig.Configurable | ||
|
||
@Configurable | ||
class Pl3xMapConfiguration { | ||
|
||
var enabled: Boolean = false | ||
private set | ||
|
||
var icon: String = "" | ||
private set | ||
|
||
var iconSize: Double = 3.0 | ||
private set | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
waypoints/src/main/kotlin/de/md5lukas/waypoints/integrations/Pl3xMapIntegration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package de.md5lukas.waypoints.integrations | ||
|
||
import com.okkero.skedule.skedule | ||
import de.md5lukas.commons.paper.registerEvents | ||
import de.md5lukas.waypoints.WaypointsPlugin | ||
import de.md5lukas.waypoints.api.Type | ||
import de.md5lukas.waypoints.api.Waypoint | ||
import de.md5lukas.waypoints.api.event.WaypointCreateEvent | ||
import de.md5lukas.waypoints.api.event.WaypointCustomDataChangeEvent | ||
import de.md5lukas.waypoints.api.event.WaypointPostDeleteEvent | ||
import de.md5lukas.waypoints.events.ConfigReloadEvent | ||
import java.io.File | ||
import java.util.* | ||
import javax.imageio.ImageIO | ||
import net.pl3x.map.core.Pl3xMap | ||
import net.pl3x.map.core.image.IconImage | ||
import net.pl3x.map.core.markers.layer.SimpleLayer | ||
import net.pl3x.map.core.markers.marker.Marker | ||
import net.pl3x.map.core.markers.option.Options | ||
import org.bukkit.World | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.server.PluginDisableEvent | ||
|
||
class Pl3xMapIntegration(private val plugin: WaypointsPlugin) : Listener { | ||
|
||
companion object Constants { | ||
const val CUSTOM_DATA_KEY = "pl3xmap-icon" | ||
} | ||
|
||
private lateinit var api: Pl3xMap | ||
private val layerKey: String = "waypoints" | ||
private val layerProviders: MutableMap<UUID, SimpleLayer?> = HashMap() | ||
|
||
private val iconFolder = File(plugin.dataFolder, "icons") | ||
|
||
fun setupPl3xMap(): Boolean { | ||
if (plugin.server.pluginManager.getPlugin("Pl3xMap") === null) { | ||
return false | ||
} | ||
|
||
plugin.slF4JLogger.info("Found Pl3xMap plugin") | ||
|
||
extractIcons(plugin) | ||
|
||
api = Pl3xMap.api() | ||
|
||
plugin.skedule { plugin.api.publicWaypoints.getAllWaypoints().forEach { createMarker(it) } } | ||
|
||
plugin.registerEvents(this) | ||
return true | ||
} | ||
|
||
@EventHandler | ||
fun onDisable(e: PluginDisableEvent) { | ||
if (e.plugin !== plugin) { | ||
return | ||
} | ||
|
||
layerProviders.values.forEach { it?.clearMarkers() } | ||
} | ||
|
||
@EventHandler | ||
@Suppress("UNUSED_PARAMETER") | ||
fun onConfigReload(e: ConfigReloadEvent) { | ||
plugin.skedule { | ||
plugin.api.publicWaypoints.getAllWaypoints().let { waypoints -> | ||
waypoints.forEach { it.removeMarker() } | ||
unregisterLayerProviders() | ||
waypoints.forEach { createMarker(it) } | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun onCreate(e: WaypointCreateEvent) { | ||
if (e.waypoint.type === Type.PUBLIC) { | ||
plugin.skedule { createMarker(e.waypoint) } | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun onDelete(e: WaypointPostDeleteEvent) { | ||
if (e.waypoint.type === Type.PUBLIC) { | ||
e.waypoint.removeMarker() | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun onUpdate(e: WaypointCustomDataChangeEvent) { | ||
if (e.key != CUSTOM_DATA_KEY || e.waypoint.type !== Type.PUBLIC) { | ||
return | ||
} | ||
e.waypoint.removeMarker() | ||
|
||
plugin.skedule { createMarker(e.waypoint) } | ||
} | ||
|
||
private suspend fun createMarker(waypoint: Waypoint) { | ||
val worldNotNull = waypoint.location.world ?: return | ||
|
||
worldNotNull.layerProvider?.let { provider -> | ||
val marker = | ||
Marker.icon( | ||
waypoint.id.toString(), | ||
waypoint.location.x, | ||
waypoint.location.z, | ||
getMarkerForWaypoint(waypoint), | ||
plugin.waypointsConfig.integrations.pl3xmap.iconSize) | ||
marker.setOptions(Options.builder().tooltipContent(waypoint.name)) | ||
provider.addMarker(marker) | ||
} | ||
} | ||
|
||
private suspend fun getMarkerForWaypoint(waypoint: Waypoint): String { | ||
val key = | ||
waypoint.getCustomData(CUSTOM_DATA_KEY) ?: plugin.waypointsConfig.integrations.pl3xmap.icon | ||
|
||
if (api.iconRegistry.has(key)) { | ||
return key | ||
} | ||
|
||
val prefixedKey = "waypoints-$key" | ||
|
||
if (!api.iconRegistry.has(prefixedKey)) { | ||
val image = File(iconFolder, "$key.png") | ||
api.iconRegistry.register(IconImage(prefixedKey, ImageIO.read(image), "png")) | ||
} | ||
|
||
return prefixedKey | ||
} | ||
|
||
private val World.layerProvider: SimpleLayer? | ||
get() = | ||
layerProviders.computeIfAbsent(uid) { | ||
mapWorld?.let { mapWorld -> | ||
val layer = | ||
SimpleLayer(layerKey) { plugin.translations.INTEGRATIONS_MAPS_LABEL.rawText } | ||
|
||
mapWorld.layerRegistry.register(layer) | ||
|
||
layer | ||
} | ||
} | ||
|
||
private fun unregisterLayerProviders() { | ||
api.worldRegistry.forEach { | ||
it.layerRegistry.let { registry -> | ||
if (registry.has(layerKey)) { | ||
registry.unregister(layerKey) | ||
} | ||
} | ||
} | ||
layerProviders.clear() | ||
} | ||
|
||
private val World.mapWorld | ||
get() = api.worldRegistry.get(name) | ||
|
||
private fun Waypoint.removeMarker() { | ||
location.world?.layerProvider?.removeMarker(id.toString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters