diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index 867e4428..dadf089b 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -80,6 +80,22 @@ public interface ProxiedPlayer extends Connection, CommandSender */ public void sendMessage(ChatMessageType position, BaseComponent message); + /** + * Send a message to this player. + * + * @param sender the sender of the message + * @param message the message to send + */ + public void sendMessage(UUID sender, BaseComponent... message); + + /** + * Send a message to this player. + * + * @param sender the sender of the message + * @param message the message to send + */ + public void sendMessage(UUID sender, BaseComponent message); + /** * Connects / transfers this user to the specified connection, gracefully * closing the current one. Depending on the implementation, this method diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java index b5615a9f..7a0a1ce7 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java @@ -2,7 +2,6 @@ package net.md_5.bungee.protocol.packet; import io.netty.buffer.ByteBuf; import java.util.UUID; -import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -12,7 +11,6 @@ import net.md_5.bungee.protocol.ProtocolConstants; @Data @NoArgsConstructor -@AllArgsConstructor @EqualsAndHashCode(callSuper = false) public class Chat extends DefinedPacket { @@ -32,6 +30,13 @@ public class Chat extends DefinedPacket this( message, position, EMPTY_UUID ); } + public Chat(String message, byte position, UUID sender) + { + this.message = message; + this.position = position; + this.sender = sender == null ? EMPTY_UUID : sender; + } + @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 4199bdad..90bfc8cb 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -441,13 +441,36 @@ public final class UserConnection implements ProxiedPlayer sendMessage( ChatMessageType.SYSTEM, message ); } - private void sendMessage(ChatMessageType position, String message) + @Override + public void sendMessage(ChatMessageType position, BaseComponent... message) { - unsafe().sendPacket( new Chat( message, (byte) position.ordinal() ) ); + sendMessage( position, null, message ); } @Override - public void sendMessage(ChatMessageType position, BaseComponent... message) + public void sendMessage(ChatMessageType position, BaseComponent message) + { + sendMessage( position, (UUID) null, message ); + } + + @Override + public void sendMessage(UUID sender, BaseComponent... message) + { + sendMessage( ChatMessageType.CHAT, sender, message ); + } + + @Override + public void sendMessage(UUID sender, BaseComponent message) + { + sendMessage( ChatMessageType.CHAT, sender, message ); + } + + private void sendMessage(ChatMessageType position, UUID sender, String message) + { + unsafe().sendPacket( new Chat( message, (byte) position.ordinal(), sender ) ); + } + + private void sendMessage(ChatMessageType position, UUID sender, BaseComponent... message) { // transform score components message = ChatComponentTransformer.getInstance().transform( this, true, message ); @@ -458,7 +481,7 @@ public final class UserConnection implements ProxiedPlayer // Fix by converting to a legacy message, see https://bugs.mojang.com/browse/MC-119145 if ( getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_10 ) { - sendMessage( position, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) ); + sendMessage( position, sender, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) ); } else { net.md_5.bungee.protocol.packet.Title title = new net.md_5.bungee.protocol.packet.Title(); @@ -468,22 +491,7 @@ public final class UserConnection implements ProxiedPlayer } } else { - sendMessage( position, ComponentSerializer.toString( message ) ); - } - } - - @Override - public void sendMessage(ChatMessageType position, BaseComponent message) - { - message = ChatComponentTransformer.getInstance().transform( this, true, message )[0]; - - // Action bar doesn't display the new JSON formattings, legacy works - send it using this for now - if ( position == ChatMessageType.ACTION_BAR ) - { - sendMessage( position, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) ); - } else - { - sendMessage( position, ComponentSerializer.toString( message ) ); + sendMessage( position, sender, ComponentSerializer.toString( message ) ); } }