Merge branch 4.9

This commit is contained in:
destro174
2022-03-14 16:48:35 +01:00
21 changed files with 258 additions and 177 deletions
@@ -93,7 +93,7 @@ public class PartyCommand implements SimpleCommand {
List<String> finalValues = new ArrayList<>();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
if (str.toLowerCase().startsWith(remaining.toLowerCase())) {
finalValues.add(StringArgumentType.escapeIfRequired(str));
}
}
@@ -2,11 +2,15 @@ package com.alttd.velocitychat.commands;
import com.alttd.chat.config.Config;
import com.alttd.chat.util.Utility;
import com.alttd.velocitychat.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.alttd.proxydiscordlink.DiscordLink;
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta;
@@ -16,8 +20,12 @@ import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.ArrayList;
import java.util.Collection;
import java.awt.*;
import java.util.Optional;
public class Report {
@@ -26,40 +34,43 @@ public class Report {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("report")
.requires(ctx -> ctx.hasPermission("command.chat.report"))
.then(RequiredArgumentBuilder.<CommandSource, String>argument("username", StringArgumentType.string())
.suggests((context, builder) -> {
Collection<String> possibleValues = new ArrayList<>();
for (Player player : proxyServer.getAllPlayers()) {
possibleValues.add(player.getGameProfile().getName());
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("report", StringArgumentType.greedyString())
.executes(context -> {
if (!(context.getSource() instanceof Player player)) {
context.getSource().sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
return 1;
}
if(possibleValues.isEmpty()) return Suggestions.empty();
String remaining = builder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(StringArgumentType.escapeIfRequired(str));
}
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
if (optionalServerConnection.isEmpty()) {
return 1;
}
return builder.buildFuture();
ServerConnection serverConnection = optionalServerConnection.get();
String serverName = serverConnection.getServer().getServerInfo().getName();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(player.getUsername(), null, "https://crafatar.com/avatars/" + player.getUniqueId() + "?overlay");
embedBuilder.setTitle("Player Report");
embedBuilder.setColor(Color.CYAN);
embedBuilder.addField("Incident",
context.getArgument("report", String.class),
false);
embedBuilder.addField("Server",
serverName.substring(0, 1).toUpperCase() + serverName.substring(1),
false);
Long id = Config.serverChannelId.get(serverName.toLowerCase());
if (id <= 0)
id = Config.serverChannelId.get("general");
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(id, embedBuilder, -1);
player.sendMessage(Utility.parseMiniMessage(Config.REPORT_SENT));
return 1;
})
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("report", StringArgumentType.greedyString())
.executes(context -> {
if (!(context.getSource() instanceof Player player)) {
context.getSource().sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
return 1;
}
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
if (optionalServerConnection.isEmpty()) {
return 1;
}
ServerConnection serverConnection = optionalServerConnection.get();
String serverName = serverConnection.getServer().getServerInfo().getName();
//TODO send message to channel with that server name
return 1;
})
)
)
.executes(context -> 0)
.executes(context -> {
context.getSource().sendMessage(Utility.parseMiniMessage(Config.HELP_REPORT));
return 0;
})
.build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
@@ -59,6 +59,11 @@ public class Invite implements SubCommand {
Placeholder.unparsed("party", party.getPartyName()),
Placeholder.unparsed("party_password", party.getPartyPassword())
));
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
Placeholder.unparsed("player", target.getUsername()),
Placeholder.unparsed("party", party.getPartyName()),
Placeholder.unparsed("party_password", party.getPartyPassword())
));
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
Placeholder.unparsed("player", target.getUsername())
));
@@ -45,12 +45,17 @@ public class Join implements SubCommand {
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
if (chatUser.getPartyId() == party.getPartyId()) {
source.sendMessage(Utility.parseMiniMessage(Config.ALREADY_IN_THIS_PARTY, Placeholder.parsed("party", party.getPartyName())));
return;
}
party.addUser(chatUser, player.getUsername());
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.unparsed("party_name", party.getPartyName())));
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.parsed("party_name", party.getPartyName())));
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
Placeholder.component("player_name", chatUser.getDisplayName()),
Placeholder.unparsed("party_name", party.getPartyName())
Placeholder.parsed("party_name", party.getPartyName())
), null);
}