diff --git a/src/main/java/com/artillexstudios/axtrade/commands/Commands.java b/src/main/java/com/artillexstudios/axtrade/commands/Commands.java index 0f2de40..8840efe 100644 --- a/src/main/java/com/artillexstudios/axtrade/commands/Commands.java +++ b/src/main/java/com/artillexstudios/axtrade/commands/Commands.java @@ -75,11 +75,12 @@ public class Commands implements OrphanCommand { @Subcommand("deny") public void deny(@NotNull Player sender, @NotNull Player other) { var request = Requests.getRequest(sender, other); - if (request == null || request.getSender().equals(sender)) { + if (request == null || request.getSender().equals(sender) || request.isDeclined()) { MESSAGEUTILS.sendLang(sender, "request.no-request", Map.of("%player%", other.getName())); return; } + request.decline(); MESSAGEUTILS.sendLang(request.getSender(), "request.deny-sender", Map.of("%player%", request.getReceiver().getName())); MESSAGEUTILS.sendLang(request.getReceiver(), "request.deny-receiver", Map.of("%player%", request.getSender().getName())); SoundUtils.playSound(request.getSender(), "deny"); diff --git a/src/main/java/com/artillexstudios/axtrade/request/Request.java b/src/main/java/com/artillexstudios/axtrade/request/Request.java index b243aa4..c9edde4 100644 --- a/src/main/java/com/artillexstudios/axtrade/request/Request.java +++ b/src/main/java/com/artillexstudios/axtrade/request/Request.java @@ -6,6 +6,7 @@ public class Request { private final long time; private final Player sender; private final Player receiver; + private boolean declined = false; public Request(Player sender, Player receiver) { this.time = System.currentTimeMillis(); @@ -24,4 +25,12 @@ public class Request { public Player getSender() { return sender; } + + public boolean isDeclined() { + return declined; + } + + public void decline() { + declined = true; + } } diff --git a/src/main/java/com/artillexstudios/axtrade/request/Requests.java b/src/main/java/com/artillexstudios/axtrade/request/Requests.java index 2d8584d..b1f734b 100644 --- a/src/main/java/com/artillexstudios/axtrade/request/Requests.java +++ b/src/main/java/com/artillexstudios/axtrade/request/Requests.java @@ -58,16 +58,17 @@ public class Requests { return; } - var request = Requests.getRequest(sender, receiver); - if (request != null && !request.getSender().equals(sender)) { - Trades.addTrade(sender, receiver); - requests.remove(request); - return; - } - - if (request != null && System.currentTimeMillis() - request.getTime() < CONFIG.getInt("trade-request-expire-seconds", 60) * 1_000L) { - MESSAGEUTILS.sendLang(sender, "request.already-sent", replacements); - return; + final Request request = Requests.getRequest(sender, receiver); + if (request != null) { + if (!request.getSender().equals(sender)) { + Trades.addTrade(sender, receiver); + requests.remove(request); + return; + } + if (request.isDeclined() || System.currentTimeMillis() - request.getTime() < CONFIG.getInt("trade-request-expire-seconds", 60) * 1_000L) { + MESSAGEUTILS.sendLang(sender, "request.already-sent", replacements); + return; + } } final AxTradeRequestEvent apiEvent = new AxTradeRequestEvent(sender, receiver);