From 6786795c1f943e639b1ac311bad68aaa5b8ac203 Mon Sep 17 00:00:00 2001 From: TheFaser Date: Sun, 24 Dec 2023 22:03:31 +0500 Subject: [PATCH] Integrations: fix invisible name for DiscordSRV --- .../chat/module/integrations/FDiscordSRV.java | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/flectone/chat/module/integrations/FDiscordSRV.java b/src/main/java/net/flectone/chat/module/integrations/FDiscordSRV.java index 94503d8..e1e223b 100644 --- a/src/main/java/net/flectone/chat/module/integrations/FDiscordSRV.java +++ b/src/main/java/net/flectone/chat/module/integrations/FDiscordSRV.java @@ -13,9 +13,11 @@ import net.flectone.chat.model.damager.PlayerDamager; import net.flectone.chat.model.file.FConfiguration; import net.flectone.chat.model.player.Moderation; +import net.flectone.chat.util.MessageUtil; import net.flectone.chat.util.TimeUtil; import org.bukkit.Material; import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -69,22 +71,31 @@ public void init() { public void sendDeathMessage(@NotNull Player sender, @NotNull PlayerDamager playerDamager, @NotNull String typeDeath) { Entity finalEntity = playerDamager.getFinalEntity(); + Material finalBlock = playerDamager.getFinalBlockDamager(); Entity killer = playerDamager.getKiller(); ItemStack killerItem = playerDamager.getKillerItem(); String message = integrations.getString("DiscordSRV.message.death.type" + typeDeath); - if (finalEntity != null) message = message - .replace("", finalEntity.getName()) - .replace("", finalEntity.getName()); + if (finalEntity != null) { + String finalEntityName = finalEntity instanceof Player player + ? MessageUtil.formatPlayerString(player, "") + : finalEntity.getName(); + message = message + .replace("", finalEntityName) + .replace("", finalEntityName); + } if (finalBlock != null) message = message .replace("", finalBlock.name()); if (killer != null && finalEntity != null && !killer.getType().equals(finalEntity.getType())) { + String killerName = killer instanceof Player player + ? MessageUtil.formatPlayerString(player, "") + : finalEntity.getName(); String dueToMessage = integrations.getString("DiscordSRV.message.death.due-to"); - message = message.replace("", dueToMessage.replace("", killer.getName())); + message = message.replace("", dueToMessage.replace("", killerName)); } if (killerItem != null) { @@ -106,45 +117,49 @@ public void sendDeathMessage(@NotNull Player sender, @NotNull PlayerDamager play Map replacements = new HashMap<>(); replacements.put("", message); - replacements.put("", sender.getName()); + replacements.put("", MessageUtil.formatPlayerString(sender, "")); sendMessage(sender, "death", replacements); } public void sendJoinMessage(@NotNull Player sender, @NotNull String type) { + String senderName = MessageUtil.formatPlayerString(sender, ""); + String message = integrations.getString("DiscordSRV.message.join.type." + type) - .replace("", sender.getName()); + .replace("", senderName); Map replacements = new HashMap<>(); replacements.put("", message); - replacements.put("", sender.getName()); + replacements.put("", senderName); sendMessage(sender, "join", replacements); } public void sendQuitMessage(@NotNull Player sender, @NotNull String type) { + String senderName = MessageUtil.formatPlayerString(sender, ""); + String message = integrations.getString("DiscordSRV.message.quit.type." + type) - .replace("", sender.getName()); + .replace("", senderName); Map replacements = new HashMap<>(); replacements.put("", message); - replacements.put("", sender.getName()); + replacements.put("", senderName); sendMessage(sender, "quit", replacements); } public void sendAdvancementMessage(@NotNull Player sender, @NotNull FAdvancement advancement) { HashMap replacements = new HashMap<>(); - replacements.put("", sender.getName()); + replacements.put("", MessageUtil.formatPlayerString(sender, "")); replacements.put("", advancement.getTitle()); sendMessage(sender, "advancement-" + advancement.getType(), replacements); } public void sendStreamMessage(@Nullable Player sender, @NotNull String urls) { - String senderName = sender == null ? "CONSOLE" : sender.getName(); + String senderName = sender == null ? "CONSOLE" : MessageUtil.formatPlayerString(sender, ""); HashMap replacements = new HashMap<>(); replacements.put("", senderName); @@ -170,7 +185,7 @@ public void sendBanMessage(@Nullable OfflinePlayer sender, @NotNull Moderation m public void sendMuteMessage(@Nullable OfflinePlayer sender, @NotNull Moderation moderation) { HashMap replacements = new HashMap<>(); - replacements.put("", moderation.getModeratorName()); + replacements.put("", moderation.getPlayerName()); replacements.put("