diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index fdf8d99..f8467b4 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f59193..af62aa4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,11 @@
### Added
- Added feature flag for teleportations at `general.features.teleportation`
+- Added player tracking requests [#102](https://github.com/Sytm/waypoints/issues/102)
### Fixed
- Fixed another incorrect translation mapping
--
+
### Removed
- Java interoperability helpers for API
diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/tracking/PlayerTrackingConfiguration.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/tracking/PlayerTrackingConfiguration.kt
index 0b2c368..3d2019e 100644
--- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/tracking/PlayerTrackingConfiguration.kt
+++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/config/tracking/PlayerTrackingConfiguration.kt
@@ -1,6 +1,8 @@
package de.md5lukas.waypoints.config.tracking
+import de.md5lukas.konfig.ConfigPath
import de.md5lukas.konfig.Configurable
+import java.time.Duration
@Configurable
class PlayerTrackingConfiguration {
@@ -14,6 +16,14 @@ class PlayerTrackingConfiguration {
var trackingRequiresTrackable = false
private set
+ @ConfigPath("request.enabled")
+ var requestEnabled = false
+ private set
+
+ @ConfigPath("request.validFor")
+ var requestValidFor: Duration = Duration.ZERO
+ private set
+
var notification = false
private set
}
diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/PlayerTrackingPage.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/PlayerTrackingPage.kt
index 4f791f0..b99b954 100644
--- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/PlayerTrackingPage.kt
+++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/gui/pages/PlayerTrackingPage.kt
@@ -13,6 +13,7 @@ import de.md5lukas.waypoints.WaypointsPermissions
import de.md5lukas.waypoints.gui.WaypointsGUI
import de.md5lukas.waypoints.gui.items.TrackableToggleItem
import de.md5lukas.waypoints.pointers.PlayerTrackable
+import net.kyori.adventure.text.event.ClickEvent
import org.bukkit.entity.Player
import org.bukkit.inventory.meta.SkullMeta
@@ -63,13 +64,41 @@ class PlayerTrackingPage(
wpGUI.playSound { clickError }
wpGUI.translations.MESSAGE_TRACKING_PLAYER_NO_LONGER_ONLINE.send(wpGUI.viewer)
} else {
- wpGUI.playSound { playerSelected }
+ fun activatePlayerTracking() {
+ wpGUI.playSound { playerSelected }
+ wpGUI.plugin.pointerManager.enable(
+ wpGUI.viewer, PlayerTrackable(wpGUI.plugin, value))
+ if (wpGUI.plugin.waypointsConfig.playerTracking.notification) {
+ wpGUI.playSound { playerNotification }
+ wpGUI.translations.MESSAGE_TRACKING_NOTIFICATION.send(
+ value, "name" placeholder wpGUI.viewer.displayName())
+ }
+ }
+
wpGUI.viewer.closeInventory()
- wpGUI.plugin.pointerManager.enable(wpGUI.viewer, PlayerTrackable(wpGUI.plugin, value))
- if (wpGUI.plugin.waypointsConfig.playerTracking.notification) {
- wpGUI.playSound { playerNotification }
- wpGUI.translations.MESSAGE_TRACKING_NOTIFICATION.send(
- value, "name" placeholder wpGUI.viewer.displayName())
+
+ if (wpGUI.plugin.waypointsConfig.playerTracking.requestEnabled) {
+ val validFor = wpGUI.plugin.waypointsConfig.playerTracking.requestValidFor
+ val validForResolver =
+ "valid_for" placeholder wpGUI.plugin.durationFormatter.formatDuration(validFor)
+
+ wpGUI.translations.MESSAGE_TRACKING_REQUEST_SENT.send(
+ wpGUI.viewer,
+ "to" placeholder value.displayName(),
+ validForResolver,
+ )
+
+ value.sendMessage(
+ wpGUI.translations.MESSAGE_TRACKING_REQUEST_REQUEST.withReplacements(
+ "from" placeholder wpGUI.viewer.displayName(),
+ validForResolver,
+ )
+ .clickEvent(
+ ClickEvent.callback({ activatePlayerTracking() }) { options ->
+ options.lifetime(validFor)
+ }))
+ } else {
+ activatePlayerTracking()
}
}
}
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 1f8cd53..b4d38ef 100644
--- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/lang/Translations.kt
+++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/lang/Translations.kt
@@ -152,6 +152,8 @@ class Translations(tl: TranslationLoader) {
Translation(tl, "message.tracking.playerNoLongerOnline", PREFIX)
val MESSAGE_TRACKING_TRACKABLE_REQUIRED =
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_NOTIFICATION = Translation(tl, "message.tracking.notification", PREFIX)
val MESSAGE_SHARING_ALREADY_SHARED = Translation(tl, "message.sharing.alreadyShared", PREFIX)
diff --git a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/CommandAPI.kt b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/CommandAPI.kt
index c147e8e..2a1ffc2 100644
--- a/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/CommandAPI.kt
+++ b/waypoints/src/main/kotlin/de/md5lukas/waypoints/util/CommandAPI.kt
@@ -5,4 +5,4 @@ import dev.jorel.commandapi.executors.CommandArguments
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
val CommandArguments.labelResolver: TagResolver
- get() = "label" placeholder fullInput.substringBefore(' ').removePrefix("/")
+ get() = "label" placeholder fullInput().substringBefore(' ').removePrefix("/")
diff --git a/waypoints/src/main/resources/config.yml b/waypoints/src/main/resources/config.yml
index bd12230..a01f17b 100644
--- a/waypoints/src/main/resources/config.yml
+++ b/waypoints/src/main/resources/config.yml
@@ -190,6 +190,11 @@ playerTracking:
toggleable: true
# When true, players can only track other players when they themselves can be tracked by other players
trackingRequiresTrackable: false
+ request:
+ # When true, the player to be tracked first needs to accept the request of the tracking player to begin tracking
+ enabled: false
+ # The amount of time the request is valid for
+ validFor: 30s
# When true, the tracked player is notified when someone starts to track them
notification: true
diff --git a/waypoints/src/main/resources/lang/de.yml b/waypoints/src/main/resources/lang/de.yml
index 6dca6b0..9d3f383 100644
--- a/waypoints/src/main/resources/lang/de.yml
+++ b/waypoints/src/main/resources/lang/de.yml
@@ -219,6 +219,9 @@ message:
playerNoLongerOnline: "Der Spieler den du verfolgen möchtest ist nicht mehr online."
trackableRequired: "Um andere Spieler verfolgen zu können musst du dich selbst sichtbar machen."
notification: "Der Spieler verfolgt dich."
+ request:
+ sent: "Eine Verfolgungsanfrage wurde an gesendet. Sie wird in ablaufen."
+ request: " möchte deine Position verfolgen. Drücke auf diese Nachricht um die Anfrage zu akzeptieren. Diese Anfrage wird in ablaufen."
pointers:
actionBar:
diff --git a/waypoints/src/main/resources/lang/en.yml b/waypoints/src/main/resources/lang/en.yml
index f258ec8..c1a9f23 100644
--- a/waypoints/src/main/resources/lang/en.yml
+++ b/waypoints/src/main/resources/lang/en.yml
@@ -215,6 +215,9 @@ message:
playerNoLongerOnline: "The player you are trying to track is no longer online."
trackableRequired: "To track other players you must make yourself visible."
notification: "The player is tracking you."
+ request:
+ sent: "A tracking request has been sent to . It will expire in ."
+ request: " wants to track your location. Click this message to accept. This request will expire in ."
sharing:
alreadyShared: "You have already shared this waypoint with ."