From 720e8ec8eeb69d24afbb6b14068563cde2d470f0 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 23 Apr 2020 14:51:29 +0800 Subject: Version 1.1.0-dev: - Optimized backup lag (using async I/O). - Added twice confirmation /kb confirm and cancellation /kb cancel, to avoid mistake. - Added countdown before restoring. - Adjusted some text. - Code optimization. --- .../com/keuin/kbackupfabric/util/PrintUtil.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java (limited to 'src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java') diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java new file mode 100644 index 0000000..e76155f --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java @@ -0,0 +1,57 @@ +package com.keuin.kbackupfabric.util; + +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +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 CommandContext message(CommandContext context, String messageText) { + return message(context, messageText, false); + } + + public static CommandContext message(CommandContext context, String messageText, boolean broadcastToOps) { + synchronized (syncMessage) { + context.getSource().sendFeedback(new LiteralText("[KBackup] " + messageText), broadcastToOps); + } + return context; + } + + public static void debug(String message) { + synchronized (syncDebug) { + if (printDebugMessages) { + System.out.println(String.format("[DEBUG] [KBackup] %s", message)); + LOGGER.debug(message); + } + } + } + + public static void error(String message) { + synchronized (syncError) { + if (printErrorMessages) { + System.out.println(String.format("[ERROR] [KBackup] %s", message)); + LOGGER.error(message); + } + } + } + + public static void info(String message) { + synchronized (syncInfo) { + if (printInfoMessages) { + System.out.println(String.format("[INFO] [KBackup] %s", message)); + LOGGER.info(message); + } + } + } +} -- cgit v1.2.3