Requesting PR for 1.19.1 (and 1.19.2) #44

Merged
isu-kim merged 8 commits from main into main 2022-08-16 12:03:14 +00:00
3 changed files with 21 additions and 11 deletions
Showing only changes of commit 67354e0917 - Show all commits

No files matched your search

@@ -119,7 +119,7 @@ public class Bot extends Thread {
new ArrayList<>(), new ArrayList<>(),
true, true,
new ArrayList<>(), new ArrayList<>(),
new LastSeenMessage(uuid, new byte[0]) null
)); ));
} else { } else {
// Send chat message // Send chat message
@@ -132,7 +132,7 @@ public class Bot extends Thread {
new byte[0], new byte[0],
true, true,
new ArrayList<>(), new ArrayList<>(),
new LastSeenMessage(uuid, new byte[0]) null
)); ));
} }
} }
@@ -41,9 +41,11 @@ public class MainListener implements SessionListener {
} else { // If this was normal case when unsigned content was not null. } else { // If this was normal case when unsigned content was not null.
if (message instanceof TextComponent) { // For normal chat packets. 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.
if (sender != null)
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.
else
Log.chat(Utils.getFullText(null, (TextComponent) message, Main.coloredChat)); // Use this for messages and sender's username.
} }
if (message instanceof TranslatableComponent) { // For system chat packets (such as user joining server). 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));
@@ -10,6 +10,7 @@ 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.Style;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import java.io.InputStream; import java.io.InputStream;
@@ -59,21 +60,21 @@ public class Utils {
* @param colored Whether if this output was colored or not. * @param colored Whether if this output was colored or not.
* @return Returns String in "Username : Message" format. * @return Returns String in "Username : Message" format.
*/ */
public static String getFullText(TextComponent sender, TextComponent message, boolean colored) { public static String getFullText(@Nullable TextComponent sender, TextComponent message, boolean colored) {
if (colored) { // Check if we are using colors. if (colored) { // Check if we are using colors.
Style senderStyle = sender.style();
Style messageStyle = message.style(); Style messageStyle = message.style();
StringBuilder outString = new StringBuilder(); StringBuilder outString = new StringBuilder();
if (sender != null) {
Style senderStyle = sender.style();
if (senderStyle.color() != null) { // Generate sender text with color. if (senderStyle.color() != null) { // Generate sender text with color.
NamedTextColor color = (NamedTextColor) senderStyle.color(); NamedTextColor color = (NamedTextColor) senderStyle.color();
outString.append(colorize(sender.content(), getColor(color))); outString.append(colorize(sender.content(), getColor(color)));
} else { } else {
outString.append(sender.content()); outString.append(sender.content());
} }
outString.append(" : "); // Add delimiter as : between sender and message. outString.append(" : "); // Add delimiter as : between sender and message.
}
if (messageStyle.color() != null) { // Generate message text with color. if (messageStyle.color() != null) { // Generate message text with color.
NamedTextColor color = (NamedTextColor) messageStyle.color(); NamedTextColor color = (NamedTextColor) messageStyle.color();
@@ -84,6 +85,9 @@ public class Utils {
return outString.toString(); return outString.toString();
} else { // When color formating was disabled. } else { // When color formating was disabled.
if (sender == null)
return message.content();
else
return sender.content() + " : " + message.content(); return sender.content() + " : " + message.content();
} }
} }
@@ -98,23 +102,27 @@ public class Utils {
* @param colored Whether if this output was colored or not. * @param colored Whether if this output was colored or not.
* @return Returns String in "Username : Message" format. * @return Returns String in "Username : Message" format.
*/ */
public static String getFullText(TextComponent sender, String message, boolean colored) { public static String getFullText(@Nullable TextComponent sender, String message, boolean colored) {
if (colored) { // Check if we are using colors. if (colored) { // Check if we are using colors.
Style senderStyle = sender.style();
StringBuilder outString = new StringBuilder(); StringBuilder outString = new StringBuilder();
if (sender != null) {
Style senderStyle = sender.style();
if (senderStyle.color() != null) { // Generate sender text with color. if (senderStyle.color() != null) { // Generate sender text with color.
NamedTextColor color = (NamedTextColor) senderStyle.color(); NamedTextColor color = (NamedTextColor) senderStyle.color();
outString.append(colorize(sender.content(), getColor(color))); outString.append(colorize(sender.content(), getColor(color)));
} else { } else {
outString.append(sender.content()); outString.append(sender.content());
} }
outString.append(" : "); // Add delimiter as : between sender and message. outString.append(" : "); // Add delimiter as : between sender and message.
}
outString.append(message); outString.append(message);
return outString.toString(); return outString.toString();
} else { // When color formating was disabled. } else { // When color formating was disabled.
if (sender == null)
return message;
else
return sender.content() + " : " + message; return sender.content() + " : " + message;
} }
} }