Updated to 1.11.2 API version

Does not mean the added functions are implemented in the prior versions, but it means they all compile against the same API and ZS version
This commit is contained in:
kindlich committed 2019-10-20 18:00:11 +02:00
1 parent 0f74091da5
commit 1c0344a25b
140 files changed
+6307 -6387

No files matched your search

@@ -1,85 +1,83 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package minetweaker.api.logger;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import minetweaker.runtime.ILogger;
import java.io.*;
import java.util.regex.Pattern;
/**
*
* @author Stan Hebben
*/
public class FileLogger implements ILogger {
private final Writer writer;
private final PrintWriter printWriter;
public FileLogger(File output) {
try {
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
printWriter = new PrintWriter(writer);
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException("What the heck?");
} catch (FileNotFoundException ex) {
throw new RuntimeException("Could not open log file " + output);
}
}
private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
private final Writer writer;
private final PrintWriter printWriter;
@Override
public void logCommand(String message) {
try {
writer.write(message + "\n");
writer.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public FileLogger(File output) {
try {
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
printWriter = new PrintWriter(writer);
} catch(UnsupportedEncodingException ex) {
throw new RuntimeException("What the heck?");
} catch(FileNotFoundException ex) {
throw new RuntimeException("Could not open log file " + output);
}
}
@Override
public void logInfo(String message) {
try {
writer.write("INFO: " + message + "\n");
writer.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logCommand(String message) {
try {
writer.write(stripMessage(message) + "\n");
writer.flush();
} catch(IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logWarning(String message) {
try {
writer.write("WARNING: " + message + "\n");
writer.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logInfo(String message) {
try {
writer.write("INFO: " + stripMessage(message) + "\n");
writer.flush();
} catch(IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logError(String message) {
logError(message, null);
}
@Override
public void logWarning(String message) {
try {
writer.write("WARNING: " + stripMessage(message) + "\n");
writer.flush();
} catch(IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logError(String message, Throwable exception) {
try {
writer.write("ERROR: " + message + "\n");
if (exception != null) {
exception.printStackTrace(printWriter);
}
writer.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public void logError(String message) {
logError(message, null);
}
@Override
public void logError(String message, Throwable exception) {
try {
writer.write("ERROR: " + stripMessage(message) + "\n");
if(exception != null) {
exception.printStackTrace(printWriter);
}
writer.flush();
} catch(IOException ex) {
throw new RuntimeException(ex);
}
}
/**
* Returns a copy of the given string, with formatting codes stripped away.
*/
public String stripMessage(String message) {
return message == null ? null : FORMATTING_CODE_PATTERN.matcher(message).replaceAll("");
}
}