summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/IO.java
blob: 6d969badf265ee77fbdf076793ed93a1c31ddc8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 class IO {

    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();

    public static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText) {
        return message(context, messageText, false);
    }

    public static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) {
        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);
            }
        }
    }
}