Added optional sender argument to /mail list <username>

This commit is contained in:
Stijn 2022-09-21 18:26:16 +02:00
parent 6e41a81ed1
commit d3be713c9a
2 changed files with 43 additions and 3 deletions

View File

@ -41,6 +41,27 @@ public class MailCommand {
return 1;
});
RequiredArgumentBuilder<CommandSource, String> playerNodeSender = RequiredArgumentBuilder
.<CommandSource, String>argument("sender", StringArgumentType.string())
.suggests((context, builder) -> {
Collection<String> possibleValues = new ArrayList<>();
for (Player player : proxyServer.getAllPlayers()) {
possibleValues.add(player.getGameProfile().getName());
}
if(possibleValues.isEmpty()) return Suggestions.empty();
String remaining = builder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
}
}
return builder.buildFuture();
})
.executes(context -> {
sendHelpMessage(context.getSource());
return 1;
});
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("mail")
.requires(ctx -> ctx.hasPermission("command.chat.mail"))
@ -79,8 +100,13 @@ public class MailCommand {
)
.then(playerNode
.requires(ctx -> ctx.hasPermission("command.chat.mail.list.other"))// TODO permission
.then(playerNodeSender
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), context.getArgument("sender", String.class));
return 1;
}))
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class));
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), null);
return 1;
})
)

View File

@ -213,14 +213,28 @@ public class ChatHandler {
commandSource.sendMessage(Utility.parseMiniMessage("<yellow>Sent mail to " + senderName + "!"));
}
public void readMail(CommandSource commandSource, String targetPlayer) {
public void readMail(CommandSource commandSource, String targetPlayer, String senderPlayer) {
UUID uuid = ServerHandler.getPlayerUUID(targetPlayer);
if (uuid == null) {
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailNoUser));
return;
}
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
commandSource.sendMessage(parseMails(chatUser.getMails(), false));
if (senderPlayer == null) {
commandSource.sendMessage(parseMails(chatUser.getMails(), false));
}
UUID sender = ServerHandler.getPlayerUUID(senderPlayer);
if (sender == null) {
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailNoUser));
return;
}
List<Mail> mails = chatUser.getMails().stream()
.filter(mail -> mail.getSender().equals(sender))
.toList();
commandSource.sendMessage(parseMails(mails, false));
}
public void readMail(CommandSource commandSource, boolean unread) {