Skip to content

Commit

Permalink
Revert "Remove Pl3xMap (it just disappeared from GH and Modrinth??)"
Browse files Browse the repository at this point in the history
This reverts commit 55e018a.
  • Loading branch information
Sytm committed Oct 26, 2023
1 parent c02d5b7 commit 2e1dde8
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 3 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
### Fixed
- Default colors for beacon beams are not applied

### Removed
- Pl3xMap support because the project disappeared

## 4.2.0

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ And if your language is not there, the plugin is fully translatable
- [Dynmap](https://www.spigotmc.org/resources/dynmap%C2%AE.274/)
- [SquareMap](https://github.com/jpenilla/squaremap)
- [BlueMap](https://bluemap.bluecolored.de/)
- [Pl3xMap](https://modrinth.com/plugin/pl3xmap)

## Videos

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dynmap-coreApi = { group = "us.dynmap", name = "DynmapCoreAPI", version.ref = "d
dynmap-api = { group = "us.dynmap", name = "dynmap-api", version.ref = "dynmap" }
squaremapApi = { group = "xyz.jpenilla", name = "squaremap-api", version = "1.1.16" }
bluemapApi = { group = "com.github.BlueMap-Minecraft", name = "BlueMapAPI", version = "2.6.0" }
pl3xmap = { group = "maven.modrinth", name = "pl3xmap", version = "1.20.2-10" }

# Links to the various projects to check versions:
#
Expand All @@ -53,6 +54,7 @@ bluemapApi = { group = "com.github.BlueMap-Minecraft", name = "BlueMapAPI", vers
# https://github.com/jpenilla/squaremap
# https://github.com/BlueMap-Minecraft/BlueMapAPI
# https://github.com/dmulloy2/ProtocolLib
# https://modrinth.com/plugin/pl3xmap

# Test dependencies
junitLauncher = { group = "org.junit.platform", name = "junit-platform-launcher" }
Expand Down
6 changes: 6 additions & 0 deletions waypoints/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ repositories {
maven("https://libraries.minecraft.net") // Brigadier

maven("https://repo.mikeprimm.com/") // DynMap
exclusiveContent { // Pl3xMap
forRepository { maven("https://api.modrinth.com/maven") }
filter { includeGroup("maven.modrinth") }
}
}

dependencies {
Expand Down Expand Up @@ -54,6 +58,7 @@ dependencies {
implementation(variantOf(libs.dynmap.api) { classifier("unshaded") }) { isTransitive = false }
implementation(libs.squaremapApi)
implementation(libs.bluemapApi)
implementation(libs.pl3xmap)

// Testing
testImplementation(kotlin("test-junit5"))
Expand Down Expand Up @@ -177,6 +182,7 @@ modrinth {

dependencies {
with(optional) {
project("pl3xmap")
project("bluemap")
project("squaremap")
project("dynmap")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import de.md5lukas.waypoints.events.PointerEvents
import de.md5lukas.waypoints.events.WaypointsListener
import de.md5lukas.waypoints.integrations.BlueMapIntegration
import de.md5lukas.waypoints.integrations.DynMapIntegration
import de.md5lukas.waypoints.integrations.Pl3xMapIntegration
import de.md5lukas.waypoints.integrations.SquareMapIntegration
import de.md5lukas.waypoints.integrations.VaultIntegration
import de.md5lukas.waypoints.lang.Translations
Expand Down Expand Up @@ -88,6 +89,9 @@ class WaypointsPlugin : JavaPlugin() {
var squareMapIntegrationAvailable = false
private set

var pl3xMapIntegrationAvailable = false
private set

private var blueMapIntegrationAvailable = false

private lateinit var metrics: Metrics
Expand Down Expand Up @@ -205,6 +209,9 @@ class WaypointsPlugin : JavaPlugin() {
if (bluemap.enabled) {
blueMapIntegrationAvailable = BlueMapIntegration(this@WaypointsPlugin).setupBlueMap()
}
if (pl3xmap.enabled) {
pl3xMapIntegrationAvailable = Pl3xMapIntegration(this@WaypointsPlugin).setupPl3xMap()
}
}
}
}
Expand Down Expand Up @@ -232,6 +239,7 @@ class WaypointsPlugin : JavaPlugin() {
dynMapIntegrationAvailable -> "DynMap"
squareMapIntegrationAvailable -> "squaremap"
blueMapIntegrationAvailable -> "BlueMap"
pl3xMapIntegrationAvailable -> "Pl3xMap"
else -> "none"
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class IntegrationsConfiguration {
val dynmap = DynMapConfiguration()
val squaremap = SquareMapConfiguration()
val bluemap = BlueMapConfiguration()
val pl3xmap = Pl3xMapConfiguration()
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import de.md5lukas.waypoints.api.Type
import de.md5lukas.waypoints.api.Waypoint
import de.md5lukas.waypoints.gui.WaypointsGUI
import de.md5lukas.waypoints.integrations.DynMapIntegration
import de.md5lukas.waypoints.integrations.Pl3xMapIntegration
import de.md5lukas.waypoints.integrations.SquareMapIntegration
import de.md5lukas.waypoints.pointers.WaypointTrackable
import de.md5lukas.waypoints.util.*
Expand Down Expand Up @@ -284,6 +285,11 @@ class WaypointPage(wpGUI: WaypointsGUI, private val waypoint: Waypoint) :
SquareMapIntegration.CUSTOM_DATA_KEY,
wpGUI.plugin.waypointsConfig.integrations.squaremap.icon)
}
wpGUI.plugin.pl3xMapIntegrationAvailable -> {
createChangeCustomMapIconItem(
Pl3xMapIntegration.CUSTOM_DATA_KEY,
wpGUI.plugin.waypointsConfig.integrations.pl3xmap.icon)
}
else -> {
background
}
Expand Down
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())
}
}
9 changes: 9 additions & 0 deletions waypoints/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ integrations:
iconSize: 20
bluemap:
enabled: true
pl3xmap:
enabled: true
# The icon id must either be the full key of an existing icon that got registered by another plugin (see "plugins/Pl3xMap/web/images/icon/registered")
# Or it must be the name of an icon in the folder "plugins/Waypoints/icons".
# Examples:
# plugins/Pl3xMap/web/images/icon/registered/spawn.png -> spawn
# plugins/Waypoints/icons/special.png -> special
icon: w
iconSize: 20

playerTracking:
enabled: false
Expand Down
3 changes: 3 additions & 0 deletions waypoints/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ dependencies:
BlueMap:
load: BEFORE
required: false
Pl3xMap:
load: BEFORE
required: false

permissions:
waypoints.*:
Expand Down

0 comments on commit 2e1dde8

Please sign in to comment.