Skip to content

Commit

Permalink
Allow bedrock clients to accept tracking requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytm committed Nov 2, 2024
1 parent 5100b69 commit 6bc8d73
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Option to disallow teleports to different worlds
- Variable containing the distance between a player and waypoint for the cost formula (`distance`)
- Option to hide waypoints that are in different worlds as the player
- Use custom Bedrock window to accept tracking request instead of (broken) clickable link in chat

### Fixed
- Warning that a world name has not been translated is printed multiple times
Expand Down
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "2.0.0"
coroutines = "1.8.1"
kotlin = "2.0.21"
coroutines = "1.9.0"
jvmToolchain = "21"
paper = "1.20.6-R0.1-SNAPSHOT"

Expand All @@ -26,7 +26,7 @@ pathfinder = { group = "de.md5lukas", name = "pathfinder", version = "1.0.0-SNAP

# (external)
schedulers = { group = "de.md5lukas", name = "schedulers", version = "1.0.1" }
skedule = { group = "de.md5lukas", name = "skedule", version = "2.0.0" }
skedule = { group = "de.md5lukas", name = "skedule", version = "2.0.1" }
anvilGui = { group = "de.md5lukas", name = "anvilgui", version = "2.0.0-SNAPSHOT" }
bStats = { group = "org.bstats", name = "bstats-bukkit", version = "3.0.2" }

Expand All @@ -39,6 +39,7 @@ dynmap-api = { group = "us.dynmap", name = "dynmap-api", version.ref = "dynmap"
squaremapApi = { group = "xyz.jpenilla", name = "squaremap-api", version = "1.2.3" }
bluemapApi = { group = "de.bluecolored.bluemap", name = "BlueMapAPI", version = "2.7.1" }
pl3xmap = { group = "maven.modrinth", name = "pl3xmap", version = "1.20.4-492" }
geyser = { group = "org.geysermc.geyser", name = "api", version = "2.4.2-SNAPSHOT" }

# Links to the various projects to check versions:
#
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion waypoints/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Run Paper Plugin Directory
run
run*
5 changes: 4 additions & 1 deletion waypoints/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repositories {
forRepository { maven("https://api.modrinth.com/maven") }
filter { includeGroup("maven.modrinth") }
}
maven("https://repo.opencollab.dev/main/") // Geyser
}

dependencies {
Expand Down Expand Up @@ -57,6 +58,7 @@ dependencies {
implementation(libs.squaremapApi)
implementation(libs.bluemapApi)
implementation(libs.pl3xmap)
implementation(libs.geyser)

// Testing
testImplementation(kotlin("test-junit5"))
Expand Down Expand Up @@ -133,7 +135,8 @@ tasks {

runServer {
dependsOn("jar")
minecraftVersion(libs.versions.paper.get().substringBefore('-'))
// minecraftVersion(libs.versions.paper.get().substringBefore('-'))
minecraftVersion("1.21.1")

downloadPlugins {
url(
Expand Down
25 changes: 17 additions & 8 deletions waypoints/src/main/kotlin/de/md5lukas/waypoints/WaypointsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import de.md5lukas.waypoints.config.general.TeleportPaymentType
import de.md5lukas.waypoints.events.ConfigReloadEvent
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.integrations.*
import de.md5lukas.waypoints.lang.Translations
import de.md5lukas.waypoints.lang.WorldTranslations
import de.md5lukas.waypoints.lang.YmlTranslationLoader
Expand Down Expand Up @@ -86,6 +82,9 @@ class WaypointsPlugin : JavaPlugin() {
?: throw IllegalStateException(
"The vault integration is configured to be used, but no vault compatible plugin is installed")

var geyserIntegration: GeyserIntegration? = null
private set

var dynMapIntegrationAvailable = false
private set

Expand Down Expand Up @@ -206,9 +205,19 @@ class WaypointsPlugin : JavaPlugin() {
}

private fun initIntegrations() {
val integration = VaultIntegration(this)
if (integration.setupEconomy()) {
vaultIntegration0 = integration
val vault = VaultIntegration(this)
if (vault.setupEconomy()) {
vaultIntegration0 = vault
}

if (waypointsConfig.integrations.geyser.enabled) {
val geyser = GeyserIntegration(this)
if (geyser.setupGeyser()) {
geyserIntegration = geyser
} else {
slF4JLogger.warn(
"The geyser integration is enabled in the config but geyser is not installed on this server")
}
}

if (waypointsConfig.general.features.globalWaypoints) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.md5lukas.waypoints.config.integrations

import de.md5lukas.konfig.ConfigPath
import de.md5lukas.konfig.Configurable

@Configurable
class GeyserConfiguration {

var enabled: Boolean = false
private set

@ConfigPath("icon.accept")
var acceptIcon: String = ""
private set

@ConfigPath("icon.decline")
var declineIcon: String = ""
private set
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import de.md5lukas.konfig.Configurable
@Configurable
class IntegrationsConfiguration {

val geyser = GeyserConfiguration()

val dynmap = DynMapConfiguration()
val squaremap = SquareMapConfiguration()
val bluemap = BlueMapConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import de.md5lukas.waypoints.WaypointsPermissions
import de.md5lukas.waypoints.gui.WaypointsGUI
import de.md5lukas.waypoints.gui.items.ToggleTrackableItem
import de.md5lukas.waypoints.pointers.PlayerTrackable
import java.time.Instant
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.minimessage.tag.Tag
Expand Down Expand Up @@ -84,6 +85,7 @@ class PlayerTrackingPage(
wpGUI.viewer.closeInventory()

if (wpGUI.plugin.waypointsConfig.playerTracking.requestEnabled) {
val geyser = wpGUI.plugin.geyserIntegration
val validFor = wpGUI.plugin.waypointsConfig.playerTracking.requestValidFor
val validForResolver =
"valid_for" placeholder wpGUI.plugin.durationFormatter.formatDuration(validFor)
Expand All @@ -94,17 +96,26 @@ class PlayerTrackingPage(
validForResolver,
)

value.sendMessage(
wpGUI.translations.MESSAGE_TRACKING_REQUEST_REQUEST.withReplacements(
"from" placeholder wpGUI.viewer.displayName(),
validForResolver,
TagResolver.resolver(
"accept",
Tag.styling(
ClickEvent.callback({ activatePlayerTracking() }) { options ->
options.lifetime(validFor)
})),
))
if (geyser?.isBedrockPlayer(value) == true) {
val validUntil = Instant.now().plus(validFor)
geyser.sendTrackingRequest(value, wpGUI.viewer, validForResolver) {
if (Instant.now().isBefore(validUntil)) {
activatePlayerTracking()
}
}
} else {
value.sendMessage(
wpGUI.translations.MESSAGE_TRACKING_REQUEST_REQUEST.withReplacements(
"from" placeholder wpGUI.viewer.displayName(),
validForResolver,
TagResolver.resolver(
"accept",
Tag.styling(
ClickEvent.callback({ activatePlayerTracking() }) { options ->
options.lifetime(validFor)
})),
))
}
} else {
activatePlayerTracking()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.md5lukas.waypoints.integrations

import de.md5lukas.commons.paper.placeholder
import de.md5lukas.waypoints.WaypointsPlugin
import de.md5lukas.waypoints.config.integrations.GeyserConfiguration
import de.md5lukas.waypoints.lang.Translations
import de.md5lukas.waypoints.util.asPlainText
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
import org.bukkit.entity.Player
import org.geysermc.cumulus.form.SimpleForm
import org.geysermc.cumulus.util.FormImage
import org.geysermc.geyser.api.GeyserApi

class GeyserIntegration(private val plugin: WaypointsPlugin) {

private val translations: Translations
get() = plugin.translations

private val config: GeyserConfiguration
get() = plugin.waypointsConfig.integrations.geyser

fun setupGeyser(): Boolean {
return plugin.server.pluginManager.getPlugin("Geyser-Spigot") !== null
}

fun isBedrockPlayer(player: Player): Boolean {
return GeyserApi.api().isBedrockPlayer(player.uniqueId)
}

fun sendTrackingRequest(
player: Player,
from: Player,
validForResolver: TagResolver,
onAccept: () -> Unit
) {
GeyserApi.api()
.sendForm(
player.uniqueId,
SimpleForm.builder()
.title(translations.MESSAGE_TRACKING_REQUEST_GEYSER_TITLE.text.asPlainText())
.content(
translations.MESSAGE_TRACKING_REQUEST_GEYSER_MESSAGE.withReplacements(
"from" placeholder from.displayName(),
validForResolver,
)
.asPlainText())
.button(
translations.MESSAGE_TRACKING_REQUEST_GEYSER_ACCEPT.text.asPlainText(),
FormImage.Type.PATH,
config.acceptIcon)
.button(
translations.MESSAGE_TRACKING_REQUEST_GEYSER_DECLINE.text.asPlainText(),
FormImage.Type.PATH,
config.declineIcon)
.validResultHandler { response ->
@Suppress(
"KotlinConstantConditions") // Annotation is messed up. The id is 0 based
if (response.clickedButtonId() == 0) {
onAccept()
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ class Translations(tl: TranslationLoader) {
Translation(tl, "message.tracking.trackableRequired", PREFIX)
val MESSAGE_TRACKING_REQUEST_SENT = Translation(tl, "message.tracking.request.sent", PREFIX)
val MESSAGE_TRACKING_REQUEST_REQUEST = Translation(tl, "message.tracking.request.request", PREFIX)
val MESSAGE_TRACKING_REQUEST_GEYSER_TITLE =
Translation(tl, "message.tracking.request.geyser.title")
val MESSAGE_TRACKING_REQUEST_GEYSER_MESSAGE =
Translation(tl, "message.tracking.request.geyser.message")
val MESSAGE_TRACKING_REQUEST_GEYSER_ACCEPT =
Translation(tl, "message.tracking.request.geyser.accept")
val MESSAGE_TRACKING_REQUEST_GEYSER_DECLINE =
Translation(tl, "message.tracking.request.geyser.decline")
val MESSAGE_TRACKING_NOTIFICATION = Translation(tl, "message.tracking.notification", PREFIX)

val MESSAGE_SHARING_ALREADY_SHARED = Translation(tl, "message.sharing.alreadyShared", PREFIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package de.md5lukas.waypoints.util
import de.md5lukas.commons.paper.placeholder
import de.md5lukas.commons.paper.placeholderIgnoringArguments
import de.md5lukas.waypoints.WaypointsPlugin
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
import org.bukkit.Location
import org.bukkit.entity.Player

Expand All @@ -21,3 +23,5 @@ fun Location.getResolvers(plugin: WaypointsPlugin, player: Player, translatedTar
"block_y" placeholder blockY,
"block_z" placeholder blockZ,
)

fun Component.asPlainText(): String = PlainTextComponentSerializer.plainText().serialize(this)
7 changes: 7 additions & 0 deletions waypoints/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ general:
distance: 1000.0

integrations:
geyser:
enabled: false

icon:
accept: "textures/ui/confirm"
decline: "textures/ui/redX1"

dynmap:
enabled: true
# See https://github.com/webbukkit/dynmap/wiki/Using-Markers#marker-icons for more information
Expand Down
7 changes: 7 additions & 0 deletions waypoints/src/main/resources/lang/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ message:
request: |
<yellow><from><gray> möchte deine Position verfolgen. Diese Anfrage wird in <yellow><valid_for><gray> ablaufen.
<gray>[<green><accept>Anfrage akzeptieren</accept><gray>]
geyser:
title: "Du hast eine Verfolgungsanfrage erhalten"
message: |
<from> möchte deine Position verfolgen.
Diese Anfrage wird in <valid_for> ablaufen.
accept: "Anfrage akzeptieren"
decline: "Anfrage ablehnen"

sharing:
alreadyShared: "<red>Du hast diesen Wegpunkt bereits mit <yellow><name></yellow> geteilt."
Expand Down
8 changes: 8 additions & 0 deletions waypoints/src/main/resources/lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ message:
request: |
<yellow><from><gray> wants to track your location. This request will expire in <yellow><valid_for><gray>.
<gray>[<green><accept>Accept request</accept><gray>]
geyser:
title: "You have received a tracking request"
message: |
<from> wants to track your location.
This request will expire in <valid_for>.
accept: "Accept request"
decline: "Decline request"


sharing:
alreadyShared: "<red>You have already shared this waypoint with <yellow><name></yellow>."
Expand Down
7 changes: 7 additions & 0 deletions waypoints/src/main/resources/lang/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ message:
request: |
<yellow><from><gray> desidera tracciare la tua posizione. Questa richiesta scadrà tra <yellow><valid_for><gray>.
<gray>[<green><accept>Accetta la richiesta</accept><gray>]
# geyser:
# title: "You have received a tracking request"
# message: |
# <from> wants to track your location.
# This request will expire in <valid_for>.
# accept: "Accept request"
# decline: "Decline request"

sharing:
alreadyShared: "<red>Hai già condiviso questo waypoint con <yellow><name></yellow>."
Expand Down
7 changes: 7 additions & 0 deletions waypoints/src/main/resources/lang/zh-hk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ message:
request: |
<yellow><from><gray> 想追蹤你的位置。 請求將在 <yellow><valid_for><gray> 內過期。
<gray>[<green><accept>接受請求</accept><gray>]
# geyser:
# title: "You have received a tracking request"
# message: |
# <from> wants to track your location.
# This request will expire in <valid_for>.
# accept: "Accept request"
# decline: "Decline request"

sharing:
alreadyShared: "<red>你已與 <yellow><name></yellow> 共享此座標。"
Expand Down
7 changes: 7 additions & 0 deletions waypoints/src/main/resources/lang/zh-simplified.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ message:
request: |
<yellow><from><gray> 想要获取你的位置. 该请求将会在 <yellow><valid_for><gray> 后过期.
<gray>[<green><accept>接受请求</accept><gray>]
# geyser:
# title: "You have received a tracking request"
# message: |
# <from> wants to track your location.
# This request will expire in <valid_for>.
# accept: "Accept request"
# decline: "Decline request"

sharing:
alreadyShared: "<red>你已经正在与玩家 <yellow><name></yellow> 分享路径点."
Expand Down
1 change: 1 addition & 0 deletions waypoints/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ softdepend:
- squaremap
- BlueMap
- Pl3xMap
- Geyser-Spigot

libraries:
- org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}
Expand Down

0 comments on commit 6bc8d73

Please sign in to comment.