Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): ExceptionCommandExceptionType
- Loading branch information
1 parent
b5cb190
commit c348f18
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/auioc/mcmod/arnicalib/api/game/command/ExceptionCommandExceptionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, ""); | ||
} | ||
|
||
} |