From 36d8e67e12ebae6a0b77c91734b4a63d00b22eef Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP Date: Sun, 13 Aug 2023 14:47:24 +0200 Subject: [PATCH 1/2] Downgrade for 1.19.2 Signed-off-by: ErdbeerbaerLP --- build.gradle | 2 +- gradle.properties | 4 ++-- .../dcintegration/forge/command/DCCommandSender.java | 6 +++--- src/main/resources/META-INF/mods.toml | 4 ++-- update_checker.json | 6 +++++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 8e67b865..8b7bcb02 100644 --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,7 @@ dependencies { } // ========= Minecraft Forge ============= - minecraft "net.minecraftforge:forge:${project.mcVersion}-45.1.0" + minecraft "net.minecraftforge:forge:${project.mcVersion}-43.2.21" //Mixin annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' diff --git a/gradle.properties b/gradle.properties index a2e7fc24..c3eb9907 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\nOld configuration can be used as-is +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 -mcVersion = 1.19.4 \ No newline at end of file +mcVersion = 1.19.2 \ No newline at end of file diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java index f951ef72..74bccf6b 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java @@ -8,7 +8,7 @@ import net.dv8tion.jda.api.interactions.InteractionHook; import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.OutgoingChatMessage; +import net.minecraft.network.protocol.game.ServerboundChatPacket; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.server.ServerLifecycleHooks; @@ -61,8 +61,8 @@ public void sendSystemMessage(Component p_240560_, boolean p_240545_) { } @Override - public void sendChatMessage(OutgoingChatMessage p_249852_, boolean p_250110_, ChatType.Bound p_252108_) { - message.append(textComponentToDiscordMessage(p_249852_.content())).append("\n"); + public void displayClientMessage(Component chatComponent, boolean actionBar) { + message.append(textComponentToDiscordMessage(chatComponent)).append("\n"); if (cmdMessage == null) cmdMsg.thenAccept((msg) -> { cmdMessage = msg.editOriginal(message.toString().trim()).submit(); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 00db7f24..ee19bb0b 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,6 +1,6 @@ modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion = "[41,)" #mandatory +loaderVersion = "[43,)" #mandatory license = "MIT License" # A URL to refer people to when problems occur with this mod issueTrackerURL = "https://github.com/ErdbeerbaerLP/Discord-Chat-Integration/issues" #optional @@ -29,6 +29,6 @@ side = "SERVER" [[dependencies.dcintegration]] modId = "forge" mandatory = true -versionRange = "[41.1.0,)" +versionRange = "[43.2.0,)" ordering = "NONE" side = "BOTH" \ No newline at end of file diff --git a/update_checker.json b/update_checker.json index e42e8cb7..3779396f 100644 --- a/update_checker.json +++ b/update_checker.json @@ -1,7 +1,11 @@ [ { + "version": "3.0.2", + "changelog": "Fixed linking not being saved\nOptimized code", + "type": "alpha" + },{ "version": "3.0.0", - "changelog": "Added new event handling methods for addons\nOtherwise mostly a bug fix update\nDon't forget to use 'discord migrate' in console when updating from below 2.6.0", + "changelog": "Large discord integration rewrite adding new features and fixing long existing bugs Old configuration can be used as-is", "type": "alpha" },{ "version": "2.6.4", From fc4892887308aff6f0f6c877c1ba8b481d1144a3 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP Date: Sat, 30 Sep 2023 14:49:44 +0200 Subject: [PATCH 2/2] 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",