mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-25 22:34:35 +00:00
- Refactoring towards MineTweakerMC calls - Added IC2 matter amplifier support
123 lines
2.5 KiB
Java
123 lines
2.5 KiB
Java
/*
|
|
* 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.mc172;
|
|
|
|
import java.io.BufferedOutputStream;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.OutputStreamWriter;
|
|
import java.io.Writer;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import minetweaker.runtime.ILogger;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.util.ChatComponentText;
|
|
|
|
/**
|
|
*
|
|
* @author Stan
|
|
*/
|
|
public class MineTweakerLogger implements ILogger {
|
|
private Writer writer;
|
|
private List<String> unreportedErrors;
|
|
private List<EntityPlayer> players;
|
|
|
|
public MineTweakerLogger() {
|
|
File logFile = new File("minetweaker.log");
|
|
if (logFile.exists()) logFile.delete();
|
|
|
|
unreportedErrors = new ArrayList<String>();
|
|
players = new ArrayList<EntityPlayer>();
|
|
|
|
try {
|
|
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(logFile)));
|
|
} catch (IOException ex) {
|
|
|
|
}
|
|
}
|
|
|
|
public void clear() {
|
|
unreportedErrors.clear();
|
|
}
|
|
|
|
public void addPlayer(EntityPlayer player) {
|
|
players.add(player);
|
|
|
|
if (!unreportedErrors.isEmpty()) {
|
|
for (String error : unreportedErrors) {
|
|
player.addChatMessage(new ChatComponentText(error));
|
|
}
|
|
|
|
unreportedErrors.clear();
|
|
}
|
|
}
|
|
|
|
public void removePlayer(EntityPlayer player) {
|
|
players.remove(player);
|
|
}
|
|
|
|
@Override
|
|
public void logCommand(String message) {
|
|
try {
|
|
writer.append("COMMAND: ");
|
|
writer.append(message);
|
|
writer.append('\n');
|
|
writer.flush();
|
|
} catch (IOException ex) {
|
|
|
|
}
|
|
|
|
System.out.println("COMMAND: " + message);
|
|
}
|
|
|
|
@Override
|
|
public void logInfo(String message) {
|
|
try {
|
|
writer.append("INFO: ");
|
|
writer.append(message);
|
|
writer.append('\n');
|
|
writer.flush();
|
|
} catch (IOException ex) {
|
|
|
|
}
|
|
|
|
System.out.println("INFO: " + message);
|
|
}
|
|
|
|
@Override
|
|
public void logWarning(String message) {
|
|
report("WARNING: " + message);
|
|
}
|
|
|
|
@Override
|
|
public void logError(String message) {
|
|
report("ERROR: " + message);
|
|
}
|
|
|
|
private void report(String message) {
|
|
try {
|
|
writer.append(message);
|
|
writer.append('\n');
|
|
writer.flush();
|
|
} catch (IOException ex) {
|
|
|
|
}
|
|
|
|
System.out.println(message);
|
|
|
|
if (players.isEmpty()) {
|
|
unreportedErrors.add(message);
|
|
} else {
|
|
ChatComponentText text = new ChatComponentText(message);
|
|
for (EntityPlayer player : players) {
|
|
player.addChatMessage(text);
|
|
}
|
|
}
|
|
}
|
|
}
|