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") @Subcommand("deny")
public void deny(@NotNull Player sender, @NotNull Player other) { public void deny(@NotNull Player sender, @NotNull Player other) {
var request = Requests.getRequest(sender, 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())); MESSAGEUTILS.sendLang(sender, "request.no-request", Map.of("%player%", other.getName()));
return; return;
} }
request.decline();
MESSAGEUTILS.sendLang(request.getSender(), "request.deny-sender", Map.of("%player%", request.getReceiver().getName())); 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())); MESSAGEUTILS.sendLang(request.getReceiver(), "request.deny-receiver", Map.of("%player%", request.getSender().getName()));
SoundUtils.playSound(request.getSender(), "deny"); SoundUtils.playSound(request.getSender(), "deny");

View File

@ -6,6 +6,7 @@ public class Request {
private final long time; private final long time;
private final Player sender; private final Player sender;
private final Player receiver; private final Player receiver;
private boolean declined = false;
public Request(Player sender, Player receiver) { public Request(Player sender, Player receiver) {
this.time = System.currentTimeMillis(); this.time = System.currentTimeMillis();
@ -24,4 +25,12 @@ public class Request {
public Player getSender() { public Player getSender() {
return sender; return sender;
} }
public boolean isDeclined() {
return declined;
}
public void decline() {
declined = true;
}
} }

View File

@ -58,16 +58,17 @@ public class Requests {
return; return;
} }
var request = Requests.getRequest(sender, receiver); final Request request = Requests.getRequest(sender, receiver);
if (request != null && !request.getSender().equals(sender)) { if (request != null) {
Trades.addTrade(sender, receiver); if (!request.getSender().equals(sender)) {
requests.remove(request); Trades.addTrade(sender, receiver);
return; requests.remove(request);
} return;
}
if (request != null && System.currentTimeMillis() - request.getTime() < CONFIG.getInt("trade-request-expire-seconds", 60) * 1_000L) { if (request.isDeclined() || System.currentTimeMillis() - request.getTime() < CONFIG.getInt("trade-request-expire-seconds", 60) * 1_000L) {
MESSAGEUTILS.sendLang(sender, "request.already-sent", replacements); MESSAGEUTILS.sendLang(sender, "request.already-sent", replacements);
return; return;
}
} }
final AxTradeRequestEvent apiEvent = new AxTradeRequestEvent(sender, receiver); final AxTradeRequestEvent apiEvent = new AxTradeRequestEvent(sender, receiver);