net.forthecrown.grenadier.annotations.compiler.CommandCompilationException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grenadier-annotations Show documentation
Show all versions of grenadier-annotations Show documentation
Annotation-based command support for Grenadier
package net.forthecrown.grenadier.annotations.compiler;
import com.mojang.brigadier.StringReader;
import java.io.PrintStream;
import java.util.List;
import net.forthecrown.grenadier.annotations.compiler.CompileErrors.Error;
import net.forthecrown.grenadier.annotations.util.ErrorMessages;
import org.jetbrains.annotations.ApiStatus.Internal;
public class CommandCompilationException extends RuntimeException {
public CommandCompilationException(List errors,
StringReader reader,
String name
) {
super(createMessage(errors, reader, name));
}
public static void print(List errors, StringReader input, String name, PrintStream out) {
String message = createMessage(errors, input, name);
out.print(message);
out.print("\n");
}
@Internal
public static String createMessage(List errors, StringReader input, String name) {
StringBuilder builder = new StringBuilder();
builder.append("Errors/Warnings during compilation of command '")
.append(name)
.append("' (")
.append(errors.size())
.append(" total warnings/errors)");
for (var e: errors) {
String s = ErrorMessages.formatError(input, e.position(), e.message());
builder.append("\n\n");
if (e.type() == Error.TYPE_WARN) {
builder.append("Warning: ");
} else {
builder.append("Error: ");
}
builder.append(s);
}
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy