diff --git a/common/src/main/java/net/william278/huskhomes/config/Settings.java b/common/src/main/java/net/william278/huskhomes/config/Settings.java index d7307b26..666a5f35 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Settings.java +++ b/common/src/main/java/net/william278/huskhomes/config/Settings.java @@ -157,6 +157,9 @@ public final class Settings { @Comment("How long before received teleport requests expire (in seconds)") private int teleportRequestExpiryTime = 60; + @Comment("Whether /tpa should use the location of the sender when accepted. ") + private boolean strictTpaRequests = false; + @Comment("Whether /tpahere should use the location of the sender when sent. " + "Docs: https://william278.net/docs/huskhomes/strict-tpahere/") private boolean strictTpaHereRequests = true; diff --git a/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java b/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java index 9d976aac..094d46cd 100644 --- a/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java +++ b/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java @@ -308,6 +308,12 @@ public class RequestsManager { "teleport_request_" + (accepted ? "accepted" : "declined") + "_confirmation", request.getRequesterName() ).ifPresent(recipient::sendMessage); + // snapshot the recipient's position if the request is a strict tpa request + if (accepted && request.getType() == TeleportRequest.Type.TPA) { + if (plugin.getSettings().getGeneral().isStrictTpaRequests()) { + request.setRecipientPosition(recipient.getPosition()); + } + } // Find the requester and inform them of the response final Optional localRequester = plugin.getOnlineUserExact(request.getRequesterName()); @@ -363,11 +369,17 @@ public class RequestsManager { // If the request is a tpa request, teleport the requester to the recipient if (accepted && (request.getType() == TeleportRequest.Type.TPA)) { - Teleport.builder(plugin) + final TeleportBuilder builder = Teleport.builder(plugin) .teleporter(requester) - .target(request.getRecipientName()) - .actions(TransactionResolver.Action.ACCEPT_TELEPORT_REQUEST) - .buildAndComplete(true); + .actions(TransactionResolver.Action.ACCEPT_TELEPORT_REQUEST); + + // strictTPA: use the recipient's position at the time of acceptance + if (plugin.getSettings().getGeneral().isStrictTpaRequests() && request.getRecipientPosition() != null) { + builder.target(request.getRecipientPosition()); + } else { + builder.target(request.getRecipientName()); + } + builder.buildAndComplete(true); } } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportRequest.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportRequest.java index 0358acd2..5ac45f0a 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportRequest.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportRequest.java @@ -46,6 +46,9 @@ public class TeleportRequest { @SerializedName("requester_position") private Position requesterPosition; @Expose + @SerializedName("recipient_position") + private Position recipientPosition; + @Expose @SerializedName("expiry_time") @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)