Requesting PR for 1.19.1 (and 1.19.2) #44
No files matched your search
@@ -125,7 +125,6 @@ public class Bot extends Thread {
|
|||||||
// Send chat message
|
// Send chat message
|
||||||
// From 1.19.1 or 1.19, the ServerboundChatPacket needs timestamp, salt and signed signature to generate packet.
|
// From 1.19.1 or 1.19, the ServerboundChatPacket needs timestamp, salt and signed signature to generate packet.
|
||||||
// tmpSignature will provide an empty byte array that can pretend it as signature.
|
// tmpSignature will provide an empty byte array that can pretend it as signature.
|
||||||
byte[] tmpSignature = new byte[0]; // Set it empty byte array.
|
|
||||||
// salt is set 0 since this is offline server and no body will check it.
|
// salt is set 0 since this is offline server and no body will check it.
|
||||||
client.send(new ServerboundChatPacket(text,
|
client.send(new ServerboundChatPacket(text,
|
||||||
timeStamp,
|
timeStamp,
|
||||||
|
|||||||
@@ -20,18 +20,21 @@ public class MainListener implements SessionListener {
|
|||||||
// From 1.19.1 (as well as 1.19), the class ClientboundChatPacket was removed.
|
// From 1.19.1 (as well as 1.19), the class ClientboundChatPacket was removed.
|
||||||
// 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;
|
||||||
|
|
||||||
if (packet instanceof ClientboundPlayerChatPacket) {
|
if (packet instanceof ClientboundPlayerChatPacket) {
|
||||||
message = ((ClientboundPlayerChatPacket) packet).getMessageDecorated();
|
ClientboundPlayerChatPacket clientboundPlayerChatPacket = ((ClientboundPlayerChatPacket) packet);
|
||||||
|
message = clientboundPlayerChatPacket.getUnsignedContent();
|
||||||
|
sender = clientboundPlayerChatPacket.getName();
|
||||||
} else if (packet instanceof ClientboundSystemChatPacket) {
|
} else if (packet instanceof ClientboundSystemChatPacket) {
|
||||||
message = ((ClientboundSystemChatPacket) packet).getContent();
|
message = ((ClientboundSystemChatPacket) packet).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log.chat(message.toString());
|
|
||||||
if (message instanceof TextComponent) {
|
if (message instanceof TextComponent) {
|
||||||
TextComponent msg = (TextComponent) message;
|
// Log.chat(Utils.getFullText((TextComponent) message, Main.coloredChat)); // Use this for only messages.
|
||||||
Log.chat(Utils.getFullText(msg, Main.coloredChat));
|
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) {
|
||||||
TranslatableComponent msg = (TranslatableComponent) message;
|
TranslatableComponent msg = (TranslatableComponent) message;
|
||||||
Log.chat("[T]", Utils.translate(msg));
|
Log.chat("[T]", Utils.translate(msg));
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.TranslatableComponent;
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -45,7 +47,45 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* Thus, we need to merge two TextComponent (sender and message) and generate a text that consists of sent message.
|
||||||
|
* This means using old getFullText will just send the message. Which does NOT contain username who sent this message
|
||||||
|
* @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, TextComponent message, boolean colored) {
|
||||||
|
if (colored) { // Check if we are using colors.
|
||||||
|
Style senderStyle = sender.style();
|
||||||
|
Style messageStyle = message.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.
|
||||||
|
|
||||||
|
if (messageStyle.color() != null) { // Generate message text with color.
|
||||||
|
NamedTextColor color = (NamedTextColor) messageStyle.color();
|
||||||
|
outString.append(colorize(message.content(), getColor(color)));
|
||||||
|
} else {
|
||||||
|
outString.append(message.content());
|
||||||
|
}
|
||||||
|
|
||||||
|
return outString.toString();
|
||||||
|
} else { // When color formating was disabled.
|
||||||
|
return sender.content() + " : " + message.content();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Attribute getColor(NamedTextColor color) {
|
public static Attribute getColor(NamedTextColor color) {
|
||||||
|
|||||||
Reference in new issue
Block a user