mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
option to send all console message to render chat box (and Log improvements)
This commit is contained in:
parent
bc9ffd84c3
commit
38bd37b9f0
@ -22,6 +22,7 @@ public class StaticConfiguration {
|
|||||||
public static final boolean DEBUG_MODE = true; // if true, additional checks will be made to validate data, ... Decreases performance
|
public static final boolean DEBUG_MODE = true; // if true, additional checks will be made to validate data, ... Decreases performance
|
||||||
public static final boolean BIOME_DEBUG_MODE = false; // colors all biomes according to the biome hashCode
|
public static final boolean BIOME_DEBUG_MODE = false; // colors all biomes according to the biome hashCode
|
||||||
public static final boolean DEBUG_SLOW_LOADING = false; // if true, many Thread.sleep will be executed and the start will be delayed (by a lot)
|
public static final boolean DEBUG_SLOW_LOADING = false; // if true, many Thread.sleep will be executed and the start will be delayed (by a lot)
|
||||||
|
public static final boolean SHOW_LOG_MESSAGES_IN_CHAT = false; // prints all console messages in the chat box
|
||||||
public static String CONFIG_FILENAME = "minosoft.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
|
public static String CONFIG_FILENAME = "minosoft.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
|
||||||
public static boolean SKIP_MOJANG_AUTHENTICATION; // disables all connections to mojang
|
public static boolean SKIP_MOJANG_AUTHENTICATION; // disables all connections to mojang
|
||||||
public static boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components)
|
public static boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components)
|
||||||
|
@ -49,7 +49,7 @@ public class BaseComponent extends ChatComponent {
|
|||||||
public BaseComponent(MinecraftLocaleManager localeManager, @Nullable ChatComponent parent, String text) {
|
public BaseComponent(MinecraftLocaleManager localeManager, @Nullable ChatComponent parent, String text) {
|
||||||
// legacy String
|
// legacy String
|
||||||
StringBuilder currentText = new StringBuilder();
|
StringBuilder currentText = new StringBuilder();
|
||||||
RGBColor color = ChatColors.WHITE;
|
RGBColor color = null;
|
||||||
BetterHashSet<ChatFormattingCode> formattingCodes = new BetterHashSet<>();
|
BetterHashSet<ChatFormattingCode> formattingCodes = new BetterHashSet<>();
|
||||||
StringCharacterIterator iterator = new StringCharacterIterator(text);
|
StringCharacterIterator iterator = new StringCharacterIterator(text);
|
||||||
while (iterator.current() != CharacterIterator.DONE) {
|
while (iterator.current() != CharacterIterator.DONE) {
|
||||||
@ -180,7 +180,7 @@ public class BaseComponent extends ChatComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return PostChatFormattingCodes.RESET.getANSI() + getANSIColoredMessage();
|
return getLegacyText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -245,4 +245,16 @@ public class BaseComponent extends ChatComponent {
|
|||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.parts.isEmpty();
|
return this.parts.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void applyDefaultColor(RGBColor color) {
|
||||||
|
for (var part : this.parts) {
|
||||||
|
if (part instanceof BaseComponent baseComponent) {
|
||||||
|
baseComponent.applyDefaultColor(color);
|
||||||
|
} else if (part instanceof TextComponent textComponent) {
|
||||||
|
if (textComponent.getColor() == null) {
|
||||||
|
textComponent.setColor(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,18 +39,17 @@ import java.util.function.Consumer
|
|||||||
|
|
||||||
open class TextComponent : ChatComponent {
|
open class TextComponent : ChatComponent {
|
||||||
private val text: String
|
private val text: String
|
||||||
var color: RGBColor = ChatColors.WHITE
|
var color: RGBColor? = null
|
||||||
|
private set
|
||||||
var formatting: BetterHashSet<ChatFormattingCode> = BetterHashSet()
|
var formatting: BetterHashSet<ChatFormattingCode> = BetterHashSet()
|
||||||
|
|
||||||
constructor(text: String, color: RGBColor?, formatting: BetterHashSet<ChatFormattingCode>) {
|
constructor(text: String, color: RGBColor?, formatting: BetterHashSet<ChatFormattingCode>) {
|
||||||
this.text = text
|
this.text = text
|
||||||
if (color != null) {
|
|
||||||
this.color = color
|
this.color = color
|
||||||
}
|
|
||||||
this.formatting = formatting
|
this.formatting = formatting
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(text: String, color: RGBColor) {
|
constructor(text: String, color: RGBColor?) {
|
||||||
this.text = text
|
this.text = text
|
||||||
this.color = color
|
this.color = color
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ open class TextComponent : ChatComponent {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setColor(color: RGBColor): TextComponent {
|
fun setColor(color: RGBColor?): TextComponent {
|
||||||
this.color = color
|
this.color = color
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -115,12 +114,14 @@ open class TextComponent : ChatComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return ansiColoredMessage
|
return legacyText
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getANSIColoredMessage(): String {
|
override fun getANSIColoredMessage(): String {
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
builder.append(ChatColors.getANSIColorByRGBColor(this.color))
|
this.color?.let {
|
||||||
|
builder.append(ChatColors.getANSIColorByRGBColor(it))
|
||||||
|
}
|
||||||
|
|
||||||
for (formattingCode in this.formatting) {
|
for (formattingCode in this.formatting) {
|
||||||
if (formattingCode is PreChatFormattingCodes) {
|
if (formattingCode is PreChatFormattingCodes) {
|
||||||
@ -139,10 +140,12 @@ open class TextComponent : ChatComponent {
|
|||||||
|
|
||||||
override fun getLegacyText(): String {
|
override fun getLegacyText(): String {
|
||||||
val output = StringBuilder()
|
val output = StringBuilder()
|
||||||
|
if (color != null) {
|
||||||
val colorChar = ChatColors.getColorId(color)
|
val colorChar = ChatColors.getColorId(color)
|
||||||
if (colorChar != null) {
|
if (colorChar != null) {
|
||||||
output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(Integer.toHexString(colorChar))
|
output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(Integer.toHexString(colorChar))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
formatting.forEach(Consumer { chatFormattingCode: ChatFormattingCode -> output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(chatFormattingCode.char) })
|
formatting.forEach(Consumer { chatFormattingCode: ChatFormattingCode -> output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(chatFormattingCode.char) })
|
||||||
output.append(text)
|
output.append(text)
|
||||||
output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(PostChatFormattingCodes.RESET.char)
|
output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(PostChatFormattingCodes.RESET.char)
|
||||||
@ -155,6 +158,7 @@ open class TextComponent : ChatComponent {
|
|||||||
|
|
||||||
override fun getJavaFXText(nodes: ObservableList<Node>): ObservableList<Node> {
|
override fun getJavaFXText(nodes: ObservableList<Node>): ObservableList<Node> {
|
||||||
val text = Text(text)
|
val text = Text(text)
|
||||||
|
val color = this.color ?: ProtocolDefinition.DEFAULT_COLOR
|
||||||
text.fill = Color.WHITE
|
text.fill = Color.WHITE
|
||||||
if (Minosoft.getConfig().config.chat.colored) {
|
if (Minosoft.getConfig().config.chat.colored) {
|
||||||
text.fill = Color.rgb(color.red, color.green, color.blue)
|
text.fill = Color.rgb(color.red, color.green, color.blue)
|
||||||
@ -204,6 +208,7 @@ open class TextComponent : ChatComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun addVerticies(startPosition: Vec2, offset: Vec2, perspectiveMatrix: Mat4, binding: FontBindings, font: Font, hudScale: HUDScale, mesh: HUDFontMesh, maxSize: Vec2) {
|
override fun addVerticies(startPosition: Vec2, offset: Vec2, perspectiveMatrix: Mat4, binding: FontBindings, font: Font, hudScale: HUDScale, mesh: HUDFontMesh, maxSize: Vec2) {
|
||||||
|
val color = this.color ?: ProtocolDefinition.DEFAULT_COLOR
|
||||||
|
|
||||||
fun drawLetterVertex(position: Vec3, uv: Vec2, atlasPage: Int) {
|
fun drawLetterVertex(position: Vec3, uv: Vec2, atlasPage: Int) {
|
||||||
val matrixPosition = perspectiveMatrix * Vec4(position.x, position.y, 0f, 1f)
|
val matrixPosition = perspectiveMatrix * Vec4(position.x, position.y, 0f, 1f)
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
package de.bixilon.minosoft.protocol.protocol;
|
package de.bixilon.minosoft.protocol.protocol;
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||||
|
import de.bixilon.minosoft.data.text.ChatColors;
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -98,6 +100,8 @@ public final class ProtocolDefinition {
|
|||||||
|
|
||||||
public static final ResourceLocation AIR_RESOURCE_LOCATION = new ResourceLocation("air");
|
public static final ResourceLocation AIR_RESOURCE_LOCATION = new ResourceLocation("air");
|
||||||
|
|
||||||
|
public static final RGBColor DEFAULT_COLOR = ChatColors.WHITE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// java does (why ever) not allow to directly assign a null
|
// java does (why ever) not allow to directly assign a null
|
||||||
InetAddress tempInetAddress;
|
InetAddress tempInetAddress;
|
||||||
|
@ -13,9 +13,12 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.util.logging;
|
package de.bixilon.minosoft.util.logging;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.Minosoft;
|
||||||
import de.bixilon.minosoft.config.StaticConfiguration;
|
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||||
|
import de.bixilon.minosoft.data.ChatTextPositions;
|
||||||
|
import de.bixilon.minosoft.data.text.BaseComponent;
|
||||||
import de.bixilon.minosoft.data.text.ChatColors;
|
import de.bixilon.minosoft.data.text.ChatColors;
|
||||||
import de.bixilon.minosoft.data.text.PostChatFormattingCodes;
|
import de.bixilon.minosoft.data.text.ChatComponent;
|
||||||
import de.bixilon.minosoft.data.text.RGBColor;
|
import de.bixilon.minosoft.data.text.RGBColor;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
@ -25,7 +28,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
public class Log {
|
public class Log {
|
||||||
public static final long MINOSOFT_START_TIME = System.currentTimeMillis();
|
public static final long MINOSOFT_START_TIME = System.currentTimeMillis();
|
||||||
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
private static final LinkedBlockingQueue<String> LOG_QUEUE = new LinkedBlockingQueue<>();
|
private static final LinkedBlockingQueue<ChatComponent> LOG_QUEUE = new LinkedBlockingQueue<>();
|
||||||
private static final PrintStream SYSTEM_ERR_STREAM = System.err;
|
private static final PrintStream SYSTEM_ERR_STREAM = System.err;
|
||||||
private static final PrintStream SYSTEM_OUT_STREAM = System.out;
|
private static final PrintStream SYSTEM_OUT_STREAM = System.out;
|
||||||
private static final PrintStream ERROR_PRINT_STREAM = new LogPrintStream(LogLevels.WARNING);
|
private static final PrintStream ERROR_PRINT_STREAM = new LogPrintStream(LogLevels.WARNING);
|
||||||
@ -38,15 +41,20 @@ public class Log {
|
|||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
while (true) {
|
while (true) {
|
||||||
// something to print
|
// something to print
|
||||||
String message;
|
ChatComponent message;
|
||||||
try {
|
try {
|
||||||
message = LOG_QUEUE.take();
|
message = LOG_QUEUE.take();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SYSTEM_OUT_STREAM.println(message);
|
SYSTEM_OUT_STREAM.println(message.getANSIColoredMessage());
|
||||||
|
|
||||||
|
if (StaticConfiguration.SHOW_LOG_MESSAGES_IN_CHAT) {
|
||||||
|
for (var connection : Minosoft.CONNECTIONS.values()) {
|
||||||
|
connection.getSender().sendFakeChatMessage(message, ChatTextPositions.CHAT_BOX);
|
||||||
|
}
|
||||||
|
}
|
||||||
// ToDo: log to file
|
// ToDo: log to file
|
||||||
}
|
}
|
||||||
}, "Log").start();
|
}, "Log").start();
|
||||||
@ -98,15 +106,13 @@ public class Log {
|
|||||||
builder.append(level.name());
|
builder.append(level.name());
|
||||||
builder.append("] ");
|
builder.append("] ");
|
||||||
builder.append(prefix);
|
builder.append(prefix);
|
||||||
|
var component = (BaseComponent) ChatComponent.valueOf(builder.toString());
|
||||||
|
var messageComponent = (BaseComponent) ChatComponent.valueOf(message);
|
||||||
if (color != null && StaticConfiguration.COLORED_LOG) {
|
if (color != null && StaticConfiguration.COLORED_LOG) {
|
||||||
builder.append(ChatColors.getANSIColorByRGBColor(color));
|
messageComponent.applyDefaultColor(color);
|
||||||
builder.append(message);
|
|
||||||
builder.append(PostChatFormattingCodes.RESET.getANSI());
|
|
||||||
} else {
|
|
||||||
builder.append(message);
|
|
||||||
}
|
}
|
||||||
builder.append(PostChatFormattingCodes.RESET.getANSI());
|
component.append(messageComponent);
|
||||||
LOG_QUEUE.add(builder.toString());
|
LOG_QUEUE.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user