package com.alttd.chat.commands; import com.alttd.chat.VelocityChat; 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) { RequiredArgumentBuilder playerNode = RequiredArgumentBuilder .argument("player", StringArgumentType.string()) .suggests((context, builder) -> { Collection 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 command = LiteralArgumentBuilder .literal("mail") .requires(ctx -> ctx.hasPermission("command.proxy.mail")) .then(LiteralArgumentBuilder.literal("send") .then(playerNode .then(RequiredArgumentBuilder .argument("message", StringArgumentType.greedyString()) .executes(context -> { VelocityChat.getPlugin().getChatHandler().sendMail(context.getSource(), context.getArgument("player", String.class), context.getArgument("message", String.class)); return 1; }) ) .executes(context -> { sendHelpMessage(context.getSource()); return 1; }) ) .executes(context -> { sendHelpMessage(context.getSource()); return 1; }) ) .then(LiteralArgumentBuilder.literal("list") .requires(ctx -> ctx.hasPermission("command.proxy.list"))// TODO permission .then(LiteralArgumentBuilder.literal("unread") .executes(context -> { VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), true); return 1; }) ) .then(LiteralArgumentBuilder.literal("all") .executes(context -> { VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), false); return 1; }) ) .then(playerNode .then(LiteralArgumentBuilder.literal("unread") .executes(context -> { VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), true); return 1; }) ) .then(LiteralArgumentBuilder.literal("all") .executes(context -> { VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), false); return 1; }) ) .executes(context -> { sendHelpMessage(context.getSource()); return 1; }) ) ) .then(LiteralArgumentBuilder.literal("admin") .requires(ctx -> ctx.hasPermission("command.proxy.mail.admin"))// TODO permission // TODO admin command, remove, edit? .executes(context -> { sendAdminHelpMessage(context.getSource()); return 1; }) ) .executes(context -> { sendHelpMessage(context.getSource()); return 1; }) .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); } private void sendHelpMessage(CommandSource commandSource) { } private void sendAdminHelpMessage(CommandSource commandSource) { } }