From 9042b7c671c8c3c33202a5ae6cfcf4860e707cba Mon Sep 17 00:00:00 2001 From: DinnerBeef Date: Sun, 9 Jul 2023 14:10:37 -0500 Subject: [PATCH] Updated Mod To 1.20.1 (#12) - Moved version numbers to gradle.properties - Changed DiscriminatedName to Name as discord no longer has numbers - Fixed AdvancementEvent to AdvancementEarnEvent - Fixed the Name for AdvancementEarnEvent - Added message to config to make sure 'Message Content Intent' is enabled for the bot Co-authored-by: DinnerBeef --- build.gradle | 12 ++++++--- gradle.properties | 9 ++++++- .../org/jedi/DiscordMessageFormatter.java | 4 +-- .../jedi/JustEnoughDiscordIntegrationMod.java | 27 +++++++++---------- src/main/resources/META-INF/mods.toml | 2 +- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 1f00267..0783314 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ minecraft { // // Use non-default mappings at your own risk. They may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: 'official', version: '1.19' + mappings channel: 'official', version: minecraft_version // Default run configurations. // These can be tweaked, removed, or duplicated as needed. @@ -118,7 +118,11 @@ configurations { } minecraft.runs.all { lazyToken('minecraft_classpath') { - configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator) + configurations.library.copyRecursive().resolve() + .collect { it.absolutePath } + .findAll { !it.contains("org.jetbrains\\annotations\\13.0") } + .findAll { !it.contains("org.jetbrains\\annotations\\23.0") } + .join(File.pathSeparator) } } @@ -130,9 +134,9 @@ repositories { } dependencies { - minecraft 'net.minecraftforge:forge:1.19-41.0.98' + minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - library('org.javacord:javacord:3.6.0') + library("org.javacord:javacord:${javacord_version}") library('org.apache.logging.log4j:log4j-api:2.17.2') } diff --git a/gradle.properties b/gradle.properties index 878bf1f..32c957a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,11 @@ # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false \ No newline at end of file +org.gradle.daemon=false + +minecraft_version=1.20.1 +forge_version=47.1.0 + +javacord_version=3.8.0 + +mod_version=1.0.0 \ No newline at end of file diff --git a/src/main/java/org/jedi/DiscordMessageFormatter.java b/src/main/java/org/jedi/DiscordMessageFormatter.java index c8af314..37fb049 100644 --- a/src/main/java/org/jedi/DiscordMessageFormatter.java +++ b/src/main/java/org/jedi/DiscordMessageFormatter.java @@ -49,12 +49,12 @@ public Component format(Message message) { private Component formatAuthorName(Message message) { final TextColor color = this.getAuthorColor(message); - final MutableComponent discriminatedName = Component.literal(message.getAuthor().getDiscriminatedName()); + final MutableComponent name = Component.literal(message.getAuthor().getName()); return Component.literal(message.getAuthor().getDisplayName()) .withStyle(Style.EMPTY .withColor(color) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, discriminatedName)) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, name)) ); } diff --git a/src/main/java/org/jedi/JustEnoughDiscordIntegrationMod.java b/src/main/java/org/jedi/JustEnoughDiscordIntegrationMod.java index 7701fa8..a083232 100644 --- a/src/main/java/org/jedi/JustEnoughDiscordIntegrationMod.java +++ b/src/main/java/org/jedi/JustEnoughDiscordIntegrationMod.java @@ -2,9 +2,7 @@ import com.google.common.collect.Maps; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.advancements.Advancement; -import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -12,7 +10,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; -import net.minecraftforge.event.entity.player.AdvancementEvent; +import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.event.server.ServerStoppedEvent; @@ -31,6 +29,7 @@ import org.apache.logging.log4j.Logger; import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApiBuilder; +import org.javacord.api.entity.intent.Intent; import org.javacord.api.entity.message.Message; import org.javacord.api.entity.message.WebhookMessageBuilder; import org.javacord.api.entity.message.mention.AllowedMentions; @@ -93,16 +92,14 @@ public JustEnoughDiscordIntegrationMod() { ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG); MinecraftForge.EVENT_BUS.register(this); - ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> { - return new IExtensionPoint.DisplayTest( - () -> IGNORESERVERONLY, - (a, b) -> true - ); - }); + ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest( + () -> IGNORESERVERONLY, + (a, b) -> true + )); } private static void setupConfig(ForgeConfigSpec.Builder builder) { - builder.comment(" Create a bot here: https://discord.com/developers/applications"); + builder.comment(" Create a bot here: https://discord.com/developers/applications \"Make sure 'Message Content Intent' is enabled\""); builder.push("Discord Values"); botTokenEntry = builder.comment(" The bot-specific token for your Discord bot") @@ -154,6 +151,7 @@ public void onServerStarting(ServerStartingEvent event) { final String token = botTokenEntry.get(); if (token.length() > 0) { discordBuilder.setToken(token); + discordBuilder.addIntents(Intent.MESSAGE_CONTENT); discordBuilder.login().thenAccept(dcObject -> { discord = Optional.of(dcObject); loadWebhooks(); @@ -195,12 +193,12 @@ public void playerLeave(PlayerEvent.PlayerLoggedOutEvent event) { @SubscribeEvent public void playerJoin(PlayerEvent.PlayerLoggedInEvent event) { - CACHE_BUSTS.put(event.getEntity().getUUID(), "" + System.currentTimeMillis()); + CACHE_BUSTS.put(event.getEntity().getUUID(), String.valueOf(System.currentTimeMillis())); sendMessage(String.format(joinedGameEntry.get(), getPlayerName(event))); } @SubscribeEvent - public void playerLeave(AdvancementEvent event) { + public void onAdvancementEarn(AdvancementEarnEvent event) { final Advancement advancement = event.getAdvancement(); if (advancement.getDisplay() == null) { return; @@ -208,7 +206,6 @@ public void playerLeave(AdvancementEvent event) { final String playerName = strip(event.getEntity().getDisplayName().getString()); final String advancementName = strip(advancement.getDisplay().getTitle().getString()); final String advancementDesc = strip(advancement.getDisplay().getDescription().getString()); - sendMessage(String.format(advancementEntry.get(), playerName, advancementName, advancementDesc)); } @@ -216,7 +213,7 @@ public void playerLeave(AdvancementEvent event) { public void onServerChatEvent(ServerChatEvent event) { try { final String username = event.getUsername(); - final String message = event.getMessage(); + final String message = event.getMessage().getString(); final String uuid = event.getPlayer().getStringUUID(); final String cacheBust = CACHE_BUSTS.getOrDefault(event.getPlayer().getUUID(), username); @@ -239,7 +236,7 @@ public void onMessageCreate(MessageCreateEvent event) { if (!readChannels.get().contains(event.getChannel().getId())) return; Component chatMessage = messageFormatter.format(message); - ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastSystemMessage(chatMessage, ChatType.SYSTEM); + ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastSystemMessage(chatMessage, false); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index a8b3be5..6f6e559 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[41,)" +loaderVersion="[47,)" license="MPLv2" issueTrackerURL="https://github.com/Cojomax99/JustEnoughDiscordIntegration/issues"