mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 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 {
|
try {
|
||||||
manager.sendTeleportRequest(onlineUser, target, requestType);
|
manager.sendTeleportRequest(onlineUser, target, requestType, () -> handleSuccessfulRequest(onlineUser, target));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
plugin.getLocales().getLocale("error_player_not_found", target)
|
plugin.getLocales().getLocale("error_player_not_found", target)
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSuccessfulRequest(@NotNull OnlineUser onlineUser, @NotNull String target) {
|
||||||
plugin.performTransaction(onlineUser, TransactionResolver.Action.SEND_TELEPORT_REQUEST);
|
plugin.performTransaction(onlineUser, TransactionResolver.Action.SEND_TELEPORT_REQUEST);
|
||||||
plugin.getLocales()
|
plugin.getLocales()
|
||||||
.getLocale((requestType == TeleportRequest.Type.TPA ? "tpa" : "tpahere")
|
.getLocale((requestType == TeleportRequest.Type.TPA ? "tpa" : "tpahere")
|
||||||
+ "_request_sent", target)
|
+ "_request_sent", target)
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,12 +145,14 @@ public class RequestsManager {
|
|||||||
* @param requester The user making the request
|
* @param requester The user making the request
|
||||||
* @param targetUser The user to send the request to
|
* @param targetUser The user to send the request to
|
||||||
* @param type The type of request to send
|
* @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,
|
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()
|
final long expiry = Instant.now().getEpochSecond()
|
||||||
+ plugin.getSettings().getGeneral().getTeleportRequestExpiryTime();
|
+ plugin.getSettings().getGeneral().getTeleportRequestExpiryTime();
|
||||||
final TeleportRequest request = new TeleportRequest(requester, type, expiry);
|
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
|
// Lookup the user locally first. If there's a username match globally, perform an exact local check
|
||||||
final Optional<OnlineUser> localTarget = plugin.isUserOnlineGlobally(targetUser)
|
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");
|
throw new IllegalArgumentException("Cannot send a teleport request to a vanished player");
|
||||||
}
|
}
|
||||||
plugin.fireEvent(plugin.getSendTeleportRequestEvent(requester, request),
|
plugin.fireEvent(plugin.getSendTeleportRequestEvent(requester, request),
|
||||||
(event -> sendLocalTeleportRequest(request, localTarget.get())));
|
(event -> {
|
||||||
|
sendLocalTeleportRequest(request, localTarget.get());
|
||||||
|
callback.run();
|
||||||
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the player couldn't be found locally, send the request cross-server
|
// If the player couldn't be found locally, send the request cross-server
|
||||||
if (plugin.getSettings().getCrossServer().isEnabled()) {
|
if (plugin.getSettings().getCrossServer().isEnabled()) {
|
||||||
request.setRecipientName(targetUser);
|
|
||||||
plugin.fireEvent(
|
plugin.fireEvent(
|
||||||
plugin.getSendTeleportRequestEvent(requester, request),
|
plugin.getSendTeleportRequestEvent(requester, request),
|
||||||
(event -> plugin.getBroker().ifPresent(b -> Message.builder()
|
(event -> {
|
||||||
.type(Message.MessageType.TELEPORT_REQUEST)
|
plugin.getBroker().ifPresent(b -> Message.builder()
|
||||||
.payload(Payload.teleportRequest(request))
|
.type(Message.MessageType.TELEPORT_REQUEST)
|
||||||
.target(targetUser, Message.TargetType.PLAYER)
|
.payload(Payload.teleportRequest(request))
|
||||||
.build().send(b, requester)))
|
.target(targetUser, Message.TargetType.PLAYER)
|
||||||
|
.build().send(b, requester));
|
||||||
|
callback.run();
|
||||||
|
})
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user