All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.craftbukkit.util.TerminalConsoleWriterThread Maven / Gradle / Ivy

package org.bukkit.craftbukkit.util;

import com.mojang.util.QueueLogAppender;
import jline.console.ConsoleReader;
import org.bukkit.craftbukkit.Main;

import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TerminalConsoleWriterThread implements Runnable {
  final private ConsoleReader reader;
  final private OutputStream output;

  public TerminalConsoleWriterThread(OutputStream output, ConsoleReader reader) {
    this.output = output;
    this.reader = reader;
  }

  public void run() {
    String message;

    // Using name from log4j config in vanilla jar
    while (true) {
      message = QueueLogAppender.getNextLogEvent("TerminalConsole");
      if (message == null) {
        continue;
      }

      try {
        if (Main.useJline) {
          reader.print(ConsoleReader.RESET_LINE + "");
          reader.flush();
          output.write(message.getBytes());
          output.flush();

          try {
            reader.drawLine();
          } catch (Throwable ex) {
            reader.getCursorBuffer().clear();
          }
          reader.flush();
        } else {
          output.write(message.getBytes());
          output.flush();
        }
      } catch (IOException ex) {
        Logger.getLogger(TerminalConsoleWriterThread.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy