Skip to content

Commit

Permalink
error message shouldn't be suppressed by #ikwid
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlyhj committed Dec 28, 2020
1 parent f0b3922 commit 64f03a2
Showing 1 changed file with 17 additions and 11 deletions.
Expand Up @@ -13,7 +13,7 @@ public class MTLogger implements ILogger {

private final List<ILogger> loggers = new ArrayList<>();
private final List<IPlayer> players = new ArrayList<>();
private final List<String> unprocessed = new ArrayList<>();
private final List<ErrorMessage> unprocessed = new ArrayList<>();
private boolean isDefaultDisabled = false;

public void addLogger(ILogger logger) {
Expand All @@ -27,9 +27,9 @@ public void removeLogger(ILogger logger) {
public void addPlayer(IPlayer player) {
players.add(player);
if(!unprocessed.isEmpty()) {
if(!CraftTweakerAPI.noWarn) {
unprocessed.forEach(player::sendChat);
}
unprocessed.stream()
.filter(errorMessage -> !(CraftTweakerAPI.noWarn && errorMessage.isWarning))
.forEach(errorMessage -> player.sendChat(errorMessage.message));
}
}

Expand Down Expand Up @@ -63,7 +63,7 @@ public void logWarning(String message) {

String message2 = "WARNING: " + message;
if(players.isEmpty()) {
unprocessed.add(message2);
unprocessed.add(new ErrorMessage(message2, true));
} else {
if(!CraftTweakerAPI.noWarn) {
for(IPlayer player : players) {
Expand All @@ -86,13 +86,9 @@ public void logError(String message, Throwable exception) {

String message2 = "ERROR: " + message;
if(players.isEmpty()) {
unprocessed.add(message2);
unprocessed.add(new ErrorMessage(message2, false));
} else {
if(!CraftTweakerAPI.noWarn) {
for(IPlayer player : players) {
player.sendChat(message2);
}
}
players.forEach(player -> player.sendChat(message2));
}
}

Expand All @@ -116,4 +112,14 @@ public boolean isLogDisabled() {
public void setLogDisabled(boolean logDisabled) {
this.isDefaultDisabled = logDisabled;
}

private static class ErrorMessage {
final String message;
final boolean isWarning;

public ErrorMessage(String message, boolean isWarning) {
this.message = message;
this.isWarning = isWarning;
}
}
}

0 comments on commit 64f03a2

Please sign in to comment.