From 56010fb9ad7a3e3f28b19f7d7a9d8a2e76a50587 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sun, 20 Feb 2022 18:19:52 +0100 Subject: [PATCH] Added /report probably (and fixed party chat tab complete) --- .../java/com/alttd/chat/config/Config.java | 15 +++++++++++++ velocity/build.gradle.kts | 1 + .../com/alttd/velocitychat/VelocityChat.java | 8 +++---- .../velocitychat/commands/PartyCommand.java | 2 +- .../alttd/velocitychat/commands/Report.java | 22 ++++++++++++++++++- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/com/alttd/chat/config/Config.java b/api/src/main/java/com/alttd/chat/config/Config.java index ad9914b..370c810 100755 --- a/api/src/main/java/com/alttd/chat/config/Config.java +++ b/api/src/main/java/com/alttd/chat/config/Config.java @@ -410,4 +410,19 @@ public final class Config { mailSent = getString("settings.mail.mail-sent", mailSent); } + public static HashMap serverChannelId = new HashMap<>(); + private static void loadChannelIds() { + serverChannelId.clear(); + serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1)); + ConfigurationNode node = config.node("discord-channel-id"); + Map objectMap = node.childrenMap(); + for (Object o : objectMap.keySet()) { + String key = (String) o; + if (key.equalsIgnoreCase("general")) + continue; + ConfigurationNode configurationNode = objectMap.get(o); + long channelId = configurationNode.getLong(); + serverChannelId.put(key.toLowerCase(), channelId); + } + } } diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts index b8c4c63..b289183 100644 --- a/velocity/build.gradle.kts +++ b/velocity/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { // compileOnly("com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT") implementation("mysql:mysql-connector-java:8.0.27") // mysql implementation("org.spongepowered", "configurate-yaml", "4.1.2") + implementation("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT") implementation("net.kyori", "adventure-text-minimessage", "4.10.0-SNAPSHOT") { exclude("net.kyori") exclude("net.kyori.examination") diff --git a/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java b/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java index 7ff9cce..843c4dc 100755 --- a/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java +++ b/velocity/src/main/java/com/alttd/velocitychat/VelocityChat.java @@ -5,10 +5,7 @@ import com.alttd.chat.ChatImplementation; import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.PartyManager; import com.alttd.chat.objects.ChatUser; -import com.alttd.velocitychat.commands.GlobalAdminChat; -import com.alttd.velocitychat.commands.MailCommand; -import com.alttd.velocitychat.commands.PartyCommand; -import com.alttd.velocitychat.commands.Reload; +import com.alttd.velocitychat.commands.*; import com.alttd.chat.config.Config; import com.alttd.chat.database.DatabaseConnection; import com.alttd.velocitychat.handlers.ChatHandler; @@ -37,7 +34,7 @@ import java.nio.file.Path; @Plugin(id = "chatplugin", name = "ChatPlugin", version = "1.0.0", description = "A chat plugin for Altitude Minecraft Server", authors = {"destro174", "teri"}, - dependencies = {@Dependency(id = "luckperms"), @Dependency(id = "litebans")} + dependencies = {@Dependency(id = "luckperms"), @Dependency(id = "litebans"), @Dependency(id = "proxydiscordlink")} ) public class VelocityChat { @@ -114,6 +111,7 @@ public class VelocityChat { new GlobalAdminChat(server); new Reload(server); new MailCommand(server); + new Report(server); server.getCommandManager().register("party", new PartyCommand()); // all (proxy)commands go here } diff --git a/velocity/src/main/java/com/alttd/velocitychat/commands/PartyCommand.java b/velocity/src/main/java/com/alttd/velocitychat/commands/PartyCommand.java index 74f6462..361081f 100644 --- a/velocity/src/main/java/com/alttd/velocitychat/commands/PartyCommand.java +++ b/velocity/src/main/java/com/alttd/velocitychat/commands/PartyCommand.java @@ -93,7 +93,7 @@ public class PartyCommand implements SimpleCommand { List finalValues = new ArrayList<>(); for (String str : possibleValues) { - if (str.toLowerCase().startsWith(remaining)) { + if (str.toLowerCase().startsWith(remaining.toLowerCase())) { finalValues.add(StringArgumentType.escapeIfRequired(str)); } } diff --git a/velocity/src/main/java/com/alttd/velocitychat/commands/Report.java b/velocity/src/main/java/com/alttd/velocitychat/commands/Report.java index 408bdde..23bd78e 100644 --- a/velocity/src/main/java/com/alttd/velocitychat/commands/Report.java +++ b/velocity/src/main/java/com/alttd/velocitychat/commands/Report.java @@ -1,6 +1,9 @@ package com.alttd.velocitychat.commands; import com.alttd.chat.config.Config; +import com.alttd.chat.util.Utility; +import com.alttd.proxydiscordlink.DiscordLink; +import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder; import com.alttd.velocitychat.VelocityChat; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; @@ -15,6 +18,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ServerConnection; import net.kyori.adventure.text.minimessage.MiniMessage; +import java.awt.*; import java.util.ArrayList; import java.util.Collection; import java.util.Optional; @@ -55,7 +59,23 @@ public class Report { } ServerConnection serverConnection = optionalServerConnection.get(); String serverName = serverConnection.getServer().getServerInfo().getName(); - //TODO send message to channel with that server name + + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setAuthor(player.getUsername(), + "https://crafatar.com/avatars/" + player.getUniqueId() + "?overlay"); + embedBuilder.setTitle("Player Report"); + embedBuilder.setColor(Color.BLUE); + 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); return 1; }) )