From fc4892887308aff6f0f6c877c1ba8b481d1144a3 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP Date: Sat, 30 Sep 2023 14:49:44 +0200 Subject: [PATCH] Update to 3.0.3 Signed-off-by: ErdbeerbaerLP --- build.gradle | 7 +- gradle.properties | 4 +- .../forge/DiscordIntegrationMod.java | 118 ++++++++++++------ .../forge/util/ForgeMessageUtils.java | 3 +- update_checker.json | 5 + 5 files changed, 94 insertions(+), 43 deletions(-) diff --git a/build.gradle b/build.gradle index 8b7bcb02..10da080e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,7 @@ buildscript { url = 'https://repo.spongepowered.org/maven' } maven { - url "https://plugins.gradle.org/m2/" - + url "https://plugins.gradle.org/m2/" } } dependencies { @@ -31,7 +30,7 @@ apply plugin: 'org.spongepowered.mixin' //Build variables -version = "3.0.2" +version = "3.0.3" group = "de.erdbeerbaerlp.dcintegration" archivesBaseName = "dcintegration-forge" @@ -95,7 +94,7 @@ configurations.all { //Dependencies dependencies { // ========= Common ===================== - embed('de.erdbeerbaerlp:dcintegration.common:3.0.2') { + embed('de.erdbeerbaerlp:dcintegration.common:3.0.3') { changing = true } diff --git a/gradle.properties b/gradle.properties index c3eb9907..7411262e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,6 +2,6 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -changelog=Large discord integration rewrite adding new features and fixing long existing bugs Old configuration can be used as-is\n\nFixed linking not being saved\nOptimized code\n\nNOTE: This version may contain lots of console spam -releaseType = ALPHA +changelog=Large discord integration rewrite adding new features and fixing long existing bugs\nOld configuration can be used as-is\n\nAdded custom status\nAdded tellraw\nAdded option to disable chat message editing for compatibility reasons\nFixed lots of bugs +releaseType = BETA mcVersion = 1.19.2 \ No newline at end of file diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java index fab9891e..ed8c179c 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dcshadow.dev.vankka.mcdiscordreserializer.discord.DiscordSerializer; import dcshadow.net.kyori.adventure.text.Component; import dcshadow.net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import de.erdbeerbaerlp.dcintegration.common.DiscordIntegration; @@ -117,16 +118,16 @@ public void serverSetup(FMLDedicatedServerSetupEvent ev) { if (DiscordIntegration.INSTANCE.getJDA() != null) { Thread.sleep(2000); //Wait for it to cache the channels CommandRegistry.registerDefaultCommands(); - if (!Localization.instance().serverStarting.isBlank()) - if (DiscordIntegration.INSTANCE.getChannel() != null) { - final MessageCreateData m; - if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed) - m = new MessageCreateBuilder().setEmbeds(Configuration.instance().embedMode.startMessages.toEmbed().setDescription(Localization.instance().serverStarting).build()).build(); - else - m = new MessageCreateBuilder().addContent(Localization.instance().serverStarting).build(); - DiscordIntegration.startingMsg = DiscordIntegration.INSTANCE.sendMessageReturns(m, DiscordIntegration.INSTANCE.getChannel(Configuration.instance().advanced.serverChannelID)); - } - } + if (!Localization.instance().serverStarting.isBlank()) + if (DiscordIntegration.INSTANCE.getChannel() != null) { + final MessageCreateData m; + if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed) + m = new MessageCreateBuilder().setEmbeds(Configuration.instance().embedMode.startMessages.toEmbed().setDescription(Localization.instance().serverStarting).build()).build(); + else + m = new MessageCreateBuilder().addContent(Localization.instance().serverStarting).build(); + DiscordIntegration.startingMsg = DiscordIntegration.INSTANCE.sendMessageReturns(m, DiscordIntegration.INSTANCE.getChannel(Configuration.instance().advanced.serverChannelID)); + } + } } catch (InterruptedException | NullPointerException ignored) { } } @@ -202,22 +203,32 @@ public void advancement(AdvancementEvent.AdvancementEarnEvent ev) { } else { EmbedBuilder b = Configuration.instance().embedMode.advancementMessage.toEmbed(); b = b.setAuthor(ForgeMessageUtils.formatPlayerName(ev.getEntity()), null, avatarURL) - .setDescription(Localization.instance().advancementMessage.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity()))); + .setDescription(Localization.instance().advancementMessage.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%advName%", + ChatFormatting.stripFormatting(ev.getAdvancement() + .getDisplay() + .getTitle() + .getString())) + .replace("%advDesc%", + ChatFormatting.stripFormatting(ev.getAdvancement() + .getDisplay() + .getDescription() + .getString())) + .replace("\\n", "\n")); INSTANCE.sendMessage(new DiscordMessage(b.build())); } } else INSTANCE.sendMessage(Localization.instance().advancementMessage.replace("%player%", - ChatFormatting.stripFormatting(ForgeMessageUtils.formatPlayerName(ev.getEntity()))) - .replace("%name%", - ChatFormatting.stripFormatting(ev.getAdvancement() - .getDisplay() - .getTitle() - .getString())) - .replace("%desc%", - ChatFormatting.stripFormatting(ev.getAdvancement() - .getDisplay() - .getDescription() - .getString())) - .replace("\\n", "\n")); + ChatFormatting.stripFormatting(ForgeMessageUtils.formatPlayerName(ev.getEntity()))) + .replace("%advName%", + ChatFormatting.stripFormatting(ev.getAdvancement() + .getDisplay() + .getTitle() + .getString())) + .replace("%advDesc%", + ChatFormatting.stripFormatting(ev.getAdvancement() + .getDisplay() + .getDescription() + .getString())) + .replace("\\n", "\n")); } } @@ -252,7 +263,7 @@ public void serverStarted(final ServerStartedEvent ev) { } INSTANCE.startThreads(); } - UpdateChecker.runUpdateCheck("https://raw.githubusercontent.com/ErdbeerbaerLP/Discord-Chat-Integration/1.20.1/update_checker.json"); + UpdateChecker.runUpdateCheck("https://raw.githubusercontent.com/ErdbeerbaerLP/Discord-Chat-Integration/1.19.2/update_checker.json"); if (ModList.get().getModContainerById("dynmap").isPresent()) { new DynmapListener().register(); } @@ -291,6 +302,13 @@ public void command(CommandEvent ev) { } INSTANCE.sendMessage(source.getTextName(), sourceEntity != null ? sourceEntity.getUUID().toString() : "0000000", new DiscordMessage(null, msg, !raw), INSTANCE.getChannel(Configuration.instance().advanced.chatOutputChannelID)); } + + if(command.startsWith("tellraw ") && !Configuration.instance().messages.tellrawSelector.isBlank()){ + final String[] args = command.replace("tellraw ", "").replace("dc ", "").split(" "); + if(args[0].equals(Configuration.instance().messages.tellrawSelector)){ + INSTANCE.sendMessage(DiscordSerializer.INSTANCE.serialize(GsonComponentSerializer.gson().deserialize(command.replace("tellraw " + args[0], "")))); + } + } if (command.startsWith("discord ") || command.startsWith("dc ")) { final String[] args = command.replace("discord ", "").replace("dc ", "").split(" "); for (MCSubCommand mcSubCommand : McCommandRegistry.getCommands()) { @@ -448,10 +466,12 @@ public void chat(ServerChatEvent ev) { } } else INSTANCE.sendMessage(ForgeMessageUtils.formatPlayerName(ev.getPlayer()), ev.getPlayer().getUUID().toString(), new DiscordMessage(embed, text, true), channel); - final String json = net.minecraft.network.chat.Component.Serializer.toJson(msg); - Component comp = GsonComponentSerializer.gson().deserialize(json); - final String editedJson = GsonComponentSerializer.gson().serialize(MessageUtils.mentionsToNames(comp, channel.getGuild())); - ev.setMessage(net.minecraft.network.chat.Component.Serializer.fromJson(editedJson)); + if(!Configuration.instance().compatibility.disableParsingMentionsIngame) { + final String json = net.minecraft.network.chat.Component.Serializer.toJson(msg); + Component comp = GsonComponentSerializer.gson().deserialize(json); + final String editedJson = GsonComponentSerializer.gson().serialize(MessageUtils.mentionsToNames(comp, channel.getGuild())); + ev.setMessage(net.minecraft.network.chat.Component.Serializer.fromJson(editedJson)); + } } } @@ -501,13 +521,41 @@ public void death(LivingDeathEvent ev) { public void playerLeave(PlayerEvent.PlayerLoggedOutEvent ev) { if (stopped) return; //Try to fix player leave messages after stop! if (Localization.instance().playerLeave.isBlank()) return; - if (LinkManager.isPlayerLinked(ev.getEntity().getUUID()) && LinkManager.getLink(null, ev.getEntity().getUUID()).settings.hideFromDiscord) - return; - if (INSTANCE != null && !timeouts.contains(ev.getEntity().getUUID())) - INSTANCE.sendMessage(Localization.instance().playerLeave.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity()))); - else if (INSTANCE != null && timeouts.contains(ev.getEntity().getUUID())) { - INSTANCE.sendMessage(Localization.instance().playerTimeout.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity()))); - timeouts.remove(ev.getEntity().getUUID()); + final Player player = ev.getEntity(); + final String avatarURL = Configuration.instance().webhook.playerAvatarURL.replace("%uuid%", player.getUUID().toString()).replace("%uuid_dashless%", player.getUUID().toString().replace("-", "")).replace("%name%", player.getName().getString()).replace("%randomUUID%", UUID.randomUUID().toString()); + if (DiscordIntegration.INSTANCE != null && !DiscordIntegrationMod.timeouts.contains(player.getUUID())) { + if (!Localization.instance().playerLeave.isBlank()) { + if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerLeaveMessages.asEmbed) { + if (!Configuration.instance().embedMode.playerLeaveMessages.customJSON.isBlank()) { + final EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbedJson(Configuration.instance().embedMode.playerLeaveMessages.customJSON + .replace("%uuid%", player.getUUID().toString()) + .replace("%uuid_dashless%", player.getUUID().toString().replace("-", "")) + .replace("%name%", ForgeMessageUtils.formatPlayerName(player)) + .replace("%randomUUID%", UUID.randomUUID().toString()) + .replace("%avatarURL%", avatarURL) + .replace("%playerColor%", "" + TextColors.generateFromUUID(player.getUUID()).getRGB()) + ); + DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build())); + } else { + EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbed(); + b = b.setAuthor(ForgeMessageUtils.formatPlayerName(player), null, avatarURL) + .setDescription(Localization.instance().playerLeave.replace("%player%", ForgeMessageUtils.formatPlayerName(player))); + DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build())); + } + } else + DiscordIntegration.INSTANCE.sendMessage(Localization.instance().playerLeave.replace("%player%", ForgeMessageUtils.formatPlayerName(player))); + } + } else if (DiscordIntegration.INSTANCE != null && DiscordIntegrationMod.timeouts.contains(player.getUUID())) { + if (!Localization.instance().playerTimeout.isBlank()) { + if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerLeaveMessages.asEmbed) { + EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbed(); + b = b.setAuthor(ForgeMessageUtils.formatPlayerName(player), null, avatarURL) + .setDescription(Localization.instance().playerTimeout.replace("%player%", ForgeMessageUtils.formatPlayerName(player))); + DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build())); + } else + DiscordIntegration.INSTANCE.sendMessage(Localization.instance().playerTimeout.replace("%player%", ForgeMessageUtils.formatPlayerName(player))); + } + DiscordIntegrationMod.timeouts.remove(player.getUUID()); } } } diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java index 363c4fcd..30482aba 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java @@ -54,8 +54,7 @@ public static MessageEmbed genItemStackEmbedIfAvailable(final Component componen if (json.has("with")) { final JsonArray args = json.getAsJsonArray("with"); for (JsonElement el : args) { - if (el instanceof JsonObject) { - JsonObject arg1 = (JsonObject) el; + if (el instanceof JsonObject arg1) { if (arg1.has("hoverEvent")) { final JsonObject hoverEvent = arg1.getAsJsonObject("hoverEvent"); if (hoverEvent.has("action") && hoverEvent.get("action").getAsString().equals("show_item") && hoverEvent.has("contents")) { diff --git a/update_checker.json b/update_checker.json index 3779396f..917acd2f 100644 --- a/update_checker.json +++ b/update_checker.json @@ -1,4 +1,9 @@ [ + { + "version": "3.0.3", + "changelog": "Large discord integration rewrite adding new features and fixing long existing bugs\nOld configuration can be used as-is\n\nAdded custom status\nAdded tellraw\nAdded option to disable chat message editing for compatibility reasons\nFixed lots of bugs", + "type": "beta" + }, { "version": "3.0.2", "changelog": "Fixed linking not being saved\nOptimized code",