mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
fix: issues with the send teleport request event (#873)
* Only send message feedback when the event is confirmed (not cancelled) * For the teleport request, set the recipient name for use in local lookup as well
This commit is contained in:
1 parent
f028d9671b
commit
af08134900
2 files changed
+19
-11
No files matched your search
@@ -72,17 +72,18 @@ public class TpRequestCommand extends InGameCommand implements UserListTabComple
|
||||
}
|
||||
|
||||
try {
|
||||
manager.sendTeleportRequest(onlineUser, target, requestType);
|
||||
manager.sendTeleportRequest(onlineUser, target, requestType, () -> handleSuccessfulRequest(onlineUser, target));
|
||||
} catch (IllegalArgumentException e) {
|
||||
plugin.getLocales().getLocale("error_player_not_found", target)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSuccessfulRequest(@NotNull OnlineUser onlineUser, @NotNull String target) {
|
||||
plugin.performTransaction(onlineUser, TransactionResolver.Action.SEND_TELEPORT_REQUEST);
|
||||
plugin.getLocales()
|
||||
.getLocale((requestType == TeleportRequest.Type.TPA ? "tpa" : "tpahere")
|
||||
+ "_request_sent", target)
|
||||
+ "_request_sent", target)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -145,12 +145,14 @@ public class RequestsManager {
|
||||
* @param requester The user making the request
|
||||
* @param targetUser The user to send the request to
|
||||
* @param type The type of request to send
|
||||
* @param callback A callback to run after the request has been sent (and the event has not been cancelled)
|
||||
*/
|
||||
public void sendTeleportRequest(@NotNull OnlineUser requester, @NotNull String targetUser,
|
||||
@NotNull TeleportRequest.Type type) throws IllegalArgumentException {
|
||||
@NotNull TeleportRequest.Type type, @NotNull Runnable callback) throws IllegalArgumentException {
|
||||
final long expiry = Instant.now().getEpochSecond()
|
||||
+ plugin.getSettings().getGeneral().getTeleportRequestExpiryTime();
|
||||
final TeleportRequest request = new TeleportRequest(requester, type, expiry);
|
||||
request.setRecipientName(targetUser);
|
||||
|
||||
// Lookup the user locally first. If there's a username match globally, perform an exact local check
|
||||
final Optional<OnlineUser> localTarget = plugin.isUserOnlineGlobally(targetUser)
|
||||
@@ -163,20 +165,25 @@ public class RequestsManager {
|
||||
throw new IllegalArgumentException("Cannot send a teleport request to a vanished player");
|
||||
}
|
||||
plugin.fireEvent(plugin.getSendTeleportRequestEvent(requester, request),
|
||||
(event -> sendLocalTeleportRequest(request, localTarget.get())));
|
||||
(event -> {
|
||||
sendLocalTeleportRequest(request, localTarget.get());
|
||||
callback.run();
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// If the player couldn't be found locally, send the request cross-server
|
||||
if (plugin.getSettings().getCrossServer().isEnabled()) {
|
||||
request.setRecipientName(targetUser);
|
||||
plugin.fireEvent(
|
||||
plugin.getSendTeleportRequestEvent(requester, request),
|
||||
(event -> plugin.getBroker().ifPresent(b -> Message.builder()
|
||||
.type(Message.MessageType.TELEPORT_REQUEST)
|
||||
.payload(Payload.teleportRequest(request))
|
||||
.target(targetUser, Message.TargetType.PLAYER)
|
||||
.build().send(b, requester)))
|
||||
(event -> {
|
||||
plugin.getBroker().ifPresent(b -> Message.builder()
|
||||
.type(Message.MessageType.TELEPORT_REQUEST)
|
||||
.payload(Payload.teleportRequest(request))
|
||||
.target(targetUser, Message.TargetType.PLAYER)
|
||||
.build().send(b, requester));
|
||||
callback.run();
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user