diff --git a/src/main/java/com/cleanroommc/groovyscript/api/GroovyLog.java b/src/main/java/com/cleanroommc/groovyscript/api/GroovyLog.java index 9c932c2c9..7e01f6b4c 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/GroovyLog.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/GroovyLog.java @@ -14,7 +14,7 @@ import java.util.function.Supplier; /** - * A interface for the GroovyScript logger. The log is separate to Minecraft's normal and debug log. + * An interface for the GroovyScript logger. The log is separate to Minecraft's normal and debug log. * The generated log file can be found at "[Minecraft instance]/groovy.log". * All logging methods format its content similarly to how C does it. * Curly braces in the msg parameter get replaced with the given arguments. @@ -269,6 +269,19 @@ interface Msg { */ Msg add(boolean condition, String msg, Object... args); + /** + * Adds a sub message to this message with exactly one parameter, but only if the given condition is true. The arg {@link Supplier} + * is invoked if the condition is true. + * + * @param condition sub message will only be added if this is true + * @param msg sub message + * @param arg sub message argument + * @return this + */ + default Msg add(boolean condition, String msg, Supplier arg) { + return add(condition, msg, (Object) arg); + } + /** * Adds a sub message to this message, but only if the given condition is true. * For convenience. @@ -290,8 +303,8 @@ interface Msg { Msg add(boolean condition, Consumer msgBuilder); /** - * Adds an exception to the message. The exception will always be logged at last. - * The exception counts as a sub message. This message can only have one message at a time. + * Adds an exception to the message. The exception will always be logged at last. The exception counts as a sub message. This + * message can only have one message at a time. * * @param throwable exception. * @return this diff --git a/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/MetaClassImplMixin.java b/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/MetaClassImplMixin.java index 4d0aed9f9..6e68b12c7 100644 --- a/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/MetaClassImplMixin.java +++ b/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/MetaClassImplMixin.java @@ -22,9 +22,6 @@ public abstract class MetaClassImplMixin { @Shadow protected abstract Object doInvokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass); - @Shadow - protected MetaClassRegistry registry; - @Shadow protected abstract Object invokeMissingMethod(Object instance, String methodName, Object[] arguments, RuntimeException original, boolean isCallToSuper); @@ -47,6 +44,8 @@ public abstract class MetaClassImplMixin { @Final private MetaMethod[] additionalMetaMethods; + @Shadow protected MetaClassRegistry registry; + @Inject(method = "(Ljava/lang/Class;[Lgroovy/lang/MetaMethod;)V", at = @At("TAIL")) public void removeBlacklistedAdditional(Class theClass, MetaMethod[] add, CallbackInfo ci) { if (additionalMetaMethods.length > 0) { diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyLogImpl.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyLogImpl.java index dce75d6cc..df3484b3e 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyLogImpl.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyLogImpl.java @@ -138,7 +138,7 @@ public Path getPath() { } /** - * Logs a info msg to the groovy log AND Minecraft's log + * Logs an info msg to the groovy log AND Minecraft's log * * @param msg message * @param args arguments @@ -347,6 +347,13 @@ public Msg add(String msg, Object... data) { @Override public Msg add(boolean condition, String msg, Object... args) { if (condition) { + if (args != null && args.length > 0) { + for (int i = 0; i < args.length; i++) { + if (args[i] instanceof Supplier s) { + args[i] = s.get(); + } + } + } return add(msg, args); } return this;