diff options
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java index 8c8a687..4b93d17 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java @@ -3,27 +3,60 @@ package com.keuin.kbackupfabric.util; import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public final class PrintUtil { private static final Logger LOGGER = LogManager.getLogger(); + private static final boolean printDebugMessages = true; private static final boolean printErrorMessages = true; private static final boolean printInfoMessages = true; + private static final Object syncDebug = new Object(); private static final Object syncError = new Object(); private static final Object syncInfo = new Object(); private static final Object syncMessage = new Object(); - public static void message(CommandContext<ServerCommandSource> context, String messageText) { - message(context, messageText, false); + private static final Style infoStyle = new Style().setColor(Formatting.WHITE); + private static final Style debugStyle = new Style().setUnderline(true); + private static final Style warnStyle = new Style().setColor(Formatting.YELLOW); + private static final Style errorStyle = new Style().setColor(Formatting.DARK_RED); + + + public static CommandContext<ServerCommandSource> msgInfo(CommandContext<ServerCommandSource> context, String messageText) { + return msgInfo(context, messageText, false); + } + + public static CommandContext<ServerCommandSource> msgWarn(CommandContext<ServerCommandSource> context, String messageText) { + return msgWarn(context, messageText, false); + } + + public static CommandContext<ServerCommandSource> msgErr(CommandContext<ServerCommandSource> context, String messageText) { + return msgErr(context, messageText, false); + } + + public static CommandContext<ServerCommandSource> msgInfo(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) { + return message(context, messageText, broadcastToOps, infoStyle); + } + + public static CommandContext<ServerCommandSource> msgWarn(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) { + return message(context, messageText, broadcastToOps, warnStyle); + } + + public static CommandContext<ServerCommandSource> msgErr(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) { + return message(context, messageText, broadcastToOps, errorStyle); } - public static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) { + public static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps, Style style) { synchronized (syncMessage) { - context.getSource().sendFeedback(new LiteralText("[KBackup] " + messageText), broadcastToOps); + Text text = new LiteralText(messageText); + text.setStyle(style); + context.getSource().sendFeedback(text, broadcastToOps); } return context; } @@ -31,8 +64,8 @@ public final class PrintUtil { public static void debug(String message) { synchronized (syncDebug) { if (printDebugMessages) { - System.out.println(String.format("[DEBUG] [KBackup] %s", message)); - LOGGER.debug(message); + //System.out.println(String.format("[DBG] [KB] %s", message)); + LOGGER.debug("[KB][DEBUG] " + message); } } } @@ -40,8 +73,8 @@ public final class PrintUtil { public static void error(String message) { synchronized (syncError) { if (printErrorMessages) { - System.out.println(String.format("[ERROR] [KBackup] %s", message)); - LOGGER.error(message); + //System.out.println(String.format("[ERR] [KB] %s", message)); + LOGGER.error("[KB][ERROR]" + message); } } } @@ -49,8 +82,8 @@ public final class PrintUtil { public static void info(String message) { synchronized (syncInfo) { if (printInfoMessages) { - System.out.println(String.format("[INFO] [KBackup] %s", message)); - LOGGER.info(message); + //System.out.println(String.format("[INF] [KB] %s", message)); + LOGGER.info("[KB][INFO] " + message); } } } |