From 88ee197140ee5f89eb708af926186d596ff724ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Endre=C3=9F?= Date: Mon, 26 Apr 2021 17:34:34 +0200 Subject: [PATCH] Revert async logging fix (not needed) --- .../vcompat/utils/logging/BukkitLogger.java | 50 ++++--------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java b/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java index 694997f..da16286 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java +++ b/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java @@ -12,7 +12,6 @@ import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.Main; import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; @@ -22,10 +21,7 @@ import java.awt.Color; import java.io.IOException; import java.io.Writer; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.function.BiConsumer; public class BukkitLogger implements ILogger { @@ -41,8 +37,6 @@ private static ConsoleReader getReader() { private final boolean ansiSupported, jLine; - private final List queue = Collections.synchronizedList(new ArrayList<>()); - private final HashSet colorMessage = new HashSet<>(); private final LogTypeMap typeMap = new LogTypeMap(); private final Writer writer; @@ -56,8 +50,11 @@ private static ConsoleReader getReader() { private String format = "[%date%/%time%] [Server thread/%plugin% | %type%]: %message%"; public BukkitLogger(Plugin plugin) { - Bukkit.getScheduler().runTaskTimer(plugin, this::streamDequeue, 0, 12); - this.plugin = plugin.getName(); + this(plugin.getName()); + } + + public BukkitLogger(String plugin) { + this.plugin = plugin; this.reader = getReader(); this.writer = reader.getOutput(); this.colored = this.ansiSupported = reader.getTerminal().isAnsiSupported(); @@ -249,7 +246,7 @@ public BukkitLogger log(LogType type, String message) { return this; } - private BukkitLogger sendColored(LogType type, String format, String message) throws IOException { + public BukkitLogger sendColored(LogType type, String format, String message) throws IOException { boolean colorMessage = this.colorMessage.contains(type.getId()); String ansi; if (custom != null) { @@ -257,47 +254,20 @@ private BukkitLogger sendColored(LogType type, String format, String message) th custom.accept(true, format.replace("%type%", ansi + type.getName() + (color ? ANSI_RESET : "")).replace("%message%", (colorMessage ? ansi : "") + LoggingColors.format(message, color)) + (color ? ANSI_RESET : "")); } - return queueStream(format.replace("%type%", (ansi = type.asColorString(true)) + type.getName().toUpperCase() + ANSI_RESET) + return sendStream(format.replace("%type%", (ansi = type.asColorString(true)) + type.getName().toUpperCase() + ANSI_RESET) .replace("%message%", (colorMessage ? ansi : "") + LoggingColors.format(message, true)) + ANSI_RESET); } - private BukkitLogger sendUncolored(LogType type, String format, String message) throws IOException { + public BukkitLogger sendUncolored(LogType type, String format, String message) throws IOException { message = format.replace("%type%", type.getName().toUpperCase()).replace("%message%", LoggingColors.format(message, false)); if (custom != null) { custom.accept(true, message); } - return queueStream(message); - } - - private BukkitLogger queueStream(String message) throws IOException { - message += System.getProperty("line.separator"); - if (Bukkit.isPrimaryThread()) { - return sendStreamDequeue(message); - } - queue.add(message); - return this; - } - - private void streamDequeue() { - if (!queue.isEmpty()) { - String[] messages = queue.toArray(new String[queue.size()]); - queue.clear(); - for (String message : messages) { - try { - sendStream(message); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - - private BukkitLogger sendStreamDequeue(String message) throws IOException { - streamDequeue(); return sendStream(message); } - private BukkitLogger sendStream(String message) throws IOException { + public BukkitLogger sendStream(String message) throws IOException { + message += System.getProperty("line.separator"); if (jLine) { reader.flush(); writer.write("\b\b" + message);