From 0d0ac282d440e320bc7e52255759de098b8d6377 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP Date: Sat, 5 Aug 2023 17:49:05 +0200 Subject: [PATCH] Port 3.0.0 to 1.19 Signed-off-by: ErdbeerbaerLP --- build.gradle | 3 +- gradle.properties | 2 +- .../forge/DiscordIntegrationMod.java | 115 ++++++++---------- .../forge/command/McCommandDiscord.java | 2 +- src/main/resources/META-INF/mods.toml | 6 +- 5 files changed, 56 insertions(+), 72 deletions(-) diff --git a/build.gradle b/build.gradle index d6c6c43d..a1e22912 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,7 @@ configurations { task release{ } + shadowJar { archiveClassifier = "${project.mcVersion}" configurations = [project.configurations.embed] @@ -101,7 +102,7 @@ dependencies { } // ========= Minecraft Forge ============= - minecraft "net.minecraftforge:forge:${project.mcVersion}-47.1.43" + minecraft "net.minecraftforge:forge:${project.mcVersion}-45.1.0" //Mixin annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' diff --git a/gradle.properties b/gradle.properties index 65f812e6..a2e7fc24 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ 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 releaseType = ALPHA -mcVersion = 1.20.1 \ No newline at end of file +mcVersion = 1.19.4 \ 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 8ef16398..f078cc98 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java @@ -116,16 +116,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) { } } @@ -207,18 +207,18 @@ public void advancement(AdvancementEvent.AdvancementEarnEvent ev) { 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("%name%", + ChatFormatting.stripFormatting(ev.getAdvancement() + .getDisplay() + .getTitle() + .getString())) + .replace("%desc%", + ChatFormatting.stripFormatting(ev.getAdvancement() + .getDisplay() + .getDescription() + .getString())) + .replace("\\n", "\n")); } } @@ -304,13 +304,10 @@ public void command(CommandEvent ev) { source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.consoleOnly)); } catch (CommandSyntaxException e) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, null)); - source.sendSuccess(() -> { - try { - return ComponentArgument.textComponent().parse(new StringReader(txt)); - } catch (CommandSyntaxException ignored) { - return null; - } - }, false); + try { + source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false); + } catch (CommandSyntaxException ignored) { + } } break; case PLAYER_ONLY: @@ -319,24 +316,17 @@ public void command(CommandEvent ev) { if (!mcSubCommand.needsOP()) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID())); - source.sendSuccess(() -> { - try { - return ComponentArgument.textComponent().parse(new StringReader(txt)); - } catch (CommandSyntaxException ignored) { - return null; - } - }, false); - + try { + source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false); + } catch (CommandSyntaxException ignored) { + } } else if (source.hasPermission(4)) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID())); - source.sendSuccess(() -> { - try { - return ComponentArgument.textComponent().parse(new StringReader(txt)); - } catch (CommandSyntaxException ignored) { - return null; - } - }, false); + try { + source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false); + } catch (CommandSyntaxException ignored) { + } } else { source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.noPermission)); } @@ -351,38 +341,30 @@ public void command(CommandEvent ev) { final ServerPlayer player = source.getPlayerOrException(); if (!mcSubCommand.needsOP()) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID())); - source.sendSuccess(() -> { - try { - return ComponentArgument.textComponent().parse(new StringReader(txt)); - } catch (CommandSyntaxException ignored) { - return null; - } - }, false); + try { + source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false); + } catch (CommandSyntaxException ignored) { + } } else if (source.hasPermission(4)) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID())); - source.sendSuccess(() -> { - try { - return ComponentArgument.textComponent().parse(new StringReader(txt)); - } catch (CommandSyntaxException ignored) { - return null; - } - }, false); + + try { + source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false); + } catch (CommandSyntaxException ignored) { + } } else { source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.noPermission)); } } catch (CommandSyntaxException e) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, null)); - source.sendSuccess(() -> { - try { - return ComponentArgument.textComponent().parse(new StringReader(txt)); - } catch (CommandSyntaxException ignored) { - return null; - } - }, false); + try { + source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false); + } catch (CommandSyntaxException ignored) { + } } break; } @@ -520,7 +502,8 @@ 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 (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())) { diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java index fe0a0a97..9a93c9e2 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java @@ -14,7 +14,7 @@ public class McCommandDiscord { public McCommandDiscord(CommandDispatcher dispatcher) { final LiteralArgumentBuilder l = Commands.literal("discord"); if (Configuration.instance().ingameCommand.enabled) l.executes((ctx) -> { - ctx.getSource().sendSuccess(()->ComponentUtils.mergeStyles(Component.literal(Configuration.instance().ingameCommand.message), + ctx.getSource().sendSuccess(ComponentUtils.mergeStyles(Component.literal(Configuration.instance().ingameCommand.message), Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(Configuration.instance().ingameCommand.hoverMessage))) .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Configuration.instance().ingameCommand.inviteURL))), false); return 0; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index ea42f1ad..00db7f24 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 = "[40,)" #mandatory +loaderVersion = "[41,)" #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 @@ -23,12 +23,12 @@ This mod links your server chat with a channel on your discord server. [[dependencies.dcintegration]] modId = "minecraft" mandatory = true -versionRange = "[1.20,]" +versionRange = "[1.19,]" ordering = "NONE" side = "SERVER" [[dependencies.dcintegration]] modId = "forge" mandatory = true -versionRange = "[47.0.0,)" +versionRange = "[41.1.0,)" ordering = "NONE" side = "BOTH" \ No newline at end of file