Chat/velocity/src/main/java/com/alttd/velocitychat/commands/SendMail.java

133 lines
6.4 KiB
Java
Raw Normal View History

2021-12-11 18:35:35 +00:00
package com.alttd.velocitychat.commands;
2021-05-15 22:28:47 +00:00
2021-12-11 18:35:35 +00:00
import com.alttd.velocitychat.VelocityChat;
2021-05-15 22:28:47 +00:00
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import java.util.ArrayList;
import java.util.Collection;
public class SendMail {
public SendMail(ProxyServer proxyServer) {
2021-05-24 07:53:45 +00:00
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
.<CommandSource, String>argument("player", 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;
});
2021-05-15 22:28:47 +00:00
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("mail")
.requires(ctx -> ctx.hasPermission("command.chat.mail"))
2021-05-15 22:28:47 +00:00
.then(LiteralArgumentBuilder.<CommandSource>literal("send")
2021-05-24 07:53:45 +00:00
.then(playerNode
2021-05-15 22:28:47 +00:00
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
2021-05-24 07:53:45 +00:00
VelocityChat.getPlugin().getChatHandler().sendMail(context.getSource(), context.getArgument("player", String.class), context.getArgument("message", String.class));
2021-05-15 22:28:47 +00:00
return 1;
})
)
2021-05-22 18:34:32 +00:00
.executes(context -> {
2021-05-24 07:53:45 +00:00
sendHelpMessage(context.getSource());
2021-05-22 18:34:32 +00:00
return 1;
})
)
2021-05-24 07:53:45 +00:00
.executes(context -> {
sendHelpMessage(context.getSource());
return 1;
})
2021-05-22 18:34:32 +00:00
)
.then(LiteralArgumentBuilder.<CommandSource>literal("list")
.requires(ctx -> ctx.hasPermission("command.chat.mail.list"))// TODO permission
2021-05-24 07:53:45 +00:00
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
2021-05-22 18:34:32 +00:00
.executes(context -> {
2021-05-24 07:53:45 +00:00
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), true);
2021-05-22 18:34:32 +00:00
return 1;
})
2021-05-15 22:28:47 +00:00
)
2021-05-24 07:53:45 +00:00
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
2021-05-22 18:34:32 +00:00
.executes(context -> {
2021-05-24 07:53:45 +00:00
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), false);
2021-05-22 18:34:32 +00:00
return 1;
})
)
2021-05-24 07:53:45 +00:00
.then(playerNode
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), true);
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), false);
return 1;
})
)
2021-05-22 18:34:32 +00:00
.executes(context -> {
2021-05-24 07:53:45 +00:00
sendHelpMessage(context.getSource());
2021-05-22 18:34:32 +00:00
return 1;
})
)
)
.then(LiteralArgumentBuilder.<CommandSource>literal("admin")
.requires(ctx -> ctx.hasPermission("command.chat.mail.admin"))// TODO permission
2021-05-22 18:34:32 +00:00
// TODO admin command, remove, edit?
.executes(context -> {
2021-05-24 07:53:45 +00:00
sendAdminHelpMessage(context.getSource());
2021-05-22 18:34:32 +00:00
return 1;
})
2021-05-15 22:28:47 +00:00
)
2021-05-22 18:34:32 +00:00
.executes(context -> {
2021-05-24 07:53:45 +00:00
sendHelpMessage(context.getSource());
2021-05-22 18:34:32 +00:00
return 1;
})
2021-05-15 22:28:47 +00:00
.build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
/*for (String alias : Config.MAILCOMMANDALIASES) {
metaBuilder.aliases(alias);
}*/
CommandMeta meta = metaBuilder.build();
proxyServer.getCommandManager().register(meta, brigadierCommand);
}
2021-05-24 07:53:45 +00:00
private void sendHelpMessage(CommandSource commandSource) {
}
private void sendAdminHelpMessage(CommandSource commandSource) {
}
2021-05-15 22:28:47 +00:00
}