Don't send whisper to offline players ty

This commit is contained in:
Draycia committed 2020-09-08 21:41:46 -07:00
1 parent 986475b2b9
commit a99f445c3c
2 files changed
+21 -1

No files matched your search

@@ -1,5 +1,6 @@
package net.draycia.carbon.storage.impl; package net.draycia.carbon.storage.impl;
import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi;
import net.draycia.carbon.CarbonChat; import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel; import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.events.ChannelSwitchEvent; import net.draycia.carbon.events.ChannelSwitchEvent;
@@ -303,14 +304,32 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
} }
} }
} else if (sender.isOnline()) { } else if (sender.isOnline()) {
final String targetNameFinal = targetName;
final String senderNameFinal = senderName;
BungeeChannelApi.of(carbonChat).getPlayerList("ALL").thenAccept(list -> {
if (!list.contains(this.asOfflinePlayer().getName())) {
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
"br", "\n",
"message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName,
"target", targetNameFinal, "sender", senderNameFinal);
sender.sendMessage(playerOfflineComponent);
return;
}
sender.sendMessage(toPlayerComponent); sender.sendMessage(toPlayerComponent);
// TODO: make sure this works lol
carbonChat.getMessageManager().sendMessage("whisper-component", sender.getUUID(), (byteArray) -> { carbonChat.getMessageManager().sendMessage("whisper-component", sender.getUUID(), (byteArray) -> {
byteArray.writeLong(this.getUUID().getMostSignificantBits()); byteArray.writeLong(this.getUUID().getMostSignificantBits());
byteArray.writeLong(this.getUUID().getLeastSignificantBits()); byteArray.writeLong(this.getUUID().getLeastSignificantBits());
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(fromPlayerComponent)); byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(fromPlayerComponent));
}); });
});
} }
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
+1
View File
@@ -12,6 +12,7 @@ formatting:
reloaded: '<yellow>Chat config has been reloaded!' reloaded: '<yellow>Chat config has been reloaded!'
message-to-other: '<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>' message-to-other: '<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>'
message-from-other: '<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>' message-from-other: '<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>'
other-player-offline: '<red>That player is offline!'
spy-whispers: '<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>' spy-whispers: '<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>'
no-reply-target: '<red>You have no one to reply to!' no-reply-target: '<red>You have no one to reply to!'
empty-channel: 'NONE' #<channel>, set to "NONE" to disable empty-channel: 'NONE' #<channel>, set to "NONE" to disable