Skip to content

Commit

Permalink
Add player tracking requests.
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
Sytm committed Aug 25, 2023
1 parent acffa5b commit 73f7a3e
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 9 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.

3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
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.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

Expand Down Expand Up @@ -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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
5 changes: 5 additions & 0 deletions waypoints/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions waypoints/src/main/resources/lang/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ message:
playerNoLongerOnline: "<red>Der Spieler den du verfolgen möchtest ist nicht mehr online."
trackableRequired: "<red>Um andere Spieler verfolgen zu können musst du dich selbst sichtbar machen."
notification: "<gray>Der Spieler <yellow><name><gray> verfolgt dich."
request:
sent: "<gray>Eine Verfolgungsanfrage wurde an <yellow><to><gray> gesendet. Sie wird in <yellow><valid_for><gray> ablaufen."
request: "<yellow><from><gray> möchte deine Position verfolgen. Drücke auf diese Nachricht um die Anfrage zu akzeptieren. Diese Anfrage wird in <yellow><valid_for><gray> ablaufen."

pointers:
actionBar:
Expand Down
3 changes: 3 additions & 0 deletions waypoints/src/main/resources/lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ message:
playerNoLongerOnline: "<red>The player you are trying to track is no longer online."
trackableRequired: "<red>To track other players you must make yourself visible."
notification: "<gray>The player <yellow><name><gray> is tracking you."
request:
sent: "<gray>A tracking request has been sent to <yellow><to><gray>. It will expire in <yellow><valid_for><gray>."
request: "<yellow><from><gray> wants to track your location. Click this message to accept. This request will expire in <yellow><valid_for><gray>."

sharing:
alreadyShared: "<red>You have already shared this waypoint with <yellow><name></yellow>."
Expand Down

0 comments on commit 73f7a3e

Please sign in to comment.