From ca390cff00863858f6ace4e7ecda1ee96233a790 Mon Sep 17 00:00:00 2001 From: JRoy Date: Sat, 28 Nov 2020 16:32:17 -0500 Subject: [PATCH 01/36] Housekeeping --- .../java/com/earth2me/essentials/User.java | 24 ++++++++++++++----- .../essentials/commands/Commandtpa.java | 5 ++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index d8de3fbbeae..3b0fbc13f12 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -41,28 +41,40 @@ public class User extends UserData implements Comparable, IMessageRecipient, net.ess3.api.IUser { private static final Logger logger = Logger.getLogger("Essentials"); + + // User modules private final IMessageRecipient messageRecipient; private transient final AsyncTeleport teleport; private transient final Teleport legacyTeleport; + + // User command confirmation strings private final Map confirmingPayments = new WeakHashMap<>(); + + // User teleport variables private transient UUID teleportRequester; private transient boolean teleportRequestHere; private transient Location teleportLocation; - private transient boolean vanished; private transient long teleportRequestTime; - private transient long lastOnlineActivity; - private transient long lastThrottledAction; - private transient long lastActivity = System.currentTimeMillis(); + + // User properties + private transient boolean vanished; private boolean hidden = false; private boolean rightClickJump = false; - private transient Location afkPosition = null; private boolean invSee = false; private boolean recipeSee = false; private boolean enderSee = false; - private transient long teleportInvulnerabilityTimestamp = 0; private boolean ignoreMsg = false; + + // User afk variables private String afkMessage; private long afkSince; + private transient Location afkPosition = null; + + // Misc + private transient long lastOnlineActivity; + private transient long lastThrottledAction; + private transient long lastActivity = System.currentTimeMillis(); + private transient long teleportInvulnerabilityTimestamp = 0; private String confirmingClearCommand; private long lastNotifiedAboutMailsMs; private String lastHomeConfirmation; diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java index 6233349e628..81125415277 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java @@ -37,11 +37,15 @@ public void run(final Server server, final User user, final String commandLabel, if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("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. if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout && !player.isTpRequestHere()) { // Make sure the last teleport request was actually tpa and not tpahere throw new Exception(tl("requestSentAlready", player.getDisplayName())); } + + if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) { final Trade charge = new Trade(this.getName(), ess); final AsyncTeleport teleport = user.getAsyncTeleport(); @@ -71,6 +75,7 @@ public void run(final Server server, final User user, final String commandLabel, player.sendMessage(tl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); } } + user.sendMessage(tl("requestSent", player.getDisplayName())); if (user.isAuthorized("essentials.tpacancel")) { user.sendMessage(tl("typeTpacancel")); From 5d785d97216cd166abc859bf7e96b582e741a4bb Mon Sep 17 00:00:00 2001 From: JRoy Date: Sun, 29 Nov 2020 23:52:20 -0500 Subject: [PATCH 02/36] Add support for multiple simultaneous tpa requests --- .../java/com/earth2me/essentials/IUser.java | 60 ++++++++-- .../java/com/earth2me/essentials/User.java | 106 +++++++++++------- .../essentials/commands/Commandtpa.java | 5 +- .../essentials/commands/Commandtpaall.java | 7 +- .../essentials/commands/Commandtpacancel.java | 17 +-- .../essentials/commands/Commandtpaccept.java | 54 +++++---- .../essentials/commands/Commandtpahere.java | 5 +- .../essentials/commands/Commandtpdeny.java | 29 ++++- .../src/main/resources/messages.properties | 10 +- Essentials/src/main/resources/plugin.yml | 8 +- 10 files changed, 200 insertions(+), 101 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 45c629440ee..3b2c7d25d94 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -11,10 +11,12 @@ import org.bukkit.entity.Player; import java.math.BigDecimal; + import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.regex.Pattern; /** @@ -54,13 +56,6 @@ public interface IUser { 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(); - /** * @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.api.IAsyncTeleport IAsyncTeleport} with {@link IUser#getAsyncTeleport()} */ @@ -94,8 +89,6 @@ public interface IUser { boolean canBuild(); - long getTeleportRequestTime(); - void enableInvulnerabilityAfterTeleport(); void resetInvulnerabilityAfterTeleport(); @@ -183,6 +176,8 @@ public interface IUser { String getName(); + UUID getUUID(); + String getDisplayName(); String getAfkMessage(); @@ -210,4 +205,51 @@ public interface IUser { Map getConfirmingPayments(); Block getTargetBlock(int maxDistance); + + TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean onlyHere); + + class TpaRequestToken { + private final String name; + private final UUID requesterUuid; + private boolean here; + private Location location; + private long time; + + public TpaRequestToken(String name, UUID requesterUuid) { + this.name = name; + this.requesterUuid = requesterUuid; + } + + public String getName() { + return name; + } + + public UUID getRequesterUuid() { + return requesterUuid; + } + + public boolean isHere() { + return here; + } + + public void setHere(boolean here) { + this.here = here; + } + + public Location getLocation() { + return location; + } + + public void setLocation(Location location) { + this.location = location; + } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } + } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 3b0fbc13f12..512e4ccc9ce 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -28,6 +28,8 @@ import java.math.BigDecimal; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -51,10 +53,7 @@ public class User extends UserData implements Comparable, IMessageRecipien private final Map confirmingPayments = new WeakHashMap<>(); // User teleport variables - private transient UUID teleportRequester; - private transient boolean teleportRequestHere; - private transient Location teleportLocation; - private transient long teleportRequestTime; + private final transient LinkedHashMap teleportRequestQueue = new LinkedHashMap<>(); // User properties private transient boolean vanished; @@ -93,9 +92,8 @@ public User(final Player base, final IEssentials ess) { this.messageRecipient = new SimpleMessageRecipient(ess, this); } - User update(final Player base) { + void update(final Player base) { setBase(base); - return this; } @Override @@ -297,44 +295,71 @@ public void setLogoutLocation() { @Override public void requestTeleport(final User player, final boolean here) { - teleportRequestTime = System.currentTimeMillis(); - teleportRequester = player == null ? null : player.getBase().getUniqueId(); - teleportRequestHere = here; - if (player == null) { - teleportLocation = null; - } else { - teleportLocation = here ? player.getLocation() : this.getLocation(); - } + final TpaRequestToken token = teleportRequestQueue.getOrDefault(player.getName(), new TpaRequestToken(player.getName(), player.getUUID())); + token.setTime(System.currentTimeMillis()); + token.setHere(here); + token.setLocation(here ? player.getLocation() : this.getLocation()); } - @Override - public boolean hasOutstandingTeleportRequest() { - if (getTeleportRequest() != null) { // Player has outstanding teleport request. - final 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 boolean hasPendingTpaRequests(boolean inform) { + getNextTpaToken(inform, false, false); + return !teleportRequestQueue.isEmpty(); + } + + public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { + final TpaRequestToken token = getOutstandingTpaRequest(playerUsername, false); + return token != null && token.isHere() == here; } - public UUID getTeleportRequest() { - return teleportRequester; + public TpaRequestToken getOutstandingTpaRequest(String playerUsername, boolean inform) { + if (!teleportRequestQueue.containsKey(playerUsername)) { + return null; + } + + final long timeout = ess.getSettings().getTpaAcceptCancellation(); + final TpaRequestToken token = teleportRequestQueue.get(playerUsername); + if (timeout < 1 || System.currentTimeMillis() - token.getTime() <= timeout * 1000) { + return token; + } + teleportRequestQueue.remove(playerUsername); + if (inform) { + sendMessage(tl("requestTimedOutFrom", ess.getUser(token.getRequesterUuid()).getDisplayName())); + } + return null; } - public boolean isTpRequestHere() { - return teleportRequestHere; + public TpaRequestToken removeTpaRequest(String playerUsername) { + return teleportRequestQueue.remove(playerUsername); } - public Location getTpRequestLocation() { - return teleportLocation; + @Override + public TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean onlyHere) { + if (teleportRequestQueue.size() == 0) { + return null; + } + + final long timeout = ess.getSettings().getTpaAcceptCancellation(); + final Iterator> iterator = teleportRequestQueue.entrySet().iterator(); + TpaRequestToken nextToken = null; + while (iterator.hasNext()) { + final TpaRequestToken token = iterator.next().getValue(); + if (timeout < 1 || (System.currentTimeMillis() - token.getTime()) <= timeout * 1000) { + if (onlyHere && !token.isHere()) { + continue; + } + if (shallow) { + return token; + } else if (nextToken == null) { + nextToken = token; + } + } else { + if (inform) { + sendMessage(tl("requestTimedOutFrom", ess.getUser(token.getRequesterUuid()).getDisplayName())); + } + iterator.remove(); + } + } + return nextToken; } public String getNick() { @@ -770,10 +795,6 @@ public boolean canBuild() { return ess.getPermissionsHandler().canBuild(base, getGroup()); } - public long getTeleportRequestTime() { - return teleportRequestTime; - } - public boolean isInvSee() { return invSee; } @@ -929,6 +950,11 @@ public String getName() { return this.getBase().getName(); } + @Override + public UUID getUUID() { + return this.getBase().getUniqueId(); + } + @Override public boolean isReachable() { return getBase().isOnline(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java index 81125415277..877e0b1f6a6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java @@ -38,14 +38,11 @@ public void run(final Server server, final User user, final String commandLabel, throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName())); } - // Don't let sender request teleport twice to the same player. - if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout - && !player.isTpRequestHere()) { // Make sure the last teleport request was actually tpa and not tpahere + if (player.hasOutstandingTpaRequest(user.getName(), false)) { throw new Exception(tl("requestSentAlready", player.getDisplayName())); } - if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) { final Trade charge = new Trade(this.getName(), ess); final AsyncTeleport teleport = user.getAsyncTeleport(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java index ca3b72896f9..6f114b1124a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java @@ -19,17 +19,17 @@ public Commandtpaall() { public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { if (sender.isPlayer()) { - teleportAAllPlayers(server, sender, ess.getUser(sender.getPlayer())); + teleportAAllPlayers(sender, ess.getUser(sender.getPlayer())); return; } throw new NotEnoughArgumentsException(); } final User target = getPlayer(server, sender, args, 0); - teleportAAllPlayers(server, sender, target); + teleportAAllPlayers(sender, target); } - private void teleportAAllPlayers(final Server server, final CommandSource sender, final User target) { + private void teleportAAllPlayers(final CommandSource sender, final User target) { sender.sendMessage(tl("teleportAAll")); for (final User player : ess.getOnlineUsers()) { if (target == player) { @@ -41,6 +41,7 @@ private void teleportAAllPlayers(final Server server, final CommandSource sender if (sender.getSender().equals(target.getBase()) && target.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !target.isAuthorized("essentials.worlds." + target.getWorld().getName())) { continue; } + try { final TPARequestEvent tpaEvent = new TPARequestEvent(sender, player, true); ess.getServer().getPluginManager().callEvent(tpaEvent); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpacancel.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpacancel.java index 2531b27999f..c73e3b7b6db 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpacancel.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpacancel.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; -import net.ess3.api.IEssentials; import org.bukkit.Server; import static com.earth2me.essentials.I18n.tl; @@ -15,20 +14,12 @@ public Commandtpacancel() { /** * Cancel {@link User}'s tp request if its {@code requester} is equal to the given {@code requester}. * - * @param ess ess instance * @param user user holding tp request * @param requester tp requester * @return whether tp was cancelled */ - public static boolean cancelTeleportRequest(final IEssentials ess, final User user, final User requester) throws Exception { - if (user.getTeleportRequest() != null) { - final User userRequester = ess.getUser(user.getTeleportRequest()); - if (requester.equals(userRequester)) { - user.requestTeleport(null, false); - return true; - } - } - return false; + public static boolean cancelTeleportRequest(final User user, final User requester) { + return user.removeTpaRequest(requester.getName()) != null; } @Override @@ -37,7 +28,7 @@ public void run(final Server server, final User user, final String commandLabel, int cancellations = 0; for (final User onlineUser : ess.getOnlineUsers()) { if (onlineUser == user) continue; - if (cancelTeleportRequest(ess, onlineUser, user)) { + if (cancelTeleportRequest(onlineUser, user)) { cancellations++; } } @@ -48,7 +39,7 @@ public void run(final Server server, final User user, final String commandLabel, } } else { final User targetPlayer = getPlayer(server, user, args, 0); - if (cancelTeleportRequest(ess, targetPlayer, user)) { + if (cancelTeleportRequest(targetPlayer, user)) { user.sendMessage(tl("teleportRequestSpecificCancelled", targetPlayer.getName())); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 77c5ecfc5cf..2c261ef17a6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.AsyncTeleport; +import com.earth2me.essentials.IUser; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Location; @@ -18,32 +19,48 @@ public Commandtpaccept() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final User requester; - try { - requester = ess.getUser(user.getTeleportRequest()); - } catch (final Exception ex) { - throw new Exception(tl("noPendingRequest")); - } + if (args.length > 0) { + if (args[0].startsWith("*") || args[0].equalsIgnoreCase("all")) { + if (!user.hasPendingTpaRequests(true)) { + throw new Exception(tl("noPendingRequest")); + } - if (!requester.getBase().isOnline()) { - throw new Exception(tl("noPendingRequest")); + IUser.TpaRequestToken token; + while ((token = user.getNextTpaToken(true, true, true)) != null) { + try { + handleTeleport(user, token, commandLabel); + } catch (Exception e) { + ess.showError(user.getSource(), e, commandLabel); + } finally { + user.removeTpaRequest(token.getName()); + } + } + throw new NoChargeException(); + } + handleTeleport(user, user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), true), commandLabel); + } else { + handleTeleport(user, user.getNextTpaToken(true, false, false), commandLabel); } + throw new NoChargeException(); + } - if (user.isTpRequestHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) { + private void handleTeleport(final User user, final IUser.TpaRequestToken token, String commandLabel) throws Exception { + if (token == null) { throw new Exception(tl("noPendingRequest")); } + final User requester = ess.getUser(token.getRequesterUuid()); - if (!user.isTpRequestHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) { + if (!requester.getBase().isOnline()) { + user.removeTpaRequest(token.getName()); throw new Exception(tl("noPendingRequest")); } - if (args.length > 0 && !requester.getName().contains(args[0])) { + if (token.isHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) { throw new Exception(tl("noPendingRequest")); } - if (!user.hasOutstandingTeleportRequest()) { - user.requestTeleport(null, false); - throw new Exception(tl("requestTimedOut")); + if (!token.isHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) { + throw new Exception(tl("noPendingRequest")); } final Trade charge = new Trade(this.getName(), ess); @@ -55,8 +72,8 @@ public void run(final Server server, final User user, final String commandLabel, user.sendMessage(tl("pendingTeleportCancelled")); return false; }); - if (user.isTpRequestHere()) { - final Location loc = user.getTpRequestLocation(); + if (token.isHere()) { + final Location loc = token.getLocation(); final AsyncTeleport teleport = requester.getAsyncTeleport(); teleport.setTpType(AsyncTeleport.TeleportType.TPA); future.thenAccept(success -> { @@ -64,14 +81,13 @@ public void run(final Server server, final User user, final String commandLabel, requester.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); } }); - teleport.teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND, future); + teleport.teleportPlayer(user, loc, charge, TeleportCause.COMMAND, future); } else { final AsyncTeleport teleport = requester.getAsyncTeleport(); teleport.setTpType(AsyncTeleport.TeleportType.TPA); teleport.teleport(user.getBase(), charge, TeleportCause.COMMAND, future); } - user.requestTeleport(null, false); - throw new NoChargeException(); + user.removeTpaRequest(token.getName()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpahere.java index 5a1a3e474f6..7d1c95cce83 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpahere.java @@ -33,11 +33,12 @@ public void run(final Server server, final User user, final String commandLabel, if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("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. - if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout - && player.isTpRequestHere()) { // Make sure the last teleport request was actually tpahere and not tpa + if (player.hasOutstandingTpaRequest(user.getName(), true)) { throw new Exception(tl("requestSentAlready", player.getDisplayName())); } + if (!player.isIgnoredPlayer(user)) { final TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, true); ess.getServer().getPluginManager().callEvent(tpaEvent); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index d9c23a791d7..7b7bf3b30f2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.IUser; import com.earth2me.essentials.User; import org.bukkit.Server; @@ -12,16 +13,38 @@ public Commandtpdeny() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (user.getTeleportRequest() == null) { + if (!user.hasPendingTpaRequests(false)) { throw new Exception(tl("noPendingRequest")); } - final User player = ess.getUser(user.getTeleportRequest()); + + final IUser.TpaRequestToken denyToken; + if (args.length > 0) { + if (args[0].startsWith("*") || args[0].equalsIgnoreCase("all")) { + IUser.TpaRequestToken token; + while ((token = user.getNextTpaToken(true, true, true)) != null) { + final User player = ess.getUser(token.getRequesterUuid()); + if (player != null) { + player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); + } + + user.removeTpaRequest(token.getName()); + } + user.sendMessage(tl("requestDeniedAll")); + return; + } else { + denyToken = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); + } + } else { + denyToken = user.getNextTpaToken(false, true, false); + } + + final User player = ess.getUser(denyToken.getRequesterUuid()); if (player == null) { throw new Exception(tl("noPendingRequest")); } user.sendMessage(tl("requestDenied")); player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); - user.requestTeleport(null, false); + user.removeTpaRequest(denyToken.getName()); } } diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 5a3828d8ac6..08b4e3c4db3 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -675,10 +675,12 @@ requestAcceptedAuto=\u00a76Automatically accepted a teleport request from {0}. requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request. requestAcceptedFromAuto=\u00a7c{0} \u00a76accepted your teleport request automatically. requestDenied=\u00a76Teleport request denied. +requestDeniedAll=\u00a76Denied all pending teleport requests. requestDeniedFrom=\u00a7c{0} \u00a76denied your teleport request. requestSent=\u00a76Request sent to\u00a7c {0}\u00a76. requestSentAlready=\u00a74You have already sent {0}\u00a74 a teleport request. requestTimedOut=\u00a74Teleport request has timed out. +requestTimedOutFrom=\u00a74Teleport request from \u00a7c{0} \u00a74has timed out. resetBal=\u00a76Balance has been reset to \u00a7c{0} \u00a76for all online players. resetBalAll=\u00a76Balance has been reset to \u00a7c{0} \u00a76for all players. rest=\u00a76You feel well rested. @@ -840,16 +842,16 @@ tpaallCommandDescription=Requests all players online to teleport to you. tpaallCommandUsage=/ tpacancelCommandDescription=Cancel all outstanding teleport requests. Specify [player] to cancel requests with them. tpacancelCommandUsage=/ [player] -tpacceptCommandDescription=Accepts a teleport request. -tpacceptCommandUsage=/ [otherplayer] +tpacceptCommandDescription=Accepts most recent teleport request or one from a specific player or all tpahere requests. +tpacceptCommandUsage=/ [*|player] tpahereCommandDescription=Request that the specified player teleport to you. tpahereCommandUsage=/ tpallCommandDescription=Teleport all online players to another player. tpallCommandUsage=/ tpautoCommandDescription=Automatically accept teleportation requests. tpautoCommandUsage=/ -tpdenyCommandDescription=Reject a teleport request. -tpdenyCommandUsage=/ +tpdenyCommandDescription=Rejects most recent teleport request or one from a specific player or all tpa requests. +tpdenyCommandUsage=/ [*|player] tphereCommandDescription=Teleport a player to you. tphereCommandUsage=/ tpoCommandDescription=Teleport override for tptoggle. diff --git a/Essentials/src/main/resources/plugin.yml b/Essentials/src/main/resources/plugin.yml index 0608bd842bd..f13dc95b155 100644 --- a/Essentials/src/main/resources/plugin.yml +++ b/Essentials/src/main/resources/plugin.yml @@ -497,8 +497,8 @@ commands: usage: / aliases: [etpaall] tpaccept: - description: Accepts a teleport request. - usage: / [otherplayer] + description: Accepts most recent teleport request or one from a specific player or all tpahere requests. + usage: / [*|player] aliases: [etpaccept,tpyes,etpyes] tpahere: description: Request that the specified player teleport to you. @@ -517,8 +517,8 @@ commands: usage: / [player] aliases: [etpacancel] tpdeny: - description: Reject a teleport request. - usage: / + description: Rejects most recent teleport request or one from a specific player or all tpa requests. + usage: / [*|player] aliases: [etpdeny,tpno,etpno] tphere: description: Teleport a player to you. From 1d1fd57d04598a3568363ef6e002db64fecd7301 Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 30 Nov 2020 00:09:50 -0500 Subject: [PATCH 03/36] Add queue size limit --- .../java/com/earth2me/essentials/ISettings.java | 2 ++ .../main/java/com/earth2me/essentials/Settings.java | 5 +++++ .../src/main/java/com/earth2me/essentials/User.java | 13 +++++++++++++ Essentials/src/main/resources/config.yml | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 2a2c4ffb973..3caee66ecd4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -239,6 +239,8 @@ public interface ISettings extends IConf { long getTpaAcceptCancellation(); + int getTpaMaxAmount(); + long getTeleportInvulnerability(); boolean isTeleportInvulnerability(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index a78222edd5e..56871a2121b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1121,6 +1121,11 @@ public long getTpaAcceptCancellation() { return config.getLong("tpa-accept-cancellation", 120); } + @Override + public int getTpaMaxAmount() { + return config.getInt("tpa-max-amount", 15); + } + private long _getTeleportInvulnerability() { return config.getLong("teleport-invulnerability", 0) * 1000; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 512e4ccc9ce..ab07b396b66 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -299,6 +299,19 @@ public void requestTeleport(final User player, final boolean here) { token.setTime(System.currentTimeMillis()); token.setHere(here); token.setLocation(here ? player.getLocation() : this.getLocation()); + + // Handle max queue size + teleportRequestQueue.remove(token.getName()); + if (teleportRequestQueue.size() >= ess.getSettings().getTpaMaxAmount()) { + String lastKey = null; + for (Map.Entry entry : teleportRequestQueue.entrySet()) { + lastKey = entry.getKey(); + } + teleportRequestQueue.remove(lastKey); + } + + // Add request to queue + teleportRequestQueue.put(token.getName(), token); } public boolean hasPendingTpaRequests(boolean inform) { diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 2ad976755d8..7b46ef43715 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -626,6 +626,11 @@ teleport-back-when-freed-from-jail: true # Set to 0 for no timeout. tpa-accept-cancellation: 120 +# The maximum amount of simultaneous tpa requests that can be pending for any given user. +# Once at this threshold, any new tpa requests will bump the oldest tpa requests out of queue. +# Defaults to 15. +tpa-max-amount: 15 + # Allow players to set hats by clicking on their helmet slot. allow-direct-hat: true From e30ba17c5cf26eda1ff25f2894d0ac3fa6f4ef83 Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 30 Nov 2020 10:20:52 -0500 Subject: [PATCH 04/36] Fix inverted parameter in IUser#getNextTpaToken --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- Essentials/src/main/java/com/earth2me/essentials/User.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 3b2c7d25d94..7fcd645a6e2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -206,7 +206,7 @@ public interface IUser { Block getTargetBlock(int maxDistance); - TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean onlyHere); + TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); class TpaRequestToken { private final String name; diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index ab07b396b66..adaaf06120d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -346,7 +346,7 @@ public TpaRequestToken removeTpaRequest(String playerUsername) { } @Override - public TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean onlyHere) { + public TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere) { if (teleportRequestQueue.size() == 0) { return null; } @@ -357,7 +357,7 @@ public TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean while (iterator.hasNext()) { final TpaRequestToken token = iterator.next().getValue(); if (timeout < 1 || (System.currentTimeMillis() - token.getTime()) <= timeout * 1000) { - if (onlyHere && !token.isHere()) { + if (excludeHere && token.isHere()) { continue; } if (shallow) { From 56d65fd393e899154ebb1c61e9a2696f05f90058 Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 30 Nov 2020 10:32:38 -0500 Subject: [PATCH 05/36] Reduce message spam --- .../com/earth2me/essentials/commands/Commandtpaccept.java | 6 +++++- .../com/earth2me/essentials/commands/Commandtpdeny.java | 6 ++++-- Essentials/src/main/resources/messages.properties | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 2c261ef17a6..4b954149e60 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -26,19 +26,24 @@ public void run(final Server server, final User user, final String commandLabel, } IUser.TpaRequestToken token; + int count = 0; while ((token = user.getNextTpaToken(true, true, true)) != null) { try { handleTeleport(user, token, commandLabel); + count++; } catch (Exception e) { ess.showError(user.getSource(), e, commandLabel); } finally { user.removeTpaRequest(token.getName()); } } + user.sendMessage(tl("requestAcceptedAll", count)); throw new NoChargeException(); } + user.sendMessage(tl("requestAccepted")); handleTeleport(user, user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), true), commandLabel); } else { + user.sendMessage(tl("requestAccepted")); handleTeleport(user, user.getNextTpaToken(true, false, false), commandLabel); } throw new NoChargeException(); @@ -64,7 +69,6 @@ private void handleTeleport(final User user, final IUser.TpaRequestToken token, } final Trade charge = new Trade(this.getName(), ess); - user.sendMessage(tl("requestAccepted")); requester.sendMessage(tl("requestAcceptedFrom", user.getDisplayName())); final CompletableFuture future = getNewExceptionFuture(requester.getSource(), commandLabel); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 7b7bf3b30f2..d07b07a2757 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -21,15 +21,17 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length > 0) { if (args[0].startsWith("*") || args[0].equalsIgnoreCase("all")) { IUser.TpaRequestToken token; - while ((token = user.getNextTpaToken(true, true, true)) != null) { + int count = 0; + while ((token = user.getNextTpaToken(false, true, true)) != null) { final User player = ess.getUser(token.getRequesterUuid()); if (player != null) { player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); } user.removeTpaRequest(token.getName()); + count++; } - user.sendMessage(tl("requestDeniedAll")); + user.sendMessage(tl("requestDeniedAll", count)); return; } else { denyToken = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 08b4e3c4db3..fe0cde75087 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -671,11 +671,12 @@ replyLastRecipientDisabledFor=\u00a76Replying to last message recipient \u00a7cd replyLastRecipientEnabled=\u00a76Replying to last message recipient \u00a7cenabled\u00a76. replyLastRecipientEnabledFor=\u00a76Replying to last message recipient \u00a7cenabled \u00a76for \u00a7c{0}\u00a76. requestAccepted=\u00a76Teleport request accepted. +requestAcceptedAll=\u00a76Accepted \u00a7c{0} \u00a76pending teleport request(s). requestAcceptedAuto=\u00a76Automatically accepted a teleport request from {0}. requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request. requestAcceptedFromAuto=\u00a7c{0} \u00a76accepted your teleport request automatically. requestDenied=\u00a76Teleport request denied. -requestDeniedAll=\u00a76Denied all pending teleport requests. +requestDeniedAll=\u00a76Denied \u00a7c{0} \u00a76pending teleport request(s). requestDeniedFrom=\u00a7c{0} \u00a76denied your teleport request. requestSent=\u00a76Request sent to\u00a7c {0}\u00a76. requestSentAlready=\u00a74You have already sent {0}\u00a74 a teleport request. From 5ec3e2584d4671508f2e5be8eabc78bd99255475 Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 30 Nov 2020 10:41:02 -0500 Subject: [PATCH 06/36] Add tab completions to tpaccept and tpdeny --- .../main/java/com/earth2me/essentials/User.java | 5 +++++ .../essentials/commands/Commandtpaccept.java | 15 ++++++++++++++- .../essentials/commands/Commandtpdeny.java | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index adaaf06120d..32ac4e2424d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -27,6 +27,7 @@ import java.math.BigDecimal; import java.util.Calendar; +import java.util.Collection; import java.util.GregorianCalendar; import java.util.Iterator; import java.util.LinkedHashMap; @@ -314,6 +315,10 @@ public void requestTeleport(final User player, final boolean here) { teleportRequestQueue.put(token.getName(), token); } + public Collection getPendingTpaKeys() { + return teleportRequestQueue.keySet(); + } + public boolean hasPendingTpaRequests(boolean inform) { getNextTpaToken(inform, false, false); return !teleportRequestQueue.isEmpty(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 4b954149e60..69de7224380 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -8,6 +8,9 @@ import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.CompletableFuture; import static com.earth2me.essentials.I18n.tl; @@ -49,6 +52,17 @@ public void run(final Server server, final User user, final String commandLabel, throw new NoChargeException(); } + @Override + protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { + if (args.length == 1) { + List options = new ArrayList<>(user.getPendingTpaKeys()); + options.add("*"); + return options; + } else { + return Collections.emptyList(); + } + } + private void handleTeleport(final User user, final IUser.TpaRequestToken token, String commandLabel) throws Exception { if (token == null) { throw new Exception(tl("noPendingRequest")); @@ -93,5 +107,4 @@ private void handleTeleport(final User user, final IUser.TpaRequestToken token, } user.removeTpaRequest(token.getName()); } - } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index d07b07a2757..f2c8aa74718 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -4,6 +4,10 @@ import com.earth2me.essentials.User; import org.bukkit.Server; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import static com.earth2me.essentials.I18n.tl; public class Commandtpdeny extends EssentialsCommand { @@ -49,4 +53,15 @@ public void run(final Server server, final User user, final String commandLabel, player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); user.removeTpaRequest(denyToken.getName()); } + + @Override + protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { + if (args.length == 1) { + List options = new ArrayList<>(user.getPendingTpaKeys()); + options.add("*"); + return options; + } else { + return Collections.emptyList(); + } + } } From f299421d1e8702fba038454dd9ed435f53841d11 Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 30 Nov 2020 10:53:25 -0500 Subject: [PATCH 07/36] Fix codestyle violations --- .../java/com/earth2me/essentials/commands/Commandtpaccept.java | 2 +- .../java/com/earth2me/essentials/commands/Commandtpdeny.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 69de7224380..f2975b2aee7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -55,7 +55,7 @@ public void run(final Server server, final User user, final String commandLabel, @Override protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { if (args.length == 1) { - List options = new ArrayList<>(user.getPendingTpaKeys()); + final List options = new ArrayList<>(user.getPendingTpaKeys()); options.add("*"); return options; } else { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index f2c8aa74718..954ef18143d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -57,7 +57,7 @@ public void run(final Server server, final User user, final String commandLabel, @Override protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { if (args.length == 1) { - List options = new ArrayList<>(user.getPendingTpaKeys()); + final List options = new ArrayList<>(user.getPendingTpaKeys()); options.add("*"); return options; } else { From 71144758bd41d0e9abe548521b15a5cca26de9ac Mon Sep 17 00:00:00 2001 From: JRoy Date: Tue, 19 Jan 2021 09:59:58 -0500 Subject: [PATCH 08/36] Add back deprecated APIs + Add javadocs for IUser#getNextTpaToken --- .../java/com/earth2me/essentials/IUser.java | 31 +++++++++++++++++++ .../java/com/earth2me/essentials/User.java | 13 ++++++++ 2 files changed, 44 insertions(+) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 7fcd645a6e2..5050b017888 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -56,6 +56,16 @@ public interface IUser { void requestTeleport(final User player, final boolean here); + /** + * Returns whether this user has an outstanding teleport request to deal with. + * + * @deprecated The teleport request system has been moved into a multi-user teleport request queue. + * @see IUser#getNextTpaToken(boolean, boolean, boolean) + * @return whether there is a teleport request + */ + @Deprecated + boolean hasOutstandingTeleportRequest(); + /** * @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.api.IAsyncTeleport IAsyncTeleport} with {@link IUser#getAsyncTeleport()} */ @@ -89,6 +99,13 @@ public interface IUser { boolean canBuild(); + /** + * @deprecated The teleport request system has been moved into a multi-user teleport request queue. + * @see IUser#getNextTpaToken(boolean, boolean, boolean) + */ + @Deprecated + long getTeleportRequestTime(); + void enableInvulnerabilityAfterTeleport(); void resetInvulnerabilityAfterTeleport(); @@ -206,6 +223,20 @@ public interface IUser { Block getTargetBlock(int maxDistance); + /** + * Gets information about the last-made tpa request in the tpa queue of this {@link IUser}. + * + * The TPA Queue is Last In First Out queue which stores all the active pending teleport + * requests of this {@link IUser}. Timeout calculations are also done turning this the + * iteration process of this method, ensuring that teleport requests made past the timeout + * period are removed from queue and therefore not returned here. The maximum size of this + * queue is determined by {@link ISettings#getTpaMaxAmount()}. + * + * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. + * @param shallow true if this method should not spend time validating time for all items in the queue and just return the first item in the queue. + * @param excludeHere true if /tphere requests should be ignored in fetching the next tpa token. + * @return A {@link TpaRequestToken} corresponding to the next available request or null if no valid request is present. + */ TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); class TpaRequestToken { diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 32ac4e2424d..93d097eba20 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -315,6 +315,12 @@ public void requestTeleport(final User player, final boolean here) { teleportRequestQueue.put(token.getName(), token); } + @Override + @Deprecated + public boolean hasOutstandingTeleportRequest() { + return getNextTpaToken(false, false, false) != null; + } + public Collection getPendingTpaKeys() { return teleportRequestQueue.keySet(); } @@ -813,6 +819,13 @@ public boolean canBuild() { return ess.getPermissionsHandler().canBuild(base, getGroup()); } + @Override + @Deprecated + public long getTeleportRequestTime() { + final TpaRequestToken token = getNextTpaToken(false, false, false); + return token == null ? 0L : token.getTime(); + } + public boolean isInvSee() { return invSee; } From 7d7d06556f13eb0e759c43af32c4e96ac51aaf16 Mon Sep 17 00:00:00 2001 From: JRoy Date: Tue, 19 Jan 2021 10:24:59 -0500 Subject: [PATCH 09/36] Abstract hasPendingTpaRequests into API --- .../java/com/earth2me/essentials/IUser.java | 11 ++++++++++- .../java/com/earth2me/essentials/User.java | 6 +++--- .../essentials/commands/Commandtpaccept.java | 15 +++++++++++---- .../essentials/commands/Commandtpdeny.java | 18 ++++++++++++------ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 5050b017888..3774ce9f457 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -60,7 +60,7 @@ public interface IUser { * Returns whether this user has an outstanding teleport request to deal with. * * @deprecated The teleport request system has been moved into a multi-user teleport request queue. - * @see IUser#getNextTpaToken(boolean, boolean, boolean) + * @see IUser#hasPendingTpaRequests(boolean, boolean) * @return whether there is a teleport request */ @Deprecated @@ -239,6 +239,15 @@ public interface IUser { */ TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); + /** + * Weather or not this {@link IUser} has any valid TPA request in queue. + * + * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. + * @param excludeHere true if /tphere requests should be ignored in checking if a tpa request is available. + * @return true if the user has an available pending request in queue. + */ + boolean hasPendingTpaRequests(boolean inform, boolean excludeHere); + class TpaRequestToken { private final String name; private final UUID requesterUuid; diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 93d097eba20..b8e2ff54c25 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -325,9 +325,9 @@ public Collection getPendingTpaKeys() { return teleportRequestQueue.keySet(); } - public boolean hasPendingTpaRequests(boolean inform) { - getNextTpaToken(inform, false, false); - return !teleportRequestQueue.isEmpty(); + @Override + public boolean hasPendingTpaRequests(boolean inform, boolean excludeHere) { + return getNextTpaToken(inform, false, excludeHere) != null; } public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index f2975b2aee7..0c29c39bf1a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -22,12 +22,19 @@ public Commandtpaccept() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { + final boolean excludeOthers; if (args.length > 0) { - if (args[0].startsWith("*") || args[0].equalsIgnoreCase("all")) { - if (!user.hasPendingTpaRequests(true)) { - throw new Exception(tl("noPendingRequest")); - } + excludeOthers = args[0].startsWith("*") || args[0].equalsIgnoreCase("all"); + } else { + excludeOthers = false; + } + if (!user.hasPendingTpaRequests(true, excludeOthers)) { + throw new Exception(tl("noPendingRequest")); + } + + if (args.length > 0) { + if (excludeOthers) { IUser.TpaRequestToken token; int count = 0; while ((token = user.getNextTpaToken(true, true, true)) != null) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 954ef18143d..dea161b07c4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -17,18 +17,25 @@ public Commandtpdeny() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (!user.hasPendingTpaRequests(false)) { + final boolean excludeOthers; + if (args.length > 0) { + excludeOthers = args[0].startsWith("*") || args[0].equalsIgnoreCase("all"); + } else { + excludeOthers = false; + } + + if (!user.hasPendingTpaRequests(false, excludeOthers)) { throw new Exception(tl("noPendingRequest")); } final IUser.TpaRequestToken denyToken; if (args.length > 0) { - if (args[0].startsWith("*") || args[0].equalsIgnoreCase("all")) { + if (excludeOthers) { IUser.TpaRequestToken token; int count = 0; while ((token = user.getNextTpaToken(false, true, true)) != null) { final User player = ess.getUser(token.getRequesterUuid()); - if (player != null) { + if (player != null && player.getBase().isOnline()) { player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); } @@ -37,15 +44,14 @@ public void run(final Server server, final User user, final String commandLabel, } user.sendMessage(tl("requestDeniedAll", count)); return; - } else { - denyToken = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); } + denyToken = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); } else { denyToken = user.getNextTpaToken(false, true, false); } final User player = ess.getUser(denyToken.getRequesterUuid()); - if (player == null) { + if (player == null || !player.getBase().isOnline()) { throw new Exception(tl("noPendingRequest")); } From 18d1f54b9b6f3f98112b63b8eefc13eb7fcbb430 Mon Sep 17 00:00:00 2001 From: JRoy Date: Tue, 19 Jan 2021 11:14:35 -0500 Subject: [PATCH 10/36] Change TpaRequestToken to TpaRequest --- .../java/com/earth2me/essentials/IUser.java | 8 +++---- .../java/com/earth2me/essentials/User.java | 24 +++++++++---------- .../essentials/commands/Commandtpaccept.java | 4 ++-- .../essentials/commands/Commandtpdeny.java | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 3774ce9f457..65d12930ebc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -235,9 +235,9 @@ public interface IUser { * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. * @param shallow true if this method should not spend time validating time for all items in the queue and just return the first item in the queue. * @param excludeHere true if /tphere requests should be ignored in fetching the next tpa token. - * @return A {@link TpaRequestToken} corresponding to the next available request or null if no valid request is present. + * @return A {@link TpaRequest} corresponding to the next available request or null if no valid request is present. */ - TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); + TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); /** * Weather or not this {@link IUser} has any valid TPA request in queue. @@ -248,14 +248,14 @@ public interface IUser { */ boolean hasPendingTpaRequests(boolean inform, boolean excludeHere); - class TpaRequestToken { + class TpaRequest { private final String name; private final UUID requesterUuid; private boolean here; private Location location; private long time; - public TpaRequestToken(String name, UUID requesterUuid) { + public TpaRequest(String name, UUID requesterUuid) { this.name = name; this.requesterUuid = requesterUuid; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index b8e2ff54c25..b4898f86697 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -54,7 +54,7 @@ public class User extends UserData implements Comparable, IMessageRecipien private final Map confirmingPayments = new WeakHashMap<>(); // User teleport variables - private final transient LinkedHashMap teleportRequestQueue = new LinkedHashMap<>(); + private final transient LinkedHashMap teleportRequestQueue = new LinkedHashMap<>(); // User properties private transient boolean vanished; @@ -296,7 +296,7 @@ public void setLogoutLocation() { @Override public void requestTeleport(final User player, final boolean here) { - final TpaRequestToken token = teleportRequestQueue.getOrDefault(player.getName(), new TpaRequestToken(player.getName(), player.getUUID())); + final TpaRequest token = teleportRequestQueue.getOrDefault(player.getName(), new TpaRequest(player.getName(), player.getUUID())); token.setTime(System.currentTimeMillis()); token.setHere(here); token.setLocation(here ? player.getLocation() : this.getLocation()); @@ -305,7 +305,7 @@ public void requestTeleport(final User player, final boolean here) { teleportRequestQueue.remove(token.getName()); if (teleportRequestQueue.size() >= ess.getSettings().getTpaMaxAmount()) { String lastKey = null; - for (Map.Entry entry : teleportRequestQueue.entrySet()) { + for (Map.Entry entry : teleportRequestQueue.entrySet()) { lastKey = entry.getKey(); } teleportRequestQueue.remove(lastKey); @@ -331,17 +331,17 @@ public boolean hasPendingTpaRequests(boolean inform, boolean excludeHere) { } public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { - final TpaRequestToken token = getOutstandingTpaRequest(playerUsername, false); + final TpaRequest token = getOutstandingTpaRequest(playerUsername, false); return token != null && token.isHere() == here; } - public TpaRequestToken getOutstandingTpaRequest(String playerUsername, boolean inform) { + public TpaRequest getOutstandingTpaRequest(String playerUsername, boolean inform) { if (!teleportRequestQueue.containsKey(playerUsername)) { return null; } final long timeout = ess.getSettings().getTpaAcceptCancellation(); - final TpaRequestToken token = teleportRequestQueue.get(playerUsername); + final TpaRequest token = teleportRequestQueue.get(playerUsername); if (timeout < 1 || System.currentTimeMillis() - token.getTime() <= timeout * 1000) { return token; } @@ -352,21 +352,21 @@ public TpaRequestToken getOutstandingTpaRequest(String playerUsername, boolean i return null; } - public TpaRequestToken removeTpaRequest(String playerUsername) { + public TpaRequest removeTpaRequest(String playerUsername) { return teleportRequestQueue.remove(playerUsername); } @Override - public TpaRequestToken getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere) { + public TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere) { if (teleportRequestQueue.size() == 0) { return null; } final long timeout = ess.getSettings().getTpaAcceptCancellation(); - final Iterator> iterator = teleportRequestQueue.entrySet().iterator(); - TpaRequestToken nextToken = null; + final Iterator> iterator = teleportRequestQueue.entrySet().iterator(); + TpaRequest nextToken = null; while (iterator.hasNext()) { - final TpaRequestToken token = iterator.next().getValue(); + final TpaRequest token = iterator.next().getValue(); if (timeout < 1 || (System.currentTimeMillis() - token.getTime()) <= timeout * 1000) { if (excludeHere && token.isHere()) { continue; @@ -822,7 +822,7 @@ public boolean canBuild() { @Override @Deprecated public long getTeleportRequestTime() { - final TpaRequestToken token = getNextTpaToken(false, false, false); + final TpaRequest token = getNextTpaToken(false, false, false); return token == null ? 0L : token.getTime(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 0c29c39bf1a..444a9c021db 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -35,7 +35,7 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length > 0) { if (excludeOthers) { - IUser.TpaRequestToken token; + IUser.TpaRequest token; int count = 0; while ((token = user.getNextTpaToken(true, true, true)) != null) { try { @@ -70,7 +70,7 @@ protected List getTabCompleteOptions(Server server, User user, String co } } - private void handleTeleport(final User user, final IUser.TpaRequestToken token, String commandLabel) throws Exception { + private void handleTeleport(final User user, final IUser.TpaRequest token, String commandLabel) throws Exception { if (token == null) { throw new Exception(tl("noPendingRequest")); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index dea161b07c4..42cd95333ce 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -28,10 +28,10 @@ public void run(final Server server, final User user, final String commandLabel, throw new Exception(tl("noPendingRequest")); } - final IUser.TpaRequestToken denyToken; + final IUser.TpaRequest denyToken; if (args.length > 0) { if (excludeOthers) { - IUser.TpaRequestToken token; + IUser.TpaRequest token; int count = 0; while ((token = user.getNextTpaToken(false, true, true)) != null) { final User player = ess.getUser(token.getRequesterUuid()); From ce57dd22b4bc68e6586ffba9fe183e33a2ef308b Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 8 Feb 2021 08:11:53 -0500 Subject: [PATCH 11/36] Fix small typo in javadocs --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 65d12930ebc..363df8dc635 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -226,8 +226,8 @@ public interface IUser { /** * Gets information about the last-made tpa request in the tpa queue of this {@link IUser}. * - * The TPA Queue is Last In First Out queue which stores all the active pending teleport - * requests of this {@link IUser}. Timeout calculations are also done turning this the + * The TPA Queue is Last-In-First-Out queue which stores all the active pending teleport + * requests of this {@link IUser}. Timeout calculations are also done during the * iteration process of this method, ensuring that teleport requests made past the timeout * period are removed from queue and therefore not returned here. The maximum size of this * queue is determined by {@link ISettings#getTpaMaxAmount()}. From 2e74dac93df90c19b53179c13a25778959c74441 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Mon, 10 May 2021 17:10:05 -0400 Subject: [PATCH 12/36] Typo --- Essentials/src/main/resources/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 05ea6fc287a..45fb8200391 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1223,7 +1223,7 @@ tpautoCommandUsage1Description=Toggles if tpa requests are auto accepted for you tpdenyCommandDescription=Rejects most recent teleport request or one from a specific player or all tpa requests. tpdenyCommandUsage=/ tpdenyCommandUsage1=/ [player] -tpdenyCommandUsage1Description=Rejects your most recent incoming teleport request or from the specified player +tpdenyCommandUsage1Description=Rejects the most recent incoming teleport request or from the specified player tpdenyCommandUsage2=/ * tpdenyCommandUsage2Description=Rejects all incoming teleport requests tphereCommandDescription=Teleport a player to you. From 5dd3c982ac028e7cf5536b5b5231d22da6b882e5 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 17:33:34 -0400 Subject: [PATCH 13/36] Update Essentials/src/main/java/com/earth2me/essentials/User.java Co-authored-by: Mariell Hoversholm --- Essentials/src/main/java/com/earth2me/essentials/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index e7f66c38cd2..6aacc9aa177 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -395,7 +395,7 @@ public TpaRequest removeTpaRequest(String playerUsername) { @Override public TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere) { - if (teleportRequestQueue.size() == 0) { + if (teleportRequestQueue.isEmpty()) { return null; } From 819b1e81dbf5d855d4d08554efaa56a07d54a90e Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 17:34:18 -0400 Subject: [PATCH 14/36] Update Essentials/src/main/java/com/earth2me/essentials/IUser.java --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 728d704492b..c2edb9fbf55 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -237,7 +237,7 @@ public interface IUser { boolean isToggleShout(); /** - * Gets information about the last-made tpa request in the tpa queue of this {@link IUser}. + * Gets information about the most recent tpa request in the tpa queue of this {@link IUser}. * * The TPA Queue is Last-In-First-Out queue which stores all the active pending teleport * requests of this {@link IUser}. Timeout calculations are also done during the From 1fb6653bf86bb00051b2ccbb59381a0662b5dbcc Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 18:13:54 -0400 Subject: [PATCH 15/36] Update Essentials/src/main/java/com/earth2me/essentials/IUser.java Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com> --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index c2edb9fbf55..d39de75bd13 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -256,7 +256,7 @@ public interface IUser { * Weather or not this {@link IUser} has any valid TPA request in queue. * * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. - * @param excludeHere true if /tphere requests should be ignored in checking if a tpa request is available. + * @param excludeHere true if /tpahere requests should be ignored in checking if a tpa request is available. * @return true if the user has an available pending request in queue. */ boolean hasPendingTpaRequests(boolean inform, boolean excludeHere); From 7efc535d18b0cac440c89e54ac077a0ac32d39f4 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 18:14:10 -0400 Subject: [PATCH 16/36] Update Essentials/src/main/java/com/earth2me/essentials/IUser.java Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com> --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index d39de75bd13..2804e631fb8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -253,7 +253,7 @@ public interface IUser { TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); /** - * Weather or not this {@link IUser} has any valid TPA request in queue. + * Whether or not this {@link IUser} has any valid TPA requests in queue. * * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. * @param excludeHere true if /tpahere requests should be ignored in checking if a tpa request is available. From 7d305e5c22ca7807da09b90c0af770c53ff36671 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 19:45:21 -0400 Subject: [PATCH 17/36] Update Essentials/src/main/java/com/earth2me/essentials/IUser.java Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com> --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 2804e631fb8..7004fa3ca39 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -238,7 +238,7 @@ public interface IUser { /** * Gets information about the most recent tpa request in the tpa queue of this {@link IUser}. - * + *

* The TPA Queue is Last-In-First-Out queue which stores all the active pending teleport * requests of this {@link IUser}. Timeout calculations are also done during the * iteration process of this method, ensuring that teleport requests made past the timeout From 9788eef6753a7e3793dfdaf7bdef9b25de5af7f7 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 21:06:01 -0400 Subject: [PATCH 18/36] Split up command usages --- .../src/main/resources/messages.properties | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 45fb8200391..38111ab71b3 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1204,10 +1204,12 @@ tpacancelCommandUsage2=/ tpacancelCommandUsage2Description=Cancels all your outstanding teleport request with the specified player tpacceptCommandDescription=Accepts a teleport request. tpacceptCommandUsage=/ [otherplayer] -tpacceptCommandUsage1=/ [player] -tpacceptCommandUsage1Description=Accepts the most recent incoming teleport request or from the specified player -tpacceptCommandUsage2=/ * -tpacceptCommandUsage2Description=Accepts all incoming teleport requests +tpacceptCommandUsage1=/ +tpacceptCommandUsage1Description=Accepts the most recent incoming teleport request +tpacceptCommandUsage2=/ +tpacceptCommandUsage2Description=Accepts an incoming teleport request from the specified player +tpacceptCommandUsage3=/ * +tpacceptCommandUsage3Description=Accepts all incoming teleport requests tpahereCommandDescription=Request that the specified player teleport to you. tpahereCommandUsage=/ tpahereCommandUsage1=/ @@ -1222,10 +1224,12 @@ tpautoCommandUsage1=/ [player] tpautoCommandUsage1Description=Toggles if tpa requests are auto accepted for yourself or another player if specified tpdenyCommandDescription=Rejects most recent teleport request or one from a specific player or all tpa requests. tpdenyCommandUsage=/ -tpdenyCommandUsage1=/ [player] -tpdenyCommandUsage1Description=Rejects the most recent incoming teleport request or from the specified player -tpdenyCommandUsage2=/ * -tpdenyCommandUsage2Description=Rejects all incoming teleport requests +tpdenyCommandUsage1=/ +tpdenyCommandUsage1Description=Rejects the most recent incoming teleport request +tpdenyCommandUsage2=/ +tpdenyCommandUsage2Description=Rejects an incoming teleport request from the specified player +tpdenyCommandUsage3=/ * +tpdenyCommandUsage3Description=Rejects all incoming teleport requests tphereCommandDescription=Teleport a player to you. tphereCommandUsage=/ tphereCommandUsage1=/ From a6b9b8b2283fd573ac92443b1f3a7824f3e5ef39 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 21:35:34 -0400 Subject: [PATCH 19/36] Rename a few method/param names --- .../src/main/java/com/earth2me/essentials/IUser.java | 11 ++++++----- .../src/main/java/com/earth2me/essentials/User.java | 10 +++++----- .../earth2me/essentials/commands/Commandtpaccept.java | 4 ++-- .../earth2me/essentials/commands/Commandtpdeny.java | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 7004fa3ca39..7fe8390c687 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -10,6 +10,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.Nullable; import java.math.BigDecimal; @@ -102,7 +103,7 @@ public interface IUser { /** * @deprecated The teleport request system has been moved into a multi-user teleport request queue. - * @see IUser#getNextTpaToken(boolean, boolean, boolean) + * @see IUser#getNextTpaRequest(boolean, boolean, boolean) */ @Deprecated long getTeleportRequestTime(); @@ -245,12 +246,12 @@ public interface IUser { * period are removed from queue and therefore not returned here. The maximum size of this * queue is determined by {@link ISettings#getTpaMaxAmount()}. * - * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. - * @param shallow true if this method should not spend time validating time for all items in the queue and just return the first item in the queue. - * @param excludeHere true if /tphere requests should be ignored in fetching the next tpa token. + * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. + * @param performExpirations true if this method should not spend time validating time for all items in the queue and just return the first item in the queue. + * @param excludeHere true if /tphere requests should be ignored in fetching the next tpa token. * @return A {@link TpaRequest} corresponding to the next available request or null if no valid request is present. */ - TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere); + @Nullable TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, boolean excludeHere); /** * Whether or not this {@link IUser} has any valid TPA requests in queue. diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 6aacc9aa177..5157158b01a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -355,7 +355,7 @@ public void requestTeleport(final User player, final boolean here) { @Override @Deprecated public boolean hasOutstandingTeleportRequest() { - return getNextTpaToken(false, false, false) != null; + return getNextTpaRequest(false, false, false) != null; } public Collection getPendingTpaKeys() { @@ -364,7 +364,7 @@ public Collection getPendingTpaKeys() { @Override public boolean hasPendingTpaRequests(boolean inform, boolean excludeHere) { - return getNextTpaToken(inform, false, excludeHere) != null; + return getNextTpaRequest(inform, false, excludeHere) != null; } public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { @@ -394,7 +394,7 @@ public TpaRequest removeTpaRequest(String playerUsername) { } @Override - public TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean excludeHere) { + public TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, boolean excludeHere) { if (teleportRequestQueue.isEmpty()) { return null; } @@ -408,7 +408,7 @@ public TpaRequest getNextTpaToken(boolean inform, boolean shallow, boolean exclu if (excludeHere && token.isHere()) { continue; } - if (shallow) { + if (performExpirations) { return token; } else if (nextToken == null) { nextToken = token; @@ -880,7 +880,7 @@ public boolean canBuild() { @Override @Deprecated public long getTeleportRequestTime() { - final TpaRequest token = getNextTpaToken(false, false, false); + final TpaRequest token = getNextTpaRequest(false, false, false); return token == null ? 0L : token.getTime(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 444a9c021db..39c8e288876 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -37,7 +37,7 @@ public void run(final Server server, final User user, final String commandLabel, if (excludeOthers) { IUser.TpaRequest token; int count = 0; - while ((token = user.getNextTpaToken(true, true, true)) != null) { + while ((token = user.getNextTpaRequest(true, true, true)) != null) { try { handleTeleport(user, token, commandLabel); count++; @@ -54,7 +54,7 @@ public void run(final Server server, final User user, final String commandLabel, handleTeleport(user, user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), true), commandLabel); } else { user.sendMessage(tl("requestAccepted")); - handleTeleport(user, user.getNextTpaToken(true, false, false), commandLabel); + handleTeleport(user, user.getNextTpaRequest(true, false, false), commandLabel); } throw new NoChargeException(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 42cd95333ce..84ff63f44ba 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -33,7 +33,7 @@ public void run(final Server server, final User user, final String commandLabel, if (excludeOthers) { IUser.TpaRequest token; int count = 0; - while ((token = user.getNextTpaToken(false, true, true)) != null) { + while ((token = user.getNextTpaRequest(false, true, true)) != null) { final User player = ess.getUser(token.getRequesterUuid()); if (player != null && player.getBase().isOnline()) { player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); @@ -47,7 +47,7 @@ public void run(final Server server, final User user, final String commandLabel, } denyToken = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); } else { - denyToken = user.getNextTpaToken(false, true, false); + denyToken = user.getNextTpaRequest(false, true, false); } final User player = ess.getUser(denyToken.getRequesterUuid()); From 96299f1713bb7b1668d2cdd31cb2124d13fcea7f Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 21:50:39 -0400 Subject: [PATCH 20/36] Add Nullable annotation to getOutstandingTpaRequest --- Essentials/src/main/java/com/earth2me/essentials/User.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 5157158b01a..96f7cf187e2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -29,6 +29,7 @@ import org.bukkit.inventory.PlayerInventory; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.checkerframework.checker.nullness.qual.Nullable; import java.math.BigDecimal; import java.util.Calendar; @@ -372,7 +373,7 @@ public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { return token != null && token.isHere() == here; } - public TpaRequest getOutstandingTpaRequest(String playerUsername, boolean inform) { + public @Nullable TpaRequest getOutstandingTpaRequest(String playerUsername, boolean inform) { if (!teleportRequestQueue.containsKey(playerUsername)) { return null; } From 48cf2f56c7a3c01c83fc7eb285b07f6276062393 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 21:51:15 -0400 Subject: [PATCH 21/36] Use TimeUnit for second to millisecond conversion --- Essentials/src/main/java/com/earth2me/essentials/User.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 96f7cf187e2..d2dc5a8c8a2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -43,6 +43,7 @@ import java.util.UUID; import java.util.WeakHashMap; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -405,7 +406,7 @@ public TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, TpaRequest nextToken = null; while (iterator.hasNext()) { final TpaRequest token = iterator.next().getValue(); - if (timeout < 1 || (System.currentTimeMillis() - token.getTime()) <= timeout * 1000) { + if (timeout < 1 || (System.currentTimeMillis() - token.getTime()) <= TimeUnit.SECONDS.toMillis(timeout)) { if (excludeHere && token.isHere()) { continue; } From 69501aa58efbfd941fbfba7da6dc881a241fb406 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 22:38:01 -0400 Subject: [PATCH 22/36] Whitespace lulw --- Essentials/src/main/java/com/earth2me/essentials/User.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index d2dc5a8c8a2..c3934ac6455 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -410,6 +410,7 @@ public TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, if (excludeHere && token.isHere()) { continue; } + if (performExpirations) { return token; } else if (nextToken == null) { From 8094a2609a80b702449ea3e2ebe090ec6efa3263 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 22:48:15 -0400 Subject: [PATCH 23/36] Move wildcard check to equals --- .../java/com/earth2me/essentials/commands/Commandtpaccept.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 39c8e288876..c2116bbcd37 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -24,7 +24,7 @@ public Commandtpaccept() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final boolean excludeOthers; if (args.length > 0) { - excludeOthers = args[0].startsWith("*") || args[0].equalsIgnoreCase("all"); + excludeOthers = args[0].equals("*") || args[0].equalsIgnoreCase("all"); } else { excludeOthers = false; } From c2befcf02df06deb996c8400d447940e161352f6 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 22:57:38 -0400 Subject: [PATCH 24/36] Fix variable name --- .../earth2me/essentials/commands/Commandtpaccept.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index c2116bbcd37..5b852725813 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -22,19 +22,19 @@ public Commandtpaccept() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final boolean excludeOthers; + final boolean excludeHere; if (args.length > 0) { - excludeOthers = args[0].equals("*") || args[0].equalsIgnoreCase("all"); + excludeHere = args[0].equals("*") || args[0].equalsIgnoreCase("all"); } else { - excludeOthers = false; + excludeHere = false; } - if (!user.hasPendingTpaRequests(true, excludeOthers)) { + if (!user.hasPendingTpaRequests(true, excludeHere)) { throw new Exception(tl("noPendingRequest")); } if (args.length > 0) { - if (excludeOthers) { + if (excludeHere) { IUser.TpaRequest token; int count = 0; while ((token = user.getNextTpaRequest(true, true, true)) != null) { From 7ed3ad62f12330011da692d195926e428c995a66 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 23:00:20 -0400 Subject: [PATCH 25/36] wtf is a token --- .../essentials/commands/Commandtpaccept.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 5b852725813..7adef243fe4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -70,22 +70,22 @@ protected List getTabCompleteOptions(Server server, User user, String co } } - private void handleTeleport(final User user, final IUser.TpaRequest token, String commandLabel) throws Exception { - if (token == null) { + private void handleTeleport(final User user, final IUser.TpaRequest request, String commandLabel) throws Exception { + if (request == null) { throw new Exception(tl("noPendingRequest")); } - final User requester = ess.getUser(token.getRequesterUuid()); + final User requester = ess.getUser(request.getRequesterUuid()); if (!requester.getBase().isOnline()) { - user.removeTpaRequest(token.getName()); + user.removeTpaRequest(request.getName()); throw new Exception(tl("noPendingRequest")); } - if (token.isHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) { + if (request.isHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) { throw new Exception(tl("noPendingRequest")); } - if (!token.isHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) { + if (!request.isHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) { throw new Exception(tl("noPendingRequest")); } @@ -97,8 +97,8 @@ private void handleTeleport(final User user, final IUser.TpaRequest token, Strin user.sendMessage(tl("pendingTeleportCancelled")); return false; }); - if (token.isHere()) { - final Location loc = token.getLocation(); + if (request.isHere()) { + final Location loc = request.getLocation(); final AsyncTeleport teleport = requester.getAsyncTeleport(); teleport.setTpType(AsyncTeleport.TeleportType.TPA); future.thenAccept(success -> { @@ -112,6 +112,6 @@ private void handleTeleport(final User user, final IUser.TpaRequest token, Strin teleport.setTpType(AsyncTeleport.TeleportType.TPA); teleport.teleport(user.getBase(), charge, TeleportCause.COMMAND, future); } - user.removeTpaRequest(token.getName()); + user.removeTpaRequest(request.getName()); } } From 204bcebf5b97667ecc5ea4609cfc2053bd9dec29 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 10 Jun 2021 23:01:12 -0400 Subject: [PATCH 26/36] Change in doc --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 7fe8390c687..4d62ac8e4d4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -238,7 +238,7 @@ public interface IUser { boolean isToggleShout(); /** - * Gets information about the most recent tpa request in the tpa queue of this {@link IUser}. + * Gets information about the most-recently-made, non-expired TPA request in the tpa queue of this {@link IUser}. *

* The TPA Queue is Last-In-First-Out queue which stores all the active pending teleport * requests of this {@link IUser}. Timeout calculations are also done during the From 7706db19f1d37f919ada722626843476c78d2443 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 11 Jun 2021 11:28:08 -0400 Subject: [PATCH 27/36] Add TeleportRequestAcceptEvent --- .../essentials/commands/Commandtpaccept.java | 11 +++ .../v2/events/TeleportRequestAcceptEvent.java | 67 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 7adef243fe4..2a43218310d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -4,6 +4,8 @@ import com.earth2me.essentials.IUser; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; +import net.essentialsx.api.v2.events.TeleportRequestAcceptEvent; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -89,6 +91,15 @@ private void handleTeleport(final User user, final IUser.TpaRequest request, Str throw new Exception(tl("noPendingRequest")); } + final TeleportRequestAcceptEvent event = new TeleportRequestAcceptEvent(user, requester, request); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + if (ess.getSettings().isDebug()) { + logger.info("TPA accept canceled by api for " + user.getName()); + } + return; + } + final Trade charge = new Trade(this.getName(), ess); requester.sendMessage(tl("requestAcceptedFrom", user.getDisplayName())); diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java new file mode 100644 index 00000000000..0753e138e65 --- /dev/null +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java @@ -0,0 +1,67 @@ +package net.essentialsx.api.v2.events; + +import com.earth2me.essentials.IUser; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a player accepts a teleport. + */ +public class TeleportRequestAcceptEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private final net.ess3.api.IUser requestee; + private final net.ess3.api.IUser requester; + private final IUser.TpaRequest tpaRequest; + private boolean canceled = false; + + public TeleportRequestAcceptEvent(net.ess3.api.IUser requestee, net.ess3.api.IUser requester, IUser.TpaRequest tpaRequest) { + this.requestee = requestee; + this.requester = requester; + this.tpaRequest = tpaRequest; + } + + /** + * Gets the user who is accepting this teleport request. + * @return the user accepting the request. + */ + public net.ess3.api.IUser getRequestee() { + return requestee; + } + + /** + * Gets the user who submitted this teleport request. + * @return the user who sent the request. + */ + public net.ess3.api.IUser getRequester() { + return requester; + } + + /** + * Gets information about this teleport request. + * @return the {@link com.earth2me.essentials.IUser.TpaRequest} object of this event. + */ + public IUser.TpaRequest getTpaRequest() { + return tpaRequest; + } + + @Override + public boolean isCancelled() { + return canceled; + } + + @Override + public void setCancelled(boolean cancel) { + this.canceled = cancel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} From 35a97371e61990c0635d1bb2c59cf81f378844bc Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:20:17 -0400 Subject: [PATCH 28/36] Apply suggestions from code review Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com> --- Essentials/src/main/java/com/earth2me/essentials/IUser.java | 2 +- .../java/com/earth2me/essentials/commands/Commandtpdeny.java | 2 +- .../api/v2/events/TeleportRequestAcceptEvent.java | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 4d62ac8e4d4..be37d45aaf5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -256,7 +256,7 @@ public interface IUser { /** * Whether or not this {@link IUser} has any valid TPA requests in queue. * - * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. + * @param inform true if the user should be informed if a request expires during iteration. * @param excludeHere true if /tpahere requests should be ignored in checking if a tpa request is available. * @return true if the user has an available pending request in queue. */ diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 84ff63f44ba..e923259affa 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -19,7 +19,7 @@ public Commandtpdeny() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final boolean excludeOthers; if (args.length > 0) { - excludeOthers = args[0].startsWith("*") || args[0].equalsIgnoreCase("all"); + excludeOthers = args[0].equals("*") || args[0].equalsIgnoreCase("all"); } else { excludeOthers = false; } diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java index 0753e138e65..f12d853dc60 100644 --- a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java @@ -52,6 +52,11 @@ public boolean isCancelled() { } @Override + /** + * Sets whether or not to cancel this teleport request. + * Note that cancelling this event will not show a message to users about the cancellation. + * @param cancel whether or not to cancel this teleport request. + */ public void setCancelled(boolean cancel) { this.canceled = cancel; } From 77185eb1480660ac23f65774dbe8c2c09d556afc Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:33:13 -0400 Subject: [PATCH 29/36] wtf is a token --- .../java/com/earth2me/essentials/IUser.java | 2 +- .../java/com/earth2me/essentials/User.java | 46 +++++++++---------- .../essentials/commands/Commandtpaccept.java | 8 ++-- .../essentials/commands/Commandtpdeny.java | 18 ++++---- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index be37d45aaf5..a5155994004 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -248,7 +248,7 @@ public interface IUser { * * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. * @param performExpirations true if this method should not spend time validating time for all items in the queue and just return the first item in the queue. - * @param excludeHere true if /tphere requests should be ignored in fetching the next tpa token. + * @param excludeHere true if /tphere requests should be ignored in fetching the next tpa request. * @return A {@link TpaRequest} corresponding to the next available request or null if no valid request is present. */ @Nullable TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, boolean excludeHere); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 6d6dece9c56..ab3953e011f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -335,13 +335,13 @@ public void setLogoutLocation() { @Override public void requestTeleport(final User player, final boolean here) { - final TpaRequest token = teleportRequestQueue.getOrDefault(player.getName(), new TpaRequest(player.getName(), player.getUUID())); - token.setTime(System.currentTimeMillis()); - token.setHere(here); - token.setLocation(here ? player.getLocation() : this.getLocation()); + final TpaRequest request = teleportRequestQueue.getOrDefault(player.getName(), new TpaRequest(player.getName(), player.getUUID())); + request.setTime(System.currentTimeMillis()); + request.setHere(here); + request.setLocation(here ? player.getLocation() : this.getLocation()); // Handle max queue size - teleportRequestQueue.remove(token.getName()); + teleportRequestQueue.remove(request.getName()); if (teleportRequestQueue.size() >= ess.getSettings().getTpaMaxAmount()) { String lastKey = null; for (Map.Entry entry : teleportRequestQueue.entrySet()) { @@ -351,7 +351,7 @@ public void requestTeleport(final User player, final boolean here) { } // Add request to queue - teleportRequestQueue.put(token.getName(), token); + teleportRequestQueue.put(request.getName(), request); } @Override @@ -370,8 +370,8 @@ public boolean hasPendingTpaRequests(boolean inform, boolean excludeHere) { } public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { - final TpaRequest token = getOutstandingTpaRequest(playerUsername, false); - return token != null && token.isHere() == here; + final TpaRequest request = getOutstandingTpaRequest(playerUsername, false); + return request != null && request.isHere() == here; } public @Nullable TpaRequest getOutstandingTpaRequest(String playerUsername, boolean inform) { @@ -380,13 +380,13 @@ public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) { } final long timeout = ess.getSettings().getTpaAcceptCancellation(); - final TpaRequest token = teleportRequestQueue.get(playerUsername); - if (timeout < 1 || System.currentTimeMillis() - token.getTime() <= timeout * 1000) { - return token; + final TpaRequest request = teleportRequestQueue.get(playerUsername); + if (timeout < 1 || System.currentTimeMillis() - request.getTime() <= timeout * 1000) { + return request; } teleportRequestQueue.remove(playerUsername); if (inform) { - sendMessage(tl("requestTimedOutFrom", ess.getUser(token.getRequesterUuid()).getDisplayName())); + sendMessage(tl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName())); } return null; } @@ -403,27 +403,27 @@ public TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, final long timeout = ess.getSettings().getTpaAcceptCancellation(); final Iterator> iterator = teleportRequestQueue.entrySet().iterator(); - TpaRequest nextToken = null; + TpaRequest nextRequest = null; while (iterator.hasNext()) { - final TpaRequest token = iterator.next().getValue(); - if (timeout < 1 || (System.currentTimeMillis() - token.getTime()) <= TimeUnit.SECONDS.toMillis(timeout)) { - if (excludeHere && token.isHere()) { + final TpaRequest request = iterator.next().getValue(); + if (timeout < 1 || (System.currentTimeMillis() - request.getTime()) <= TimeUnit.SECONDS.toMillis(timeout)) { + if (excludeHere && request.isHere()) { continue; } if (performExpirations) { - return token; - } else if (nextToken == null) { - nextToken = token; + return request; + } else if (nextRequest == null) { + nextRequest = request; } } else { if (inform) { - sendMessage(tl("requestTimedOutFrom", ess.getUser(token.getRequesterUuid()).getDisplayName())); + sendMessage(tl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName())); } iterator.remove(); } } - return nextToken; + return nextRequest; } public String getNick() { @@ -885,8 +885,8 @@ public boolean canBuild() { @Override @Deprecated public long getTeleportRequestTime() { - final TpaRequest token = getNextTpaRequest(false, false, false); - return token == null ? 0L : token.getTime(); + final TpaRequest request = getNextTpaRequest(false, false, false); + return request == null ? 0L : request.getTime(); } public boolean isInvSee() { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 2a43218310d..3d3161c8fd3 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -37,16 +37,16 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length > 0) { if (excludeHere) { - IUser.TpaRequest token; + IUser.TpaRequest request; int count = 0; - while ((token = user.getNextTpaRequest(true, true, true)) != null) { + while ((request = user.getNextTpaRequest(true, true, true)) != null) { try { - handleTeleport(user, token, commandLabel); + handleTeleport(user, request, commandLabel); count++; } catch (Exception e) { ess.showError(user.getSource(), e, commandLabel); } finally { - user.removeTpaRequest(token.getName()); + user.removeTpaRequest(request.getName()); } } user.sendMessage(tl("requestAcceptedAll", count)); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index e923259affa..9f2077381ca 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -28,36 +28,36 @@ public void run(final Server server, final User user, final String commandLabel, throw new Exception(tl("noPendingRequest")); } - final IUser.TpaRequest denyToken; + final IUser.TpaRequest denyRequest; if (args.length > 0) { if (excludeOthers) { - IUser.TpaRequest token; + IUser.TpaRequest request; int count = 0; - while ((token = user.getNextTpaRequest(false, true, true)) != null) { - final User player = ess.getUser(token.getRequesterUuid()); + while ((request = user.getNextTpaRequest(false, true, true)) != null) { + final User player = ess.getUser(request.getRequesterUuid()); if (player != null && player.getBase().isOnline()) { player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); } - user.removeTpaRequest(token.getName()); + user.removeTpaRequest(request.getName()); count++; } user.sendMessage(tl("requestDeniedAll", count)); return; } - denyToken = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); + denyRequest = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); } else { - denyToken = user.getNextTpaRequest(false, true, false); + denyRequest = user.getNextTpaRequest(false, true, false); } - final User player = ess.getUser(denyToken.getRequesterUuid()); + final User player = ess.getUser(denyRequest.getRequesterUuid()); if (player == null || !player.getBase().isOnline()) { throw new Exception(tl("noPendingRequest")); } user.sendMessage(tl("requestDenied")); player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); - user.removeTpaRequest(denyToken.getName()); + user.removeTpaRequest(denyRequest.getName()); } @Override From b3939f0676169a8f7e74119ea8225c9b5ebc275d Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:34:36 -0400 Subject: [PATCH 30/36] Clarify debug message --- .../java/com/earth2me/essentials/commands/Commandtpaccept.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 3d3161c8fd3..1be46b956b1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -95,7 +95,7 @@ private void handleTeleport(final User user, final IUser.TpaRequest request, Str Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { if (ess.getSettings().isDebug()) { - logger.info("TPA accept canceled by api for " + user.getName()); + logger.info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); } return; } From c0ce527dd95eee1c6eb103c41a094deb5d747812 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:37:03 -0400 Subject: [PATCH 31/36] Javadocs go over annotations pinapl --- .../essentialsx/api/v2/events/TeleportRequestAcceptEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java index f12d853dc60..0079bccc4b4 100644 --- a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java @@ -51,12 +51,12 @@ public boolean isCancelled() { return canceled; } - @Override /** * Sets whether or not to cancel this teleport request. * Note that cancelling this event will not show a message to users about the cancellation. * @param cancel whether or not to cancel this teleport request. */ + @Override public void setCancelled(boolean cancel) { this.canceled = cancel; } From 1ed3d8919708bf2bc208b305959b15116d25a3f7 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:55:35 -0400 Subject: [PATCH 32/36] Rename event + cover denials --- .../essentials/commands/Commandtpaccept.java | 4 ++-- .../essentials/commands/Commandtpdeny.java | 21 +++++++++++++++++++ ...java => TeleportRequestResponseEvent.java} | 20 +++++++++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) rename Essentials/src/main/java/net/essentialsx/api/v2/events/{TeleportRequestAcceptEvent.java => TeleportRequestResponseEvent.java} (71%) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 1be46b956b1..04113d53b4e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -4,7 +4,7 @@ import com.earth2me.essentials.IUser; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import net.essentialsx.api.v2.events.TeleportRequestAcceptEvent; +import net.essentialsx.api.v2.events.TeleportRequestResponseEvent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -91,7 +91,7 @@ private void handleTeleport(final User user, final IUser.TpaRequest request, Str throw new Exception(tl("noPendingRequest")); } - final TeleportRequestAcceptEvent event = new TeleportRequestAcceptEvent(user, requester, request); + final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, requester, request, true); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { if (ess.getSettings().isDebug()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 9f2077381ca..6918ce5d024 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -2,6 +2,8 @@ import com.earth2me.essentials.IUser; import com.earth2me.essentials.User; +import net.essentialsx.api.v2.events.TeleportRequestResponseEvent; +import org.bukkit.Bukkit; import org.bukkit.Server; import java.util.ArrayList; @@ -35,6 +37,16 @@ public void run(final Server server, final User user, final String commandLabel, int count = 0; while ((request = user.getNextTpaRequest(false, true, true)) != null) { final User player = ess.getUser(request.getRequesterUuid()); + + final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, player, request, false); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + if (ess.getSettings().isDebug()) { + logger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); + } + continue; + } + if (player != null && player.getBase().isOnline()) { player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); } @@ -55,6 +67,15 @@ public void run(final Server server, final User user, final String commandLabel, throw new Exception(tl("noPendingRequest")); } + final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, player, denyRequest, false); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + if (ess.getSettings().isDebug()) { + logger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); + } + return; + } + user.sendMessage(tl("requestDenied")); player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); user.removeTpaRequest(denyRequest.getName()); diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java similarity index 71% rename from Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java rename to Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java index 0079bccc4b4..89f654556e4 100644 --- a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestAcceptEvent.java +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java @@ -6,25 +6,27 @@ import org.bukkit.event.HandlerList; /** - * Called when a player accepts a teleport. + * Called when a player accepts or denies a teleport. */ -public class TeleportRequestAcceptEvent extends Event implements Cancellable { +public class TeleportRequestResponseEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final net.ess3.api.IUser requestee; private final net.ess3.api.IUser requester; private final IUser.TpaRequest tpaRequest; + private final boolean accept; private boolean canceled = false; - public TeleportRequestAcceptEvent(net.ess3.api.IUser requestee, net.ess3.api.IUser requester, IUser.TpaRequest tpaRequest) { + public TeleportRequestResponseEvent(net.ess3.api.IUser requestee, net.ess3.api.IUser requester, IUser.TpaRequest tpaRequest, boolean accept) { this.requestee = requestee; this.requester = requester; this.tpaRequest = tpaRequest; + this.accept = accept; } /** - * Gets the user who is accepting this teleport request. - * @return the user accepting the request. + * Gets the user who is accepting/denying this teleport request. + * @return the user accepting/denying the request. */ public net.ess3.api.IUser getRequestee() { return requestee; @@ -46,6 +48,14 @@ public IUser.TpaRequest getTpaRequest() { return tpaRequest; } + /** + * Whether or not this request has been accepted or denied. + * @return true if accepted otherwise false. + */ + public boolean isAccept() { + return accept; + } + @Override public boolean isCancelled() { return canceled; From 23e7345ce41b4309bc38a82fb55ca218a5ec13d2 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 6 Jul 2021 14:12:33 -0400 Subject: [PATCH 33/36] pop_review.ogg --- .../com/earth2me/essentials/ISettings.java | 2 +- .../java/com/earth2me/essentials/IUser.java | 2 +- .../java/com/earth2me/essentials/Settings.java | 4 ++-- .../java/com/earth2me/essentials/User.java | 2 +- Essentials/src/main/resources/config.yml | 6 +++--- .../src/main/resources/messages.properties | 18 +++++++++--------- Essentials/src/main/resources/plugin.yml | 8 ++++---- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 7a69a0087e7..2c9ce01dafd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -231,7 +231,7 @@ public interface ISettings extends IConf { long getTpaAcceptCancellation(); - int getTpaMaxAmount(); + int getTpaMaxRequests(); long getTeleportInvulnerability(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 88499045bd9..797df13e439 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -259,7 +259,7 @@ public interface IUser { * requests of this {@link IUser}. Timeout calculations are also done during the * iteration process of this method, ensuring that teleport requests made past the timeout * period are removed from queue and therefore not returned here. The maximum size of this - * queue is determined by {@link ISettings#getTpaMaxAmount()}. + * queue is determined by {@link ISettings#getTpaMaxRequests()}. * * @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration. * @param performExpirations true if this method should not spend time validating time for all items in the queue and just return the first item in the queue. diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 0b7aa584cf5..03be7fe8ac6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1233,8 +1233,8 @@ public long getTpaAcceptCancellation() { } @Override - public int getTpaMaxAmount() { - return config.getInt("tpa-max-amount", 15); + public int getTpaMaxRequests() { + return config.getInt("tpa-max-requests", 15); } private long _getTeleportInvulnerability() { diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index a67390d182e..64c5908d3b8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -347,7 +347,7 @@ public void requestTeleport(final User player, final boolean here) { // Handle max queue size teleportRequestQueue.remove(request.getName()); - if (teleportRequestQueue.size() >= ess.getSettings().getTpaMaxAmount()) { + if (teleportRequestQueue.size() >= ess.getSettings().getTpaMaxRequests()) { String lastKey = null; for (Map.Entry entry : teleportRequestQueue.entrySet()) { lastKey = entry.getKey(); diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index d375796070d..7cbe2aee39c 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -666,10 +666,10 @@ jail-online-time: false # Set to 0 for no timeout. tpa-accept-cancellation: 120 -# The maximum amount of simultaneous tpa requests that can be pending for any given user. -# Once at this threshold, any new tpa requests will bump the oldest tpa requests out of queue. +# The maximum number of simultaneous tpa requests that can be pending for any player. +# Once past this threshold, old requests will instantly time out. # Defaults to 15. -tpa-max-amount: 15 +tpa-max-requests: 15 # Allow players to set hats by clicking on their helmet slot. allow-direct-hat: true diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 9b96be21b36..fd10cb0c838 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -985,7 +985,7 @@ replyLastRecipientDisabledFor=\u00a76Replying to last message recipient \u00a7cd replyLastRecipientEnabled=\u00a76Replying to last message recipient \u00a7cenabled\u00a76. replyLastRecipientEnabledFor=\u00a76Replying to last message recipient \u00a7cenabled \u00a76for \u00a7c{0}\u00a76. requestAccepted=\u00a76Teleport request accepted. -requestAcceptedAll=\u00a76Accepted \u00a7c{0} \u00a76pending teleport request(s). +requestAcceptedAll=\u00a76Denied \u00a7c{0} \u00a76pending teleport request(s). requestAcceptedAuto=\u00a76Automatically accepted a teleport request from {0}. requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request. requestAcceptedFromAuto=\u00a7c{0} \u00a76accepted your teleport request automatically. @@ -1255,14 +1255,14 @@ tpacancelCommandUsage1=/ tpacancelCommandUsage1Description=Cancels all your outstanding teleport requests tpacancelCommandUsage2=/ tpacancelCommandUsage2Description=Cancels all your outstanding teleport request with the specified player -tpacceptCommandDescription=Accepts a teleport request. +tpacceptCommandDescription=Accepts teleport requests. tpacceptCommandUsage=/ [otherplayer] tpacceptCommandUsage1=/ -tpacceptCommandUsage1Description=Accepts the most recent incoming teleport request +tpacceptCommandUsage1Description=Accepts the most recent teleport request tpacceptCommandUsage2=/ -tpacceptCommandUsage2Description=Accepts an incoming teleport request from the specified player +tpacceptCommandUsage2Description=Accepts a teleport request from the specified player tpacceptCommandUsage3=/ * -tpacceptCommandUsage3Description=Accepts all incoming teleport requests +tpacceptCommandUsage3Description=Accepts all teleport requests tpahereCommandDescription=Request that the specified player teleport to you. tpahereCommandUsage=/ tpahereCommandUsage1=/ @@ -1275,14 +1275,14 @@ tpautoCommandDescription=Automatically accept teleportation requests. tpautoCommandUsage=/ [player] tpautoCommandUsage1=/ [player] tpautoCommandUsage1Description=Toggles if tpa requests are auto accepted for yourself or another player if specified -tpdenyCommandDescription=Rejects most recent teleport request or one from a specific player or all tpa requests. +tpdenyCommandDescription=Rejects teleport requests. tpdenyCommandUsage=/ tpdenyCommandUsage1=/ -tpdenyCommandUsage1Description=Rejects the most recent incoming teleport request +tpdenyCommandUsage1Description=Rejects the most recent teleport request tpdenyCommandUsage2=/ -tpdenyCommandUsage2Description=Rejects an incoming teleport request from the specified player +tpdenyCommandUsage2Description=Rejects a teleport request from the specified player tpdenyCommandUsage3=/ * -tpdenyCommandUsage3Description=Rejects all incoming teleport requests +tpdenyCommandUsage3Description=Rejects all teleport requests tphereCommandDescription=Teleport a player to you. tphereCommandUsage=/ tphereCommandUsage1=/ diff --git a/Essentials/src/main/resources/plugin.yml b/Essentials/src/main/resources/plugin.yml index 8460a90622b..032e3f06e82 100644 --- a/Essentials/src/main/resources/plugin.yml +++ b/Essentials/src/main/resources/plugin.yml @@ -505,8 +505,8 @@ commands: usage: / aliases: [etpaall] tpaccept: - description: Accepts most recent teleport request or one from a specific player or all tpahere requests. - usage: / [*|player] + description: Accepts teleport requests. + usage: / [player|*] aliases: [etpaccept,tpyes,etpyes] tpahere: description: Request that the specified player teleport to you. @@ -525,8 +525,8 @@ commands: usage: / [player] aliases: [etpacancel] tpdeny: - description: Rejects most recent teleport request or one from a specific player or all tpa requests. - usage: / [*|player] + description: Rejects teleport requests. + usage: / [player|*] aliases: [etpdeny,tpno,etpno] tphere: description: Teleport a player to you. From 5226e0313346e7f1a9d3196459316d584ae2389d Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sat, 10 Jul 2021 10:54:13 -0400 Subject: [PATCH 34/36] Review comments --- .../main/java/com/earth2me/essentials/Settings.java | 2 +- .../api/v2/events/TeleportRequestResponseEvent.java | 12 ++++++++++-- Essentials/src/main/resources/config.yml | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 03be7fe8ac6..b691030d99c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1234,7 +1234,7 @@ public long getTpaAcceptCancellation() { @Override public int getTpaMaxRequests() { - return config.getInt("tpa-max-requests", 15); + return config.getInt("tpa-max-requests", 5); } private long _getTeleportInvulnerability() { diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java index 89f654556e4..66bd2cd81bc 100644 --- a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportRequestResponseEvent.java @@ -49,13 +49,21 @@ public IUser.TpaRequest getTpaRequest() { } /** - * Whether or not this request has been accepted or denied. - * @return true if accepted otherwise false. + * Whether or not the request has been accepted. + * @return true if accepted, false if denied. */ public boolean isAccept() { return accept; } + /** + * Whether or not the request has been denied. + * @return true if denied, false if accepted. + */ + public boolean isDeny() { + return !isAccept(); + } + @Override public boolean isCancelled() { return canceled; diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 7cbe2aee39c..c33552b0270 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -668,8 +668,8 @@ tpa-accept-cancellation: 120 # The maximum number of simultaneous tpa requests that can be pending for any player. # Once past this threshold, old requests will instantly time out. -# Defaults to 15. -tpa-max-requests: 15 +# Defaults to 5. +tpa-max-requests: 5 # Allow players to set hats by clicking on their helmet slot. allow-direct-hat: true From 25085f5022297b8bb67fd999da214a15fafb9794 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Sun, 29 Aug 2021 11:46:23 +0100 Subject: [PATCH 35/36] Thanks triagonal --- Essentials/src/main/resources/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index f0443f20d6c..835277e93b8 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -995,7 +995,7 @@ replyLastRecipientDisabledFor=\u00a76Replying to last message recipient \u00a7cd replyLastRecipientEnabled=\u00a76Replying to last message recipient \u00a7cenabled\u00a76. replyLastRecipientEnabledFor=\u00a76Replying to last message recipient \u00a7cenabled \u00a76for \u00a7c{0}\u00a76. requestAccepted=\u00a76Teleport request accepted. -requestAcceptedAll=\u00a76Denied \u00a7c{0} \u00a76pending teleport request(s). +requestAcceptedAll=\u00a76Accepted \u00a7c{0} \u00a76pending teleport request(s). requestAcceptedAuto=\u00a76Automatically accepted a teleport request from {0}. requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request. requestAcceptedFromAuto=\u00a7c{0} \u00a76accepted your teleport request automatically. From bebb60ebf36581407ccac5767ad8324213cc6a22 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sat, 20 Nov 2021 17:49:11 -0500 Subject: [PATCH 36/36] Reduce duplicated code + improve variable names --- .../essentials/commands/Commandtpaall.java | 6 +- .../essentials/commands/Commandtpaccept.java | 40 +++++----- .../essentials/commands/Commandtpdeny.java | 74 ++++++++++--------- 3 files changed, 66 insertions(+), 54 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java index 6f114b1124a..5b0ec1b8a88 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java @@ -19,17 +19,17 @@ public Commandtpaall() { public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { if (sender.isPlayer()) { - teleportAAllPlayers(sender, ess.getUser(sender.getPlayer())); + tpaAll(sender, ess.getUser(sender.getPlayer())); return; } throw new NotEnoughArgumentsException(); } final User target = getPlayer(server, sender, args, 0); - teleportAAllPlayers(sender, target); + tpaAll(sender, target); } - private void teleportAAllPlayers(final CommandSource sender, final User target) { + private void tpaAll(final CommandSource sender, final User target) { sender.sendMessage(tl("teleportAAll")); for (final User player : ess.getOnlineUsers()) { if (target == player) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 04113d53b4e..cabdeb8cae9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -24,32 +24,20 @@ public Commandtpaccept() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final boolean excludeHere; + final boolean acceptAll; if (args.length > 0) { - excludeHere = args[0].equals("*") || args[0].equalsIgnoreCase("all"); + acceptAll = args[0].equals("*") || args[0].equalsIgnoreCase("all"); } else { - excludeHere = false; + acceptAll = false; } - if (!user.hasPendingTpaRequests(true, excludeHere)) { + if (!user.hasPendingTpaRequests(true, acceptAll)) { throw new Exception(tl("noPendingRequest")); } if (args.length > 0) { - if (excludeHere) { - IUser.TpaRequest request; - int count = 0; - while ((request = user.getNextTpaRequest(true, true, true)) != null) { - try { - handleTeleport(user, request, commandLabel); - count++; - } catch (Exception e) { - ess.showError(user.getSource(), e, commandLabel); - } finally { - user.removeTpaRequest(request.getName()); - } - } - user.sendMessage(tl("requestAcceptedAll", count)); + if (acceptAll) { + acceptAllRequests(user, commandLabel); throw new NoChargeException(); } user.sendMessage(tl("requestAccepted")); @@ -61,6 +49,22 @@ public void run(final Server server, final User user, final String commandLabel, throw new NoChargeException(); } + private void acceptAllRequests(final User user, final String commandLabel) throws Exception { + IUser.TpaRequest request; + int count = 0; + while ((request = user.getNextTpaRequest(true, true, true)) != null) { + try { + handleTeleport(user, request, commandLabel); + count++; + } catch (Exception e) { + ess.showError(user.getSource(), e, commandLabel); + } finally { + user.removeTpaRequest(request.getName()); + } + } + user.sendMessage(tl("requestAcceptedAll", count)); + } + @Override protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { if (args.length == 1) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 6918ce5d024..b5c10de5109 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -19,42 +19,21 @@ public Commandtpdeny() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final boolean excludeOthers; + final boolean denyAll; if (args.length > 0) { - excludeOthers = args[0].equals("*") || args[0].equalsIgnoreCase("all"); + denyAll = args[0].equals("*") || args[0].equalsIgnoreCase("all"); } else { - excludeOthers = false; + denyAll = false; } - if (!user.hasPendingTpaRequests(false, excludeOthers)) { + if (!user.hasPendingTpaRequests(false, false)) { throw new Exception(tl("noPendingRequest")); } final IUser.TpaRequest denyRequest; if (args.length > 0) { - if (excludeOthers) { - IUser.TpaRequest request; - int count = 0; - while ((request = user.getNextTpaRequest(false, true, true)) != null) { - final User player = ess.getUser(request.getRequesterUuid()); - - final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, player, request, false); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - if (ess.getSettings().isDebug()) { - logger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); - } - continue; - } - - if (player != null && player.getBase().isOnline()) { - player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); - } - - user.removeTpaRequest(request.getName()); - count++; - } - user.sendMessage(tl("requestDeniedAll", count)); + if (denyAll) { + denyAllRequests(user); return; } denyRequest = user.getOutstandingTpaRequest(getPlayer(server, user, args, 0).getName(), false); @@ -62,17 +41,16 @@ public void run(final Server server, final User user, final String commandLabel, denyRequest = user.getNextTpaRequest(false, true, false); } + if (denyRequest == null) { + throw new Exception(tl("noPendingRequest")); + } + final User player = ess.getUser(denyRequest.getRequesterUuid()); if (player == null || !player.getBase().isOnline()) { throw new Exception(tl("noPendingRequest")); } - final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, player, denyRequest, false); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - if (ess.getSettings().isDebug()) { - logger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); - } + if (sendEvent(user, player, denyRequest)) { return; } @@ -81,6 +59,36 @@ public void run(final Server server, final User user, final String commandLabel, user.removeTpaRequest(denyRequest.getName()); } + private void denyAllRequests(User user) { + IUser.TpaRequest request; + int count = 0; + while ((request = user.getNextTpaRequest(false, true, false)) != null) { + final User player = ess.getUser(request.getRequesterUuid()); + + if (sendEvent(user, player, request)) { + continue; + } + + if (player != null && player.getBase().isOnline()) { + player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); + } + + user.removeTpaRequest(request.getName()); + count++; + } + user.sendMessage(tl("requestDeniedAll", count)); + } + + private boolean sendEvent(User user, User player, IUser.TpaRequest request) { + final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, player, request, false); + Bukkit.getPluginManager().callEvent(event); + final boolean cancelled = event.isCancelled(); + if (cancelled && ess.getSettings().isDebug()) { + logger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); + } + return event.isCancelled(); + } + @Override protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { if (args.length == 1) {