chat stuff (#251)

This commit is contained in:
RacoonDog 2023-09-24 09:11:31 -04:00 committed by GitHub
parent 62aea682c7
commit c6cb3c0ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.util.ChatUtil;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.raphimc.vialoader.netty.ViaDecoder;
@ -41,7 +42,7 @@ public class ViaFabricPlusViaDecoder extends ViaDecoder {
} catch (Throwable t) {
ViaFabricPlus.LOGGER.error("Error occurred while decoding packet in ViaDecoder", t);
if (mode == 1) {
ChatUtil.sendPrefixedMessage(Formatting.RED + "An error occurred while decoding a packet! See more details in the logs!");
ChatUtil.sendPrefixedMessage(Text.literal("An error occurred while decoding a packet! See more details in the logs!").formatted(Formatting.RED));
}
}
return;

View File

@ -23,16 +23,21 @@ import net.minecraft.util.Formatting;
public class ChatUtil {
public final static String PREFIX = Formatting.WHITE + "[" + Formatting.GOLD + "ViaFabricPlus" + Formatting.WHITE + "]";
public final static Text PREFIX_TEXT = Text.literal("[").formatted(Formatting.WHITE).append(Text.literal("ViaFabricPlus").formatted(Formatting.GOLD)).append("]");
public static Text prefixText(final String message) {
return prefixText(Text.literal(message));
}
public static Text prefixText(final Text message) {
return Text.literal("").append(PREFIX).append(" " + message.getString());
return Text.empty().append(PREFIX_TEXT).append(" ").append(message);
}
public static void sendPrefixedMessage(final String message) {
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(prefixText(message));
}
public static void sendPrefixedMessage(final Text message) {
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(prefixText(message));
}
}