Requesting PR for 1.19.1 (and 1.19.2) #44
No files matched your search
@@ -21,25 +21,35 @@ public class MainListener implements SessionListener {
|
|||||||
// Instead, they use ClientboundPlayerChatPacket and ClientboundSystemChatPacket for taking care of chat packets.
|
// Instead, they use ClientboundPlayerChatPacket and ClientboundSystemChatPacket for taking care of chat packets.
|
||||||
Component message = null;
|
Component message = null;
|
||||||
Component sender = null;
|
Component sender = null;
|
||||||
|
boolean isMessageNull = false; // For some cases when message is null.
|
||||||
|
|
||||||
if (packet instanceof ClientboundPlayerChatPacket) {
|
if (packet instanceof ClientboundPlayerChatPacket) {
|
||||||
ClientboundPlayerChatPacket clientboundPlayerChatPacket = ((ClientboundPlayerChatPacket) packet);
|
ClientboundPlayerChatPacket clientboundPlayerChatPacket = ((ClientboundPlayerChatPacket) packet);
|
||||||
message = clientboundPlayerChatPacket.getUnsignedContent();
|
message = clientboundPlayerChatPacket.getUnsignedContent();
|
||||||
sender = clientboundPlayerChatPacket.getName();
|
sender = clientboundPlayerChatPacket.getName();
|
||||||
|
isMessageNull = message == null;
|
||||||
} else if (packet instanceof ClientboundSystemChatPacket) {
|
} else if (packet instanceof ClientboundSystemChatPacket) {
|
||||||
message = ((ClientboundSystemChatPacket) packet).getContent();
|
message = ((ClientboundSystemChatPacket) packet).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message instanceof TextComponent) {
|
// For some commands (like /say), ClientboundPlayerChatPacket.getUnsignedContent() is null.
|
||||||
|
// However for those cases, the message is still valid in ClientboundPlayerChatPacket.getMessagePlain()
|
||||||
|
// Thus, this if condition will figure out if this case was the case and prints out message from the packet.
|
||||||
|
if (isMessageNull) { // When this message was null.
|
||||||
|
ClientboundPlayerChatPacket clientboundPlayerChatPacket = ((ClientboundPlayerChatPacket) packet);
|
||||||
|
Log.chat(Utils.getFullText((TextComponent) sender, clientboundPlayerChatPacket.getMessagePlain(), Main.coloredChat));
|
||||||
|
} else { // If this was normal case when unsigned content was not null.
|
||||||
|
if (message instanceof TextComponent) { // For normal chat packets.
|
||||||
// Log.chat(Utils.getFullText((TextComponent) message, Main.coloredChat)); // Use this for only messages.
|
// Log.chat(Utils.getFullText((TextComponent) message, Main.coloredChat)); // Use this for only messages.
|
||||||
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat)); // Use this for messages and sender's username.
|
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat)); // Use this for messages and sender's username.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message instanceof TranslatableComponent) {
|
if (message instanceof TranslatableComponent) { // For system chat packets (such as user joining server).
|
||||||
TranslatableComponent msg = (TranslatableComponent) message;
|
TranslatableComponent msg = (TranslatableComponent) message;
|
||||||
Log.chat("[T]", Utils.translate(msg));
|
Log.chat("[T]", Utils.translate(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetSending(PacketSendingEvent event) {
|
public void packetSending(PacketSendingEvent event) {
|
||||||
|
|||||||
@@ -88,6 +88,37 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A static function that gets full text from text components.
|
||||||
|
* From 1.19.1 the protocol does not include sender's information in the message.
|
||||||
|
* Sometimes the message as component is null. When this happens, this method will show message as String.
|
||||||
|
* Since this is just a String being represented, this will not have formatting on String.
|
||||||
|
* @param sender The TextComponent for sender.
|
||||||
|
* @param message The TextComponent for message.
|
||||||
|
* @param colored Whether if this output was colored or not.
|
||||||
|
* @return Returns String in "Username : Message" format.
|
||||||
|
*/
|
||||||
|
public static String getFullText(TextComponent sender, String message, boolean colored) {
|
||||||
|
if (colored) { // Check if we are using colors.
|
||||||
|
Style senderStyle = sender.style();
|
||||||
|
|
||||||
|
StringBuilder outString = new StringBuilder();
|
||||||
|
|
||||||
|
if (senderStyle.color() != null) { // Generate sender text with color.
|
||||||
|
NamedTextColor color = (NamedTextColor) senderStyle.color();
|
||||||
|
outString.append(colorize(sender.content(), getColor(color)));
|
||||||
|
} else {
|
||||||
|
outString.append(sender.content());
|
||||||
|
}
|
||||||
|
|
||||||
|
outString.append(" : "); // Add delimiter as : between sender and message.
|
||||||
|
outString.append(message);
|
||||||
|
return outString.toString();
|
||||||
|
} else { // When color formating was disabled.
|
||||||
|
return sender.content() + " : " + message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Attribute getColor(NamedTextColor color) {
|
public static Attribute getColor(NamedTextColor color) {
|
||||||
switch (color.toString()) {
|
switch (color.toString()) {
|
||||||
case "red":
|
case "red":
|
||||||
|
|||||||
Reference in new issue
Block a user