diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e0ef83..dafcf1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ ### Changed - ProtocolLib is no longer required for hologram pointers +### Fixed +- Hologram pointers work across dimensions changes +- Hologram pointers not showing the distance to the target when in a connected world +- Connected worlds not working by default. To apply this fix to existing users: + - Either regenerate the config.yml + - Or update `pointers.connectedWorlds.world` from `world_the_nether` to `world_nether` + ## 4.1.0 ### Added diff --git a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/BeaconColor.kt b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/BeaconColor.kt index 160c7ff..4d2de97 100644 --- a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/BeaconColor.kt +++ b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/BeaconColor.kt @@ -1,6 +1,5 @@ package de.md5lukas.waypoints.pointers -import java.util.Collections import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.TextColor import org.bukkit.Material @@ -66,9 +65,6 @@ enum class BeaconColor(val material: Material, val textColor: TextColor?) { val blockData by lazy { material.createBlockData() } companion object { - private val entries: List = - Collections.unmodifiableList(BeaconColor.values().toList()) - - fun byMaterial(material: Material) = this.entries.firstOrNull { it.material === material } + fun byMaterial(material: Material) = entries.firstOrNull { it.material === material } } } diff --git a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/ManagedPlayer.kt b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/ManagedPlayer.kt index a266fa1..cb73399 100644 --- a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/ManagedPlayer.kt +++ b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/ManagedPlayer.kt @@ -88,7 +88,7 @@ internal class ManagedPlayer( pointerManager.hooks .loadEnabledPointers(player) .thenAccept { enabled -> - PointerVariant.values() + PointerVariant.entries .filter { it.isEnabled(pointerManager.configuration) && enabled.getOrDefault(it.key, true) diff --git a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/Trackable.kt b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/Trackable.kt index ad876b7..aef349b 100644 --- a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/Trackable.kt +++ b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/Trackable.kt @@ -18,7 +18,7 @@ interface Trackable { * * If this value is null the hologram pointer will not be available. */ - fun getHologramText(player: Player): Component? = null + fun getHologramText(player: Player, translatedTarget: Location): Component? = null /** * The item the hologram pointer should use. diff --git a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/variants/HologramPointer.kt b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/variants/HologramPointer.kt index 9337389..144adb4 100644 --- a/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/variants/HologramPointer.kt +++ b/pointers/src/main/kotlin/de/md5lukas/waypoints/pointers/variants/HologramPointer.kt @@ -44,7 +44,7 @@ internal class HologramPointer( override fun update(trackable: Trackable, translatedTarget: Location?) { if (translatedTarget === null) return - val hologramText = trackable.getHologramText(player) + val hologramText = trackable.getHologramText(player, translatedTarget) if (hologramText === null) return val hologramTarget = translatedTarget.clone() @@ -95,10 +95,19 @@ internal class HologramPointer( fun update() { if (::smoothingArmorStand.isInitialized) { - smoothingArmorStand.teleport( - location, - PlayerTeleportEvent.TeleportCause.PLUGIN, - TeleportFlag.EntityState.RETAIN_PASSENGERS) + if (player.world == smoothingArmorStand.world) { + smoothingArmorStand.teleport( + location, + PlayerTeleportEvent.TeleportCause.PLUGIN, + TeleportFlag.EntityState.RETAIN_PASSENGERS) + } else { + // Cannot teleport entities with passengers, so eject, teleport separately, and remount + // them + smoothingArmorStand.eject() + arrayOf(smoothingArmorStand, textDisplay, itemDisplay).forEach { it?.teleport(location) } + smoothingArmorStand.addPassenger(textDisplay) + itemDisplay?.let { smoothingArmorStand.addPassenger(it) } + } textDisplay.text(text) } else { val world = player.world diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/command/WaypointsScriptCommand.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/command/WaypointsScriptCommand.kt index 997df7e..7a4b1d1 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/command/WaypointsScriptCommand.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/command/WaypointsScriptCommand.kt @@ -82,14 +82,14 @@ class WaypointsScriptCommand(private val plugin: WaypointsPlugin) { StringArgument("beacon-color") .replaceSuggestions( ArgumentSuggestions.strings( - BeaconColor.values().map { it.name }.toList()))) { + BeaconColor.entries.map { it.name }.toList()))) { anyExecutor { sender, args -> val player = args["player"] as Player val target = args["target"] as Location val beaconColorString = args["beacon-color"] as String? val beaconColor = - BeaconColor.values().firstOrNull { it.name.equals(beaconColorString, true) } + BeaconColor.entries.firstOrNull { it.name.equals(beaconColorString, true) } if (beaconColorString !== null && beaconColor === null) { translations.COMMAND_SCRIPT_TEMPORARY_WAYPOINT_BEACON_COLOR_NOT_FOUND.send( sender) diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/pointers/BeaconConfigurationImpl.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/pointers/BeaconConfigurationImpl.kt index 5d22e6c..68399c6 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/pointers/BeaconConfigurationImpl.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/pointers/BeaconConfigurationImpl.kt @@ -69,7 +69,7 @@ class BeaconConfigurationImpl : RepeatingPointerConfigurationImpl(), BeaconConfi private class BeaconColorDefaults : TypeAdapter> { override fun get(section: ConfigurationSection, path: String) = mutableMapOf().also { map -> - Type.values().forEach { + Type.entries.forEach { map[it] = BeaconColor.valueOf(section.getStringNotNull("$path.${it.name.lowercase()}")) } } diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/items/CycleSortItem.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/items/CycleSortItem.kt index 8fd58e9..2428614 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/items/CycleSortItem.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/items/CycleSortItem.kt @@ -26,7 +26,7 @@ class CycleSortItem(wpGUI: WaypointsGUI, onCycle: suspend (OverviewSort) -> Unit private companion object { fun getOverviewSortCycleValues(wpGUI: WaypointsGUI) = - OverviewSort.values() + OverviewSort.entries .map { current -> val additionalLines = wpGUI.translations.OVERVIEW_CYCLE_SORT_OPTIONS.map { diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/SettingsPage.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/SettingsPage.kt index 5e4f650..7ee8ec0 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/SettingsPage.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/SettingsPage.kt @@ -38,7 +38,7 @@ class SettingsPage(wpGUI: WaypointsGUI) : ) val enabledPointers = - PointerVariant.values().mapNotNull { + PointerVariant.entries.mapNotNull { if (it.isEnabled(wpGUI.plugin.waypointsConfig.pointers)) { it } else { diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/lang/Translations.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/lang/Translations.kt index 3254808..ca274ac 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/lang/Translations.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/lang/Translations.kt @@ -89,7 +89,7 @@ class Translations(tl: TranslationLoader) { val TEXT_DISTANCE_OTHER_WORLD = Translation(tl, "text.distance.otherWorld") val TEXT_BEACON_COLORS = - BeaconColor.values().map { + BeaconColor.entries.map { it to Translation( tl, "text.beaconColors.${it.name.lowercase()}", miniMessage = tl.itemMiniMessage) @@ -178,7 +178,7 @@ class Translations(tl: TranslationLoader) { Translation( tl, "inventory.overview.cycleSort.inactiveColor", miniMessage = tl.itemMiniMessage) val OVERVIEW_CYCLE_SORT_OPTIONS = - OverviewSort.values().map { it to Translation(tl, "text.sortOptions.${it.name.lowercase()}") } + OverviewSort.entries.map { it to Translation(tl, "text.sortOptions.${it.name.lowercase()}") } val OVERVIEW_SETTINGS = ItemTranslation(tl, "inventory.overview.settings") val OVERVIEW_DESELECT = ItemTranslation(tl, "inventory.overview.deselect") val OVERVIEW_DESELECT_SELECTED = InventoryTranslation(tl, "inventory.overview.deselect.selected") @@ -223,14 +223,14 @@ class Translations(tl: TranslationLoader) { val SETTINGS_POINTERS_NAMES: Map = mutableMapOf().also { map -> map.putAll( - PointerVariant.values().map { + PointerVariant.entries.map { it to Translation(tl, "inventory.settings.pointers.${it.key}.name") }) } val SETTINGS_POINTERS_DESCRIPTIONS: Map = mutableMapOf().also { map -> map.putAll( - PointerVariant.values().map { + PointerVariant.entries.map { it to InventoryTranslation(tl, "inventory.settings.pointers.${it.key}.description") }) } diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/PlayerTrackable.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/PlayerTrackable.kt index 1148e61..1c7e4b3 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/PlayerTrackable.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/PlayerTrackable.kt @@ -14,9 +14,10 @@ class PlayerTrackable(private val plugin: WaypointsPlugin, val player: Player) : override val location: Location get() = player.location - override fun getHologramText(player: Player) = + override fun getHologramText(player: Player, translatedTarget: Location) = plugin.translations.POINTERS_HOLOGRAM_PLAYER_TRACKING.withReplacements( - "name" placeholder this.player.displayName(), *location.getResolvers(plugin, player)) + "name" placeholder this.player.displayName(), + *location.getResolvers(plugin, player, translatedTarget)) override val hologramItem = ItemStack(Material.PLAYER_HEAD).also { stack -> diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/TemporaryWaypointTrackable.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/TemporaryWaypointTrackable.kt index d8188fb..d29e582 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/TemporaryWaypointTrackable.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/TemporaryWaypointTrackable.kt @@ -11,9 +11,9 @@ class TemporaryWaypointTrackable( override val beaconColor: BeaconColor? = null, ) : StaticTrackable { - override fun getHologramText(player: Player) = + override fun getHologramText(player: Player, translatedTarget: Location) = plugin.apiExtensions.run { plugin.translations.POINTERS_HOLOGRAM_TEMPORARY.withReplacements( - *location.getResolvers(plugin, player)) + *location.getResolvers(plugin, player, translatedTarget)) } } diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/WaypointTrackable.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/WaypointTrackable.kt index 7343e28..fcd45bc 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/WaypointTrackable.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/pointers/WaypointTrackable.kt @@ -21,9 +21,11 @@ class WaypointTrackable(private val plugin: WaypointsPlugin, val waypoint: Waypo override val beaconColor: BeaconColor? get() = waypoint.beaconColor?.let { BeaconColor.byMaterial(it) } - override fun getHologramText(player: Player) = + override fun getHologramText(player: Player, translatedTarget: Location) = plugin.apiExtensions.run { - waypoint.getHologramTranslations().withReplacements(*waypoint.getResolvers(player)) + waypoint + .getHologramTranslations() + .withReplacements(*waypoint.getResolvers(player, translatedTarget)) } override val hologramItem = diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/APIExtensions.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/APIExtensions.kt index 45b3d87..493a8c7 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/APIExtensions.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/APIExtensions.kt @@ -14,6 +14,7 @@ import de.md5lukas.waypoints.gui.PlayerTrackingDisplayable import de.md5lukas.waypoints.gui.SharedDisplayable import de.md5lukas.waypoints.lang.InventoryTranslation import net.kyori.adventure.text.Component +import org.bukkit.Location import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack @@ -55,7 +56,7 @@ class APIExtensions(private val plugin: WaypointsPlugin) { return stack } - fun Waypoint.getResolvers(player: Player?) = + fun Waypoint.getResolvers(player: Player?, translatedTarget: Location = this.location) = arrayOf( "name" placeholder name, "description" placeholder (description ?: ""), @@ -69,8 +70,8 @@ class APIExtensions(private val plugin: WaypointsPlugin) { "block_x" placeholder location.blockX, "block_y" placeholder location.blockY, "block_z" placeholder location.blockZ, - if (player !== null && player.world === location.world) { - "distance" placeholder player.location.distance(location) + if (player !== null && player.world === translatedTarget.world) { + "distance" placeholder player.location.distance(translatedTarget) } else { "distance" placeholderIgnoringArguments translations.TEXT_DISTANCE_OTHER_WORLD.text }, diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/KyoriHelper.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/KyoriHelper.kt index 3881009..640fe28 100644 --- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/KyoriHelper.kt +++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/KyoriHelper.kt @@ -1,15 +1,19 @@ package de.md5lukas.waypoints.util import de.md5lukas.commons.paper.placeholder +import de.md5lukas.commons.paper.placeholderIgnoringArguments import de.md5lukas.waypoints.WaypointsPlugin -import kotlin.math.roundToLong import org.bukkit.Location import org.bukkit.entity.Player -fun Location.getResolvers(plugin: WaypointsPlugin, player: Player) = +fun Location.getResolvers(plugin: WaypointsPlugin, player: Player, translatedTarget: Location) = arrayOf( "world" placeholder plugin.worldTranslations.getWorldName(world!!), - "distance" placeholder player.location.distance(this).roundToLong(), + if (player.world === translatedTarget.world) { + "distance" placeholder player.location.distance(translatedTarget) + } else { + "distance" placeholderIgnoringArguments plugin.translations.TEXT_DISTANCE_OTHER_WORLD.text + }, "x" placeholder x, "y" placeholder y, "z" placeholder z, diff --git a/waypoints/src/main/resources/config.yml b/waypoints/src/main/resources/config.yml index a01f17b..e1ed26a 100644 --- a/waypoints/src/main/resources/config.yml +++ b/waypoints/src/main/resources/config.yml @@ -204,7 +204,7 @@ pointers: # Connected worlds in this list allow the translation of the coordinates 1:8, so you can for example navigate in the nether to a waypoint in the overworld connectedWorlds: - world: world_the_nether + world: world_nether actionBar: enabled: false