Move logToChat to IMcClientWrapper
This commit is contained in:
@@ -100,6 +100,10 @@ public class ClientApi
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
private ClientApi()
|
||||
{
|
||||
|
||||
@@ -107,43 +111,6 @@ public class ClientApi
|
||||
|
||||
|
||||
|
||||
|
||||
public static void logToChat(Level logLevel, String str)
|
||||
{
|
||||
String prefix = "[" + ModInfo.READABLE_NAME + "] ";
|
||||
if (logLevel == Level.ERROR)
|
||||
{
|
||||
prefix += "\u00A74";
|
||||
}
|
||||
else if (logLevel == Level.WARN)
|
||||
{
|
||||
prefix += "\u00A76";
|
||||
}
|
||||
else if (logLevel == Level.INFO)
|
||||
{
|
||||
prefix += "\u00A7f";
|
||||
}
|
||||
else if (logLevel == Level.DEBUG)
|
||||
{
|
||||
prefix += "\u00A77";
|
||||
}
|
||||
else if (logLevel == Level.TRACE)
|
||||
{
|
||||
prefix += "\u00A78";
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix += "\u00A7f";
|
||||
}
|
||||
prefix += "\u00A7l\u00A7u";
|
||||
prefix += logLevel.name();
|
||||
prefix += ":\u00A7r ";
|
||||
if (MC != null)
|
||||
MC.sendChatMessage(prefix + str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//========//
|
||||
// events //
|
||||
//========//
|
||||
|
||||
@@ -21,6 +21,8 @@ package com.seibel.lod.core.logging;
|
||||
|
||||
import com.seibel.lod.core.api.internal.a7.ClientApi;
|
||||
import com.seibel.lod.core.enums.config.ELoggerMode;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
@@ -33,6 +35,9 @@ import java.util.function.Supplier;
|
||||
|
||||
public class ConfigBasedLogger
|
||||
{
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
|
||||
public static final List<WeakReference<ConfigBasedLogger>> loggers
|
||||
= Collections.synchronizedList(new LinkedList<WeakReference<ConfigBasedLogger>>());
|
||||
|
||||
@@ -100,10 +105,10 @@ public class ConfigBasedLogger
|
||||
if (mode.levelForChat.isLessSpecificThan(level))
|
||||
{
|
||||
if (param.length > 0 && param[param.length - 1] instanceof Throwable)
|
||||
ClientApi.logToChat(level, msgStr + "\n" +
|
||||
MC.logToChat(level, msgStr + "\n" +
|
||||
_throwableToDetailString(((Throwable) param[param.length - 1])));
|
||||
else
|
||||
ClientApi.logToChat(level, msgStr);
|
||||
MC.logToChat(level, msgStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ package com.seibel.lod.core.logging;
|
||||
|
||||
import com.seibel.lod.core.api.internal.a7.ClientApi;
|
||||
import com.seibel.lod.core.enums.config.ELoggerMode;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
@@ -34,6 +36,8 @@ import java.util.function.Supplier;
|
||||
|
||||
public class ConfigBasedSpamLogger
|
||||
{
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
|
||||
public static final List<WeakReference<ConfigBasedSpamLogger>> loggers
|
||||
= Collections.synchronizedList(new LinkedList<WeakReference<ConfigBasedSpamLogger>>());
|
||||
|
||||
@@ -113,10 +117,10 @@ public class ConfigBasedSpamLogger
|
||||
if (mode.levelForChat.isLessSpecificThan(level))
|
||||
{
|
||||
if (param.length > 0 && param[param.length - 1] instanceof Throwable)
|
||||
ClientApi.logToChat(level, msgStr + "\n" +
|
||||
MC.logToChat(level, msgStr + "\n" +
|
||||
_throwableToDetailString(((Throwable) param[param.length - 1])));
|
||||
else
|
||||
ClientApi.logToChat(level, msgStr);
|
||||
MC.logToChat(level, msgStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,10 +172,10 @@ public class ConfigBasedSpamLogger
|
||||
if (mode.levelForChat.isLessSpecificThan(level))
|
||||
{
|
||||
if (param.length > 0 && param[param.length - 1] instanceof Throwable)
|
||||
ClientApi.logToChat(level, msgStr + "\n" +
|
||||
MC.logToChat(level, msgStr + "\n" +
|
||||
_throwableToDetailString(((Throwable) param[param.length - 1])));
|
||||
else
|
||||
ClientApi.logToChat(level, msgStr);
|
||||
MC.logToChat(level, msgStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+39
-1
@@ -22,18 +22,20 @@ package com.seibel.lod.core.wrapperInterfaces.minecraft;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.enums.ELodDirection;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.IBindable;
|
||||
import com.seibel.lod.core.objects.DHBlockPos;
|
||||
import com.seibel.lod.core.objects.DHChunkPos;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
/**
|
||||
* Contains everything related to the Minecraft object.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 3-5-2022
|
||||
* @version 2022-8-20
|
||||
*/
|
||||
public interface IMinecraftClientWrapper extends IBindable
|
||||
{
|
||||
@@ -85,6 +87,41 @@ public interface IMinecraftClientWrapper extends IBindable
|
||||
|
||||
void sendChatMessage(String string);
|
||||
|
||||
/** Sends the given message to chat with a formatted prefix and color based on the log level. */
|
||||
default void logToChat(Level logLevel, String message)
|
||||
{
|
||||
String prefix = "[" + ModInfo.READABLE_NAME + "] ";
|
||||
if (logLevel == Level.ERROR)
|
||||
{
|
||||
prefix += "\u00A74";
|
||||
}
|
||||
else if (logLevel == Level.WARN)
|
||||
{
|
||||
prefix += "\u00A76";
|
||||
}
|
||||
else if (logLevel == Level.INFO)
|
||||
{
|
||||
prefix += "\u00A7f";
|
||||
}
|
||||
else if (logLevel == Level.DEBUG)
|
||||
{
|
||||
prefix += "\u00A77";
|
||||
}
|
||||
else if (logLevel == Level.TRACE)
|
||||
{
|
||||
prefix += "\u00A78";
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix += "\u00A7f";
|
||||
}
|
||||
prefix += "\u00A7l\u00A7u";
|
||||
prefix += logLevel.name();
|
||||
prefix += ":\u00A7r ";
|
||||
|
||||
this.sendChatMessage(prefix + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes Minecraft, displaying the given errorMessage <br> <br>
|
||||
* In the following format: <br>
|
||||
@@ -96,4 +133,5 @@ public interface IMinecraftClientWrapper extends IBindable
|
||||
void crashMinecraft(String errorMessage, Throwable exception);
|
||||
|
||||
Object getOptionsObject();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user