From 023d5d41d5778f86f5a268ac519ac386148e5cea Mon Sep 17 00:00:00 2001 From: Vankka Date: Sat, 20 Jul 2024 18:52:12 +0300 Subject: [PATCH] Change mentioning to usernames, add insert to mention to default Discord to Minecraft configuration --- .../main/channels/DiscordToMinecraftChatConfig.java | 2 +- .../game/minecrafttodiscord/MentionCachingModule.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java b/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java index f869bbda..9ddabc30 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java @@ -35,7 +35,7 @@ public class DiscordToMinecraftChatConfig { public boolean enabled = true; @Comment("The Discord to Minecraft message format for regular users and bots") - public String format = "[[color:#5865F2]Discord[color]] [hover:show_text:Username: @%user_tag%\nRoles: %user_roles:', '|text:'[color:gray][italics:on]None[color][italics]'%]%user_color%%user_effective_server_name%[color][hover]%message_reply% » %message%%message_attachments%"; + public String format = "[[color:#5865F2]Discord[color]] [hover:show_text:Username: @%user_tag% [italics:on](Shift+Click to mention)[italics:off]\nRoles: %user_roles:', '|text:'[color:gray][italics:on]None[color][italics]'%][insert:@%user_tag%]%user_color%%user_effective_server_name%[color][hover]%message_reply% » %message%%message_attachments%"; @Comment("The Discord to Minecraft message format for webhook messages (if enabled)") public String webhookFormat = "[[color:#5865F2]Discord[color]] [hover:show_text:Bot message]%user_effective_name%[hover] » %message%%message_attachments%"; diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/minecrafttodiscord/MentionCachingModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/minecrafttodiscord/MentionCachingModule.java index 587a6d02..c20705f4 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/minecrafttodiscord/MentionCachingModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/minecrafttodiscord/MentionCachingModule.java @@ -28,6 +28,7 @@ import com.github.benmanes.caffeine.cache.Cache; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.channel.concrete.Category; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; @@ -149,7 +150,7 @@ public class MentionCachingModule extends AbstractModule { private CachedMention convertMember(Member member) { return new CachedMention( - "@" + member.getEffectiveName(), + "@" + member.getUser().getName(), member.getAsMention(), member.getIdLong() ); @@ -230,6 +231,11 @@ public class MentionCachingModule extends AbstractModule { return channelMentions.computeIfAbsent(guild.getIdLong(), key -> { Map mentions = new LinkedHashMap<>(); for (GuildChannel channel : guild.getChannels()) { + if (channel instanceof Category) { + // Not mentionable + continue; + } + mentions.put(channel.getIdLong(), convertChannel(channel)); } return mentions;