Merge remote-tracking branch 'origin/main'

This commit is contained in:
FlorianMichael 2023-09-24 16:22:37 +02:00
commit e4cce0fa0c
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 10 additions and 4 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));
}
}

View File

@ -43,8 +43,8 @@ public abstract class FileSaver {
public void init() {
if (file.exists()) {
JsonObject parentNode = null;
try {
parentNode = ViaFabricPlus.GSON.fromJson(new FileReader(file), JsonObject.class).getAsJsonObject();
try (final FileReader fr = new FileReader(file)) {
parentNode = ViaFabricPlus.GSON.fromJson(fr, JsonObject.class);
} catch (Exception e) {
e.printStackTrace();
}