Fixed /trade deny

This commit is contained in:
BenceX100 2024-07-31 20:20:48 +02:00
parent 1989a20548
commit fda0c823ee
3 changed files with 22 additions and 11 deletions

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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);