11package pro .cloudnode .smp .cloudnodemsg ;
22
3+ import net .kyori .adventure .audience .Audience ;
34import net .kyori .adventure .text .Component ;
45import org .bukkit .NamespacedKey ;
56import org .bukkit .OfflinePlayer ;
1213import pro .cloudnode .smp .cloudnodemsg .error .InvalidPlayerError ;
1314import pro .cloudnode .smp .cloudnodemsg .error .PlayerHasIncomingDisabledError ;
1415import pro .cloudnode .smp .cloudnodemsg .error .PlayerNotFoundError ;
16+ import pro .cloudnode .smp .cloudnodemsg .error .ReplyOfflineError ;
1517
1618import java .util .Arrays ;
1719import java .util .HashSet ;
@@ -45,19 +47,22 @@ public Message(@NotNull OfflinePlayer sender, @NotNull OfflinePlayer recipient,
4547 }
4648
4749 public void send () throws InvalidPlayerError {
48- send (false );
50+ send (false , false );
4951 }
5052
51- public void send (final boolean channel ) throws InvalidPlayerError {
53+ public void send (final boolean channel , final boolean inReply ) throws InvalidPlayerError {
5254 final @ NotNull String senderUsername = playerOrServerUsername (this .sender );
5355 final @ NotNull String recipientUsername = playerOrServerUsername (this .recipient );
5456
5557 final @ NotNull Optional <@ NotNull Player > senderPlayer = Optional .ofNullable (this .sender .getPlayer ());
5658 final @ NotNull Optional <@ NotNull Player > recipientPlayer = Optional .ofNullable (this .recipient .getPlayer ());
5759
58- if (senderPlayer .isPresent () && (recipientPlayer .isEmpty () || (CloudnodeMSG .isVanished (recipientPlayer .get ()) && !senderPlayer
59- .get ().hasPermission (Permission .SEND_VANISHED )))) {
60- if (!channel ) new PlayerNotFoundError (senderPlayer .get ().getName ()).send (senderPlayer .get ());
60+ if (!recipient .getUniqueId ().equals (console .getUniqueId ()) && recipientPlayer .isEmpty () || (recipientPlayer .isPresent () && senderPlayer .isPresent () && CloudnodeMSG .isVanished (recipientPlayer .get ()) && !senderPlayer .get ().hasPermission (Permission .SEND_VANISHED ))) {
61+ if (!channel ) {
62+ final @ NotNull Audience senderAudience = senderPlayer .isPresent () ? senderPlayer .get () : CloudnodeMSG .getInstance ().getServer ();
63+ if (inReply ) new ReplyOfflineError (recipientUsername ).send (senderAudience );
64+ else new PlayerNotFoundError (recipientUsername ).send (senderAudience );
65+ }
6166 else {
6267 Message .exitChannel (senderPlayer .get ());
6368 new ChannelOfflineError (senderPlayer .get ().getName (), Optional .ofNullable (recipient .getName ())
@@ -72,17 +77,16 @@ public void send(final boolean channel) throws InvalidPlayerError {
7277 return ;
7378 }
7479
75- sendMessage (sender , CloudnodeMSG .getInstance ().config ().outgoing (senderUsername , recipientUsername , message ));
76- if (senderPlayer .isPresent () && !Message .hasChannel (senderPlayer .get (), recipient ))
77- setReplyTo (sender , recipient );
78-
7980 sendSpyMessage (sender , recipient , message );
80-
81+ sendMessage ( sender , CloudnodeMSG . getInstance (). config (). outgoing ( senderUsername , recipientUsername , message ));
8182 if ((recipientPlayer .isPresent () && Message .isIgnored (recipientPlayer .get (), sender )) && (senderPlayer .isPresent () && !senderPlayer
8283 .get ().hasPermission (Permission .IGNORE_BYPASS ))) return ;
8384 sendMessage (recipient , CloudnodeMSG .getInstance ().config ()
8485 .incoming (senderUsername , recipientUsername , message ));
85- if (recipientPlayer .isPresent () && !Message .hasChannel (recipientPlayer .get (), sender ))
86+
87+ if (sender .getUniqueId ().equals (console .getUniqueId ()) || (senderPlayer .isPresent () && !Message .hasChannel (senderPlayer .get (), recipient )))
88+ setReplyTo (sender , recipient );
89+ if (recipient .getUniqueId ().equals (console .getUniqueId ()) || (recipientPlayer .isPresent () && !Message .hasChannel (recipientPlayer .get (), sender )))
8690 setReplyTo (recipient , sender );
8791 }
8892
0 commit comments