Skip to content

Commit

Permalink
feat(api): ExceptionCommandExceptionType
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Jun 23, 2022
1 parent b5cb190 commit c348f18
Showing 1 changed file with 42 additions and 0 deletions.
@@ -0,0 +1,42 @@
package org.auioc.mcmod.arnicalib.api.game.command;

import java.util.function.Function;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.exceptions.CommandExceptionType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;


public class ExceptionCommandExceptionType implements CommandExceptionType {

private final Function<Exception, Message> messageBuilder;
private final Logger logger;
private final Marker marker;

public ExceptionCommandExceptionType(Function<Exception, Message> messageBuilder, Logger logger, Marker marker) {
this.messageBuilder = messageBuilder;
this.logger = logger;
this.marker = marker;
}

public ExceptionCommandExceptionType(Function<Exception, Message> messageBuilder) {
this(messageBuilder, null, null);
}

public CommandSyntaxException create(Exception e, String logMessage) {
if (this.logger != null) {
if (this.marker != null) {
this.logger.error(this.marker, logMessage, e);
} else {
this.logger.error(logMessage, e);
}
}
return new CommandSyntaxException(this, messageBuilder.apply(e));
}

public CommandSyntaxException create(Exception e) {
return create(e, "");
}

}

0 comments on commit c348f18

Please sign in to comment.