#2978: Allow sending messages from specific UUIDs
This commit is contained in:
parent
c987ee199d
commit
8fffa206e4
@ -80,6 +80,22 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
|||||||
*/
|
*/
|
||||||
public void sendMessage(ChatMessageType position, BaseComponent message);
|
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
|
* Connects / transfers this user to the specified connection, gracefully
|
||||||
* closing the current one. Depending on the implementation, this method
|
* closing the current one. Depending on the implementation, this method
|
||||||
|
@ -2,7 +2,6 @@ package net.md_5.bungee.protocol.packet;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -12,7 +11,6 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Chat extends DefinedPacket
|
public class Chat extends DefinedPacket
|
||||||
{
|
{
|
||||||
@ -32,6 +30,13 @@ public class Chat extends DefinedPacket
|
|||||||
this( message, position, EMPTY_UUID );
|
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
|
@Override
|
||||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||||
{
|
{
|
||||||
|
@ -441,13 +441,36 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
sendMessage( ChatMessageType.SYSTEM, message );
|
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
|
@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
|
// transform score components
|
||||||
message = ChatComponentTransformer.getInstance().transform( this, true, message );
|
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
|
// Fix by converting to a legacy message, see https://bugs.mojang.com/browse/MC-119145
|
||||||
if ( getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_10 )
|
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
|
} else
|
||||||
{
|
{
|
||||||
net.md_5.bungee.protocol.packet.Title title = new net.md_5.bungee.protocol.packet.Title();
|
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
|
} else
|
||||||
{
|
{
|
||||||
sendMessage( position, ComponentSerializer.toString( message ) );
|
sendMessage( position, sender, 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 ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user