mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Check for timeout in /tpa
and /tpaccept
. Fixes #818.
This commit adds a method called hasOutstandingTeleportRequest() in IUser - implemented fully in User.
This commit is contained in:
parent
6ade8132af
commit
ad94cca95b
5 changed files with 28 additions and 4 deletions
|
@ -43,6 +43,13 @@ public interface IUser {
|
||||||
|
|
||||||
void requestTeleport(final User player, final boolean here);
|
void requestTeleport(final User player, final boolean here);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this user has an outstanding teleport request to deal with.
|
||||||
|
*
|
||||||
|
* @return whether there is a teleport request
|
||||||
|
*/
|
||||||
|
boolean hasOutstandingTeleportRequest();
|
||||||
|
|
||||||
ITeleport getTeleport();
|
ITeleport getTeleport();
|
||||||
|
|
||||||
BigDecimal getMoney();
|
BigDecimal getMoney();
|
||||||
|
|
|
@ -241,6 +241,24 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasOutstandingTeleportRequest() {
|
||||||
|
if (getTeleportRequest() != null) { // Player has outstanding teleport request.
|
||||||
|
long timeout = ess.getSettings().getTpaAcceptCancellation();
|
||||||
|
if (timeout != 0) {
|
||||||
|
if ((System.currentTimeMillis() - getTeleportRequestTime()) / 1000 <= timeout) { // Player has outstanding request
|
||||||
|
return true;
|
||||||
|
} else { // outstanding request expired.
|
||||||
|
requestTeleport(null, false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else { // outstanding request does not expire
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getTeleportRequest() {
|
public UUID getTeleportRequest() {
|
||||||
return teleportRequester;
|
return teleportRequester;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class Commandtpa extends EssentialsCommand {
|
||||||
throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName()));
|
throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName()));
|
||||||
}
|
}
|
||||||
// Don't let sender request teleport twice to the same player.
|
// Don't let sender request teleport twice to the same player.
|
||||||
if (user.getConfigUUID().equals(player.getTeleportRequest())
|
if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout
|
||||||
&& player.isTpRequestHere() == false) { // Make sure the last teleport request was actually tpa and not tpahere
|
&& player.isTpRequestHere() == false) { // Make sure the last teleport request was actually tpa and not tpahere
|
||||||
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,7 @@ public class Commandtpaccept extends EssentialsCommand {
|
||||||
throw new Exception(tl("noPendingRequest"));
|
throw new Exception(tl("noPendingRequest"));
|
||||||
}
|
}
|
||||||
|
|
||||||
long timeout = ess.getSettings().getTpaAcceptCancellation();
|
if (user.hasOutstandingTeleportRequest()) {
|
||||||
if (timeout != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > timeout) {
|
|
||||||
user.requestTeleport(null, false);
|
user.requestTeleport(null, false);
|
||||||
throw new Exception(tl("requestTimedOut"));
|
throw new Exception(tl("requestTimedOut"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class Commandtpahere extends EssentialsCommand {
|
||||||
throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName()));
|
throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName()));
|
||||||
}
|
}
|
||||||
// Don't let sender request teleport twice to the same player.
|
// Don't let sender request teleport twice to the same player.
|
||||||
if (user.getConfigUUID().equals(player.getTeleportRequest())
|
if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout
|
||||||
&& player.isTpRequestHere() == true) { // Make sure the last teleport request was actually tpahere and not tpa
|
&& player.isTpRequestHere() == true) { // Make sure the last teleport request was actually tpahere and not tpa
|
||||||
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue