From c0664ab653c04eb8df0bc2b150c6c1f706ab62c8 Mon Sep 17 00:00:00 2001 From: TheFaser Date: Fri, 22 Dec 2023 23:38:16 +0500 Subject: [PATCH] Chat: fix noRecipient message to be after main message --- .../playerMessage/chat/ChatListener.java | 20 ++++++++++--------- .../module/playerMessage/chat/ChatModule.java | 4 +++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatListener.java b/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatListener.java index a2879ba..b2145ea 100644 --- a/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatListener.java +++ b/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatListener.java @@ -130,20 +130,22 @@ public void playerChatEvent(@NotNull AsyncPlayerChatEvent event) { String chatFormat = config.getVaultString(sender, getModule() + ".list." + playerChat + ".format"); chatFormat = MessageUtil.formatPlayerString(sender, chatFormat); - ((ChatModule) getModule()).send(sender, recipientsList, message, chatFormat, featuresList); + List finalRecipientsList = recipientsList; + String finalPlayerChat1 = playerChat; + ((ChatModule) getModule()).send(sender, recipientsList, message, chatFormat, featuresList, () -> { + finalRecipientsList.removeIf(player -> player.getGameMode() == GameMode.SPECTATOR); + + boolean noRecipientsMessageEnabled = config.getVaultBoolean(sender, getModule() + ".list." + finalPlayerChat1 + ".no-recipients.enable"); + if ((finalRecipientsList.isEmpty() || finalRecipientsList.size() == 1) && noRecipientsMessageEnabled) { + String recipientsEmpty = locale.getVaultString(sender, getModule() + ".no-recipients"); + sender.sendMessage(MessageUtil.formatAll(sender, recipientsEmpty)); + } + }); CommandSpy.send(sender, playerChat, recipientsList, CommandSpy.Type.DEFAULT, message); fPlayer.playSound(sender, recipientsList, getModule() + "." + playerChat); - recipientsList.removeIf(player -> player.getGameMode() == GameMode.SPECTATOR); - - boolean noRecipientsMessageEnabled = config.getVaultBoolean(sender, getModule() + ".list." + playerChat + ".no-recipients.enable"); - if ((recipientsList.isEmpty() || recipientsList.size() == 1) && noRecipientsMessageEnabled) { - String recipientsEmpty = locale.getVaultString(sender, getModule() + ".no-recipients"); - sender.sendMessage(MessageUtil.formatAll(sender, recipientsEmpty)); - } - boolean isCancelled = config.getVaultBoolean(sender, getModule() + ".list." + playerChat + ".set-cancelled"); event.setCancelled(isCancelled); event.setMessage(message); diff --git a/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatModule.java b/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatModule.java index d40eb42..d6a0325 100644 --- a/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatModule.java +++ b/src/main/java/net/flectone/chat/module/playerMessage/chat/ChatModule.java @@ -28,7 +28,7 @@ public void init() { public void send(@NotNull Player sender, @NotNull List recipientsList, @NotNull String message, @NotNull String chatFormat, - @NotNull List featuresList) { + @NotNull List featuresList, @NotNull Runnable noRecipientRunnable) { message = IntegrationsModule.interactiveChatMark(message, sender.getUniqueId()); @@ -43,6 +43,8 @@ public void send(@NotNull Player sender, @NotNull List recipientsList, if (fModule instanceof ChatBubbleModule chatBubbleModule) { chatBubbleModule.add(sender, messageBuilder.getMessage("")); } + + noRecipientRunnable.run(); }); } }