Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Commit 40e8813

Browse files
committed
feat(tpa): when using tpa without specifying target, it will take the most recent one
1 parent f0f9805 commit 40e8813

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: plugin/src/main/java/team/devblook/pepitocore/plugin/module/tpa/TPARequestManager.java

+19
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import com.google.inject.Singleton;
66
import net.kyori.adventure.text.Component;
77
import net.kyori.adventure.text.format.TextColor;
8+
import org.bukkit.Bukkit;
89
import org.bukkit.entity.Player;
910
import team.devblook.pepitocore.plugin.module.tpa.model.TPARequest;
1011

1112
import java.util.Collection;
13+
import java.util.Comparator;
1214
import java.util.UUID;
1315

1416
@Singleton
@@ -37,6 +39,23 @@ public void send(Player from, Player to) {
3739
);
3840
}
3941

42+
public void accept(Player receiver) {
43+
TPARequest last = requests.get(receiver.getUniqueId())
44+
.stream()
45+
.min(Comparator.comparingLong(TPARequest::elapsed))
46+
.orElse(null);
47+
48+
if (last == null) {
49+
receiver.sendMessage("No se ha encontrado ninguna solicitud de TPA pendiente.");
50+
return;
51+
}
52+
53+
accept(
54+
receiver,
55+
Bukkit.getPlayer(last.from())
56+
);
57+
}
58+
4059
public void accept(Player receiver, Player from) {
4160
TPARequest request = new TPARequest(from, receiver);
4261

Diff for: plugin/src/main/java/team/devblook/pepitocore/plugin/module/tpa/command/TPACommand.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.fixeddev.commandflow.annotated.CommandClass;
55
import me.fixeddev.commandflow.annotated.annotation.ArgOrSub;
66
import me.fixeddev.commandflow.annotated.annotation.Command;
7+
import me.fixeddev.commandflow.annotated.annotation.OptArg;
78
import me.fixeddev.commandflow.bukkit.annotation.Sender;
89
import net.kyori.adventure.text.Component;
910
import net.kyori.adventure.text.format.TextColor;
@@ -56,17 +57,24 @@ public void cancel(@Sender Player player, OfflinePlayer target) {
5657
}
5758

5859
@Command(names = "accept")
59-
public void accept(@Sender Player player, OfflinePlayer target) {
60+
public void accept(@Sender Player player, @OptArg OfflinePlayer target) {
61+
if (target == null) {
62+
requestManager.accept(player);
63+
return;
64+
}
65+
6066
if (self(player, target)) {
6167
player.sendMessage(
6268
Component.text("Emm, ¿Si no puedes solicitarte un TPA, por qué crees que esto es lógico?", TextColor.fromHexString("#E7783C"))
6369
);
6470
return;
6571
}
72+
6673
Player from = online(target);
6774
if (from == null) {
6875
player.sendMessage(Component.text("El jugador" + target.getName() + " no está conectado.", TextColor.fromHexString("#E7783C")));
6976
return;
77+
7078
}
7179

7280
requestManager.accept(player, from);

0 commit comments

Comments
 (0)