Requesting PR for 1.19.1 (and 1.19.2) #44
No files matched your search
@@ -21,37 +21,35 @@ public class MainListener implements SessionListener {
|
||||
// Instead, they use ClientboundPlayerChatPacket and ClientboundSystemChatPacket for taking care of chat packets.
|
||||
Component message = null;
|
||||
Component sender = null;
|
||||
boolean isMessageNull = false; // For some cases when message is null.
|
||||
boolean chatPrintedOut = false;
|
||||
|
||||
if (packet instanceof ClientboundPlayerChatPacket) {
|
||||
ClientboundPlayerChatPacket clientboundPlayerChatPacket = ((ClientboundPlayerChatPacket) packet);
|
||||
message = clientboundPlayerChatPacket.getUnsignedContent();
|
||||
sender = clientboundPlayerChatPacket.getName();
|
||||
isMessageNull = message == null;
|
||||
|
||||
if (message == null) { // When this message was null.
|
||||
Log.chat(Utils.getFullText((TextComponent) sender, clientboundPlayerChatPacket.getMessagePlain(), Main.coloredChat));
|
||||
chatPrintedOut = true;
|
||||
} else {
|
||||
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat));
|
||||
chatPrintedOut = true;
|
||||
}
|
||||
|
||||
} else if (packet instanceof ClientboundSystemChatPacket) {
|
||||
message = ((ClientboundSystemChatPacket) packet).getContent();
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (sender != null)
|
||||
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat)); // Use this for messages and sender's username.
|
||||
else
|
||||
Log.chat(Utils.getFullText(null, (TextComponent) message, Main.coloredChat)); // Use this for messages and sender's username.
|
||||
TextComponent msg = (TextComponent) message;
|
||||
if (!chatPrintedOut)
|
||||
Log.chat(Utils.getFullText(msg, Main.coloredChat)); // Use this for only messages.
|
||||
}
|
||||
if (message instanceof TranslatableComponent) { // For system chat packets (such as user joining server).
|
||||
TranslatableComponent msg = (TranslatableComponent) message;
|
||||
Log.chat("[T]", Utils.translate(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSending(PacketSendingEvent event) {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
return outString.toString();
|
||||
} else { // When color formating was disabled.
|
||||
} else { // When color formatting was disabled.
|
||||
if (sender == null)
|
||||
return message.content();
|
||||
else
|
||||
@@ -119,7 +119,7 @@ public class Utils {
|
||||
|
||||
outString.append(message);
|
||||
return outString.toString();
|
||||
} else { // When color formating was disabled.
|
||||
} else { // When color formatting was disabled.
|
||||
if (sender == null)
|
||||
return message;
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user