Skip to content

Commit

Permalink
Prepare works for Discord's new "global_name" field
Browse files Browse the repository at this point in the history
* Javacord needs to update before I can add support for global names, but there is a working 1.20 SNAPSHOT which contains updated information regarding it and fixes a few bugs.
  • Loading branch information
FireController1847 committed Jun 26, 2023
1 parent 04317d3 commit 5035bd3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DiscordManager(TrueDiscordLink discordlink) {
if (discordlink.getConfig().getBoolean("bot.enabled")) {
new DiscordApiBuilder()
.setToken(discordlink.getConfig().getString("bot.token"))
.setIntents(Intent.GUILDS, Intent.GUILD_MESSAGES, Intent.GUILD_MEMBERS, Intent.DIRECT_MESSAGES)
.setIntents(Intent.GUILDS, Intent.GUILD_MESSAGES, Intent.GUILD_MEMBERS, Intent.DIRECT_MESSAGES, Intent.MESSAGE_CONTENT)
.login().thenAcceptAsync(api -> {
this.api = api;

Expand Down Expand Up @@ -335,7 +335,7 @@ private void sendDiscordBotMessage(String content, boolean blocking, Player play
CompletableFuture<Message> future = channel.sendMessage(TrueDiscordLink.stripColorCodes(discordlink.getTranslation("messages.from_mc_bot_format", false,
new String[] { "%message%", content },
new String[] { "%name%" , TrueDiscordLink.escapeDiscordFormatting(player.getName()) },
new String[] { "%displayName%", TrueDiscordLink.escapeDiscordFormatting(player.getDisplayName()) },
new String[] { "%display_name%", TrueDiscordLink.escapeDiscordFormatting(player.getDisplayName()) },
new String[] { "%uuid%", player.getUniqueId().toString() }
)));
if (blocking) {
Expand Down Expand Up @@ -373,7 +373,7 @@ private void sendDiscordWebhookMessage(String content, Player player) {
this.makeWebhookRequest(url, TrueDiscordLink.stripColorCodes(discordlink.getTranslation("messages.from_mc_webhook_format", false,
new String[] { "%message%", content },
new String[] { "%name%" , TrueDiscordLink.escapeDiscordFormatting(player.getName()) },
new String[] { "%displayName%", TrueDiscordLink.escapeDiscordFormatting(player.getDisplayName()) },
new String[] { "%display_name%", TrueDiscordLink.escapeDiscordFormatting(player.getDisplayName()) },
new String[] { "%uuid%", player.getUniqueId().toString() }
)), TrueDiscordLink.stripColorCodes(player.getDisplayName()), skin); // TODO: Why is the username not customizable
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private void migrateConfigurations() throws IOException {
migrated = true;
}
if (!translations.contains("linking.discord.notify", true)) {
translations.set("linking.discord.notify.link", "%username% has linked with %mention%!");
translations.set("linking.discord.notify.unlink", "%username% has unlinked with %mention%!");
translations.set("linking.discord.notify.link", "%name% has linked with %mention%!");
translations.set("linking.discord.notify.unlink", "%name% has unlinked with %mention%!");
this.getLogger().info("[en.yml] Added linking.discord.notify.*");
migrated = true;
}
Expand Down Expand Up @@ -150,6 +150,16 @@ private void migrateConfigurations() throws IOException {
migrated = true;
}

// v1.3.0 -> v1.3.3
if (Objects.requireNonNull(translations.getString("linking.discord.notify.link")).contains("%username%")) {
translations.set("linking.discord.notify.link", this.getTranslation("linking.discord.notify.link", false).replace("%username%", "%name%"));
migrated = true;
}
if (Objects.requireNonNull(translations.getString("linking.discord.notify.unlink")).contains("%username%")) {
translations.set("linking.discord.notify.unlink", this.getTranslation("linking.discord.notify.link", false).replace("%username%", "%name%"));
migrated = true;
}

// Save
if (migrated) {
this.saveConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (plugin.getConfig().getBoolean("bot.linking.notify.unlink.enabled")) {
TextChannel channel = ((TrueDiscordLink) plugin).getDiscordManager().getApi().getChannelById(plugin.getConfig().getString("bot.linking.notify.unlink.channel")).orElseThrow(() -> new Exception("Unlink Notification Channel cannot be null!")).asTextChannel().orElseThrow(() -> new Exception("Unlink Notification Channel must be a text channel"));
channel.sendMessage(plugin.getTranslation("linking.discord.notify.unlink",
new String[] { "%username%", player.getName() },
new String[] { "%name%", player.getName() },
new String[] { "%tag%", ((TrueDiscordLink) plugin).getDiscordManager().getApi().getUserById(userId).get().getDiscriminatedName() },
new String[] { "%mention%", "<@" + userId + ">"}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onMessageCreate(MessageCreateEvent event) {
if (discordlink.getConfig().getBoolean("bot.linking.notify.link.enabled")) {
TextChannel channel = discordlink.getDiscordManager().getApi().getChannelById(discordlink.getConfig().getString("bot.linking.notify.link.channel")).orElseThrow(() -> new Exception("Link Notification Channel cannot be null!")).asTextChannel().orElseThrow(() -> new Exception("Link Notification Channel must be a text channel"));
channel.sendMessage(discordlink.getTranslation("linking.discord.notify.link",
new String[] { "%username%", player.getName() },
new String[] { "%name%", player.getName() },
new String[] { "%tag%", message.getAuthor().getDiscriminatedName() },
new String[] { "%mention%", "<@" + message.getAuthor().getIdAsString() + ">"}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onMessageEdit(MessageEditEvent event) {
}

// If the message doesn't exist, return
Message message = event.getMessage().orElse(null);
Message message = event.getMessage();
if (message == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onPlayerAdvancementDone(PlayerAdvancementDoneEvent event) {
discordlink.getDiscordManager().sendDiscordMessage(
discordlink.getTranslation("events.player_advance", false,
new String[] { "%name%", event.getPlayer().getName() },
new String[] { "%displayName%", event.getPlayer().getDisplayName() },
new String[] { "%display_name%", event.getPlayer().getDisplayName() },
new String[] { "%uuid%", event.getPlayer().getUniqueId().toString() },
new String[] { "%advancement_name%", name },
new String[] { "%advancement_description%", description }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
discordlink.getTranslation("events.player_death", false,
new String[] { "%message%", event.getDeathMessage() },
new String[] { "%name%", TrueDiscordLink.escapeDiscordFormatting(TrueDiscordLink.stripColorCodes(event.getEntity().getName())) },
new String[] { "%displayName%", TrueDiscordLink.escapeDiscordFormatting(TrueDiscordLink.stripColorCodes(event.getEntity().getDisplayName())) },
new String[] { "%display_name%", TrueDiscordLink.escapeDiscordFormatting(TrueDiscordLink.stripColorCodes(event.getEntity().getDisplayName())) },
new String[] { "%uuid%", event.getEntity().getUniqueId().toString() }
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
discordlink.getDiscordManager().sendDiscordMessage(
discordlink.getTranslation("events.player_join", false,
new String[] { "%name%", TrueDiscordLink.escapeDiscordFormatting(event.getPlayer().getName()) },
new String[] { "%displayName%", TrueDiscordLink.escapeDiscordFormatting(event.getPlayer().getDisplayName()) },
new String[] { "%display_name%", TrueDiscordLink.escapeDiscordFormatting(event.getPlayer().getDisplayName()) },
new String[] { "%uuid%", event.getPlayer().getUniqueId().toString() }
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
discordlink.getDiscordManager().sendDiscordMessage(
discordlink.getTranslation("events.player_quit", false,
new String[] { "%name%", TrueDiscordLink.escapeDiscordFormatting(event.getPlayer().getName()) },
new String[] { "%displayName%", TrueDiscordLink.escapeDiscordFormatting(event.getPlayer().getDisplayName()) },
new String[] { "%display_name%", TrueDiscordLink.escapeDiscordFormatting(event.getPlayer().getDisplayName()) },
new String[] { "%uuid%", event.getPlayer().getUniqueId().toString() }
)
);
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/lang/en.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Global Arguments:
# - %prefix%: The prefix of the plugin
# - %message%: The content of a message
# - %display_name%: The display name of a Minecraft player or Discord user
# - %name%: A raw username for both Minecraft and Discord (no nickname or modifiers)
#
# Minecraft Arguments:
# - %displayName%: The displayName of a player
# - %uuid%: The UUID of a player
# - %advancement_name%: The name of a Minecraft advancement
# - %advancement_description%: The description of a Minecraft advancement
#
# Discord Arguments:
# - %nickname%: The nickname of a user, otherwise the username if no nickname is present
# - %nickname%: The nickname of a user, otherwise the display name if no nickname is present
# - %discriminator%: The discriminator of a user
# - %id%: The ID of a user
#
Expand Down Expand Up @@ -62,5 +62,5 @@ linking:
no_request: "You do not currently have a request to link your accounts. Make sure to run the `/tdl link` command in Minecraft first!"
success: "Congratulations! Your Minecraft and Discord accounts are now linked!"
notify:
link: "%username% has linked with %mention%!"
unlink: "%username% has unlinked with %mention%!"
link: "%name% has linked with %mention%!"
unlink: "%name% has unlinked with %mention%!"

0 comments on commit 5035bd3

Please sign in to comment.