-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExceptionCommandExceptionType.java
42 lines (33 loc) · 1.36 KB
/
ExceptionCommandExceptionType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.auioc.mcmod.arnicalib.game.command.exception;
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, "");
}
}