61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
/*
|
|
*
|
|
* ChatUtil
|
|
*
|
|
* Helpful utility for pretty printing in chat in the game with different supported functions and levels
|
|
*
|
|
*/
|
|
|
|
package jesse.keeblarcraft.Utils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.text.Text;
|
|
|
|
public class ChatUtil {
|
|
|
|
private static class ConsoleColor {
|
|
public static String getColor(CONSOLE_COLOR color) {
|
|
String ret = "";
|
|
switch(color) {
|
|
case CONSOLE_COLOR.RED:
|
|
ret = "31";
|
|
break;
|
|
case CONSOLE_COLOR.BLUE:
|
|
ret = "34";
|
|
break;
|
|
case CONSOLE_COLOR.GREEN:
|
|
ret = "32";
|
|
break;
|
|
case CONSOLE_COLOR.CYAN:
|
|
ret = "36";
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
public static enum CONSOLE_COLOR {
|
|
RED,
|
|
BLUE,
|
|
GREEN,
|
|
CYAN;
|
|
}
|
|
|
|
// Helpful print wrapper function
|
|
static public void SendPlayerMsg(ServerPlayerEntity player, String text) {
|
|
player.sendMessage(Text.literal(text));
|
|
}
|
|
|
|
// Returns a string with the proper ANSI encoding for the specified CONSOLE_COLOR
|
|
static public String ColoredString(String msg, CONSOLE_COLOR color) {
|
|
return "\033[" + ConsoleColor.getColor(color) + "m" + msg + "\033[0m";
|
|
}
|
|
|
|
// Takes in a (already initialized) logger object and prints to console
|
|
static public void LoggerColored(String msg, CONSOLE_COLOR color, Logger logger) {
|
|
logger.info(ColoredString(msg, color));
|
|
}
|
|
}
|