mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 11:27:35 +01:00
79e2cb620e
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 376e37db SPIGOT-7677: Update which entities are marked as spawnable 06c4add3 SPIGOT-7737: Add separate TreeType.MEGA_PINE 19b7caaa SPIGOT-7731: Spawn eggs cannot have damage e585297e PR-1022: Add force option to Player#spawnParticle d26e0094 PR-1018: Add methods to get players seeing specific chunks 8df1ed18 PR-978: Add Material#isCompostable and Material#getCompostChance 4b9b59c7 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale 8d1e700a PR-1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks fa28607a PR-1016: Fix incorrect assumption of Fireball having constant speed 4c6c8586 PR-1015: Add a tool component to ItemMeta 6f6b2123 PR-1014: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects f511cfe1 PR-1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType def44cbf SPIGOT-7669: Fix typo in ProjectileHitEvent#getHitBlockFace documentation 53fa4f72 PR-1011: Throw an exception if a RecipeChoice is ever supplied air CraftBukkit Changes: ee95e171a SPIGOT-7737: Add separate TreeType.MEGA_PINE 0dae4c62c Fix spawn egg equality check and copy constructor ab59e847c Fix spawn eggs with no entity creating invalid stacks and disconnect creative clients 3b6093b28 SPIGOT-7736: Creative spawn egg use loses components c6b4d5a87 SPIGOT-7731: Spawn eggs cannot have damage 340ccd57f SPIGOT-7735: Fix serialization of player heads with note block sound fd2f41834 SPIGOT-7734: Can't register a custom advancement using unsafe() 02456e2a5 PR-1413: Add force option to Player#spawnParticle 6a61f38b2 SPIGOT-7680: Per-world weather command 58c41cebb PR-1409: Add methods to get players seeing specific chunks 16c976797 PR-1412: Fix shipwreck loot tables not being set for BlockTransformers 7189ba636 PR-1360: Add Material#isCompostable and Material#getCompostChance 900384556 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale bdb40c5f1 Increase outdated build delay d6607c7dd SPIGOT-7675: Fix FoodComponent config deserialization b148ed332 PR-1406: Fix incorrect assumption of Fireball having constant speed 3ec31ca75 PR-1405: Add a tool component to ItemMeta 5d7d675b9 PR-1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects 960827981 PR-1403, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType 94e44ec93 PR-1401: Add a config option to accept old keys in registry get calls a43701920 PR-1402: Fix ChunkSnapshot#isSectionEmpty() is always false 87d0a3368 SPIGOT-7668: Move NONE Registry updater to FieldRename to avoid some class loader issues 2ea1e7ac2 PR-1399: Fix regression preventing positive .setDamage value from causing knockback for 0 damage events ba2d49d21 Increase outdated build delay Spigot Changes: fcd94e21 Rebuild patches 342f4939 SPIGOT-7661: Add experimental unload-frozen-chunks option
701 lines
34 KiB
Diff
701 lines
34 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Minecrell <minecrell@minecrell.net>
|
|
Date: Fri, 9 Jun 2017 19:03:43 +0200
|
|
Subject: [PATCH] Use TerminalConsoleAppender for console improvements
|
|
|
|
Rewrite console improvements (console colors, tab completion,
|
|
persistent input line, ...) using JLine 3.x and TerminalConsoleAppender.
|
|
|
|
Also uses the new ANSIComponentSerializer to serialize components when
|
|
logging them via the ComponentLogger, or when sending messages to the
|
|
console, for hex color support.
|
|
|
|
New features:
|
|
- Support console colors for Vanilla commands
|
|
- Add console colors for warnings and errors
|
|
- Server can now be turned off safely using CTRL + C. JLine catches
|
|
the signal and the implementation shuts down the server cleanly.
|
|
- Support console colors and persistent input line when running in
|
|
IntelliJ IDEA
|
|
|
|
Other changes:
|
|
- Server starts 1-2 seconds faster thanks to optimizations in Log4j
|
|
configuration
|
|
|
|
Co-Authored-By: Emilia Kond <emilia@rymiel.space>
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index 18221614060ec945cb8b197acd276e45450f7394..90ca693814a82c30de238b0228750b769a9a9c80 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -5,9 +5,29 @@ plugins {
|
|
`maven-publish`
|
|
}
|
|
|
|
+val log4jPlugins = sourceSets.create("log4jPlugins")
|
|
+configurations.named(log4jPlugins.compileClasspathConfigurationName) {
|
|
+ extendsFrom(configurations.compileClasspath.get())
|
|
+}
|
|
+val alsoShade: Configuration by configurations.creating
|
|
+
|
|
dependencies {
|
|
implementation(project(":paper-api"))
|
|
- implementation("jline:jline:2.12.1")
|
|
+ // Paper start
|
|
+ implementation("org.jline:jline-terminal-jansi:3.21.0")
|
|
+ implementation("net.minecrell:terminalconsoleappender:1.3.0")
|
|
+ implementation("net.kyori:adventure-text-serializer-ansi:4.17.0") // Keep in sync with adventureVersion from Paper-API build file
|
|
+ /*
|
|
+ Required to add the missing Log4j2Plugins.dat file from log4j-core
|
|
+ which has been removed by Mojang. Without it, log4j has to classload
|
|
+ all its classes to check if they are plugins.
|
|
+ Scanning takes about 1-2 seconds so adding this speeds up the server start.
|
|
+ */
|
|
+ runtimeOnly("org.apache.logging.log4j:log4j-core:2.19.0")
|
|
+ log4jPlugins.annotationProcessorConfigurationName("org.apache.logging.log4j:log4j-core:2.19.0") // Paper - Needed to generate meta for our Log4j plugins
|
|
+ runtimeOnly(log4jPlugins.output)
|
|
+ alsoShade(log4jPlugins.output)
|
|
+ // Paper end
|
|
implementation("org.apache.logging.log4j:log4j-iostreams:2.22.1") // Paper - remove exclusion
|
|
implementation("org.ow2.asm:asm-commons:9.7")
|
|
implementation("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT") // Paper - config files
|
|
@@ -78,6 +98,19 @@ tasks.check {
|
|
dependsOn(scanJar)
|
|
}
|
|
// Paper end
|
|
+// Paper start - use TCA for console improvements
|
|
+tasks.serverJar {
|
|
+ from(alsoShade.elements.map {
|
|
+ it.map { f ->
|
|
+ if (f.asFile.isFile) {
|
|
+ zipTree(f.asFile)
|
|
+ } else {
|
|
+ f.asFile
|
|
+ }
|
|
+ }
|
|
+ })
|
|
+}
|
|
+// Paper end - use TCA for console improvements
|
|
|
|
tasks.test {
|
|
exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class")
|
|
diff --git a/src/log4jPlugins/java/io/papermc/paper/console/StripANSIConverter.java b/src/log4jPlugins/java/io/papermc/paper/console/StripANSIConverter.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..91547f6e6fe90006713beb2818da634304bdd236
|
|
--- /dev/null
|
|
+++ b/src/log4jPlugins/java/io/papermc/paper/console/StripANSIConverter.java
|
|
@@ -0,0 +1,51 @@
|
|
+package io.papermc.paper.console;
|
|
+
|
|
+import org.apache.logging.log4j.core.LogEvent;
|
|
+import org.apache.logging.log4j.core.config.Configuration;
|
|
+import org.apache.logging.log4j.core.config.plugins.Plugin;
|
|
+import org.apache.logging.log4j.core.layout.PatternLayout;
|
|
+import org.apache.logging.log4j.core.pattern.ConverterKeys;
|
|
+import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
|
|
+import org.apache.logging.log4j.core.pattern.PatternConverter;
|
|
+import org.apache.logging.log4j.core.pattern.PatternFormatter;
|
|
+import org.apache.logging.log4j.core.pattern.PatternParser;
|
|
+
|
|
+import java.util.List;
|
|
+import java.util.regex.Pattern;
|
|
+
|
|
+@Plugin(name = "stripAnsi", category = PatternConverter.CATEGORY)
|
|
+@ConverterKeys({"stripAnsi"})
|
|
+public final class StripANSIConverter extends LogEventPatternConverter {
|
|
+ final private Pattern ANSI_PATTERN = Pattern.compile("\\e\\[[\\d;]*[^\\d;]");
|
|
+
|
|
+ private final List<PatternFormatter> formatters;
|
|
+
|
|
+ private StripANSIConverter(List<PatternFormatter> formatters) {
|
|
+ super("stripAnsi", null);
|
|
+ this.formatters = formatters;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void format(LogEvent event, StringBuilder toAppendTo) {
|
|
+ int start = toAppendTo.length();
|
|
+ for (PatternFormatter formatter : formatters) {
|
|
+ formatter.format(event, toAppendTo);
|
|
+ }
|
|
+ String content = toAppendTo.substring(start);
|
|
+ content = ANSI_PATTERN.matcher(content).replaceAll("");
|
|
+
|
|
+ toAppendTo.setLength(start);
|
|
+ toAppendTo.append(content);
|
|
+ }
|
|
+
|
|
+ public static StripANSIConverter newInstance(Configuration config, String[] options) {
|
|
+ if (options.length != 1) {
|
|
+ LOGGER.error("Incorrect number of options on stripAnsi. Expected exactly 1, received " + options.length);
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ PatternParser parser = PatternLayout.createPatternParser(config);
|
|
+ List<PatternFormatter> formatters = parser.parse(options[0]);
|
|
+ return new StripANSIConverter(formatters);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a4070b59e261f0f1ac4beec47b11492f4724bf27
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
|
@@ -0,0 +1,41 @@
|
|
+package com.destroystokyo.paper.console;
|
|
+
|
|
+import net.minecraft.server.dedicated.DedicatedServer;
|
|
+import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
|
+import org.bukkit.craftbukkit.command.ConsoleCommandCompleter;
|
|
+import org.jline.reader.LineReader;
|
|
+import org.jline.reader.LineReaderBuilder;
|
|
+
|
|
+public final class PaperConsole extends SimpleTerminalConsole {
|
|
+
|
|
+ private final DedicatedServer server;
|
|
+
|
|
+ public PaperConsole(DedicatedServer server) {
|
|
+ this.server = server;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected LineReader buildReader(LineReaderBuilder builder) {
|
|
+ return super.buildReader(builder
|
|
+ .appName("Paper")
|
|
+ .variable(LineReader.HISTORY_FILE, java.nio.file.Paths.get(".console_history"))
|
|
+ .completer(new ConsoleCommandCompleter(this.server))
|
|
+ );
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected boolean isRunning() {
|
|
+ return !this.server.isStopped() && this.server.isRunning();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected void runCommand(String command) {
|
|
+ this.server.handleConsoleInput(command, this.server.createCommandSourceStack());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected void shutdown() {
|
|
+ this.server.halt(false);
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java b/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8f07539a82f449ad217e316a7513a1708781fb63
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java
|
|
@@ -0,0 +1,26 @@
|
|
+package com.destroystokyo.paper.console;
|
|
+
|
|
+import net.kyori.adventure.audience.MessageType;
|
|
+import net.kyori.adventure.identity.Identity;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
|
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
+import org.apache.logging.log4j.LogManager;
|
|
+import org.bukkit.craftbukkit.command.CraftConsoleCommandSender;
|
|
+
|
|
+public class TerminalConsoleCommandSender extends CraftConsoleCommandSender {
|
|
+
|
|
+ private static final ComponentLogger LOGGER = ComponentLogger.logger(LogManager.getRootLogger().getName());
|
|
+
|
|
+ @Override
|
|
+ public void sendRawMessage(String message) {
|
|
+ final Component msg = LegacyComponentSerializer.legacySection().deserialize(message);
|
|
+ this.sendMessage(Identity.nil(), msg, MessageType.SYSTEM);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void sendMessage(Identity identity, Component message, MessageType type) {
|
|
+ LOGGER.info(message);
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
index 7397918cf747bc2352bf5bb112a71e7f6844e0e0..0f9b744a977ec7ab8f138989b2336117b3de1412 100644
|
|
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
@@ -31,6 +31,7 @@ import net.kyori.adventure.text.flattener.ComponentFlattener;
|
|
import net.kyori.adventure.text.format.Style;
|
|
import net.kyori.adventure.text.format.TextColor;
|
|
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
|
+import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
|
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|
@@ -128,6 +129,7 @@ public final class PaperAdventure {
|
|
public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale"); // init after FLATTENER because classloading triggered here might create a logger
|
|
@Deprecated
|
|
public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
|
|
+ public static final ANSIComponentSerializer ANSI_SERIALIZER = ANSIComponentSerializer.builder().flattener(FLATTENER).build();
|
|
public static final Codec<Tag, String, CommandSyntaxException, RuntimeException> NBT_CODEC = new Codec<>() {
|
|
@Override
|
|
public @NotNull Tag decode(final @NotNull String encoded) throws CommandSyntaxException {
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java
|
|
index 8323f135d6bf2e1f12525e05094ffa3f2420e7e1..a143ea1e58464a3122fbd8ccafe417bdb3c31c78 100644
|
|
--- a/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java
|
|
@@ -1,9 +1,11 @@
|
|
package io.papermc.paper.adventure.providers;
|
|
|
|
import io.papermc.paper.adventure.PaperAdventure;
|
|
+import java.util.Locale;
|
|
import net.kyori.adventure.text.Component;
|
|
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
|
import net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider;
|
|
+import net.kyori.adventure.translation.GlobalTranslator;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@@ -15,6 +17,6 @@ public class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
|
|
}
|
|
|
|
private String serialize(final Component message) {
|
|
- return PaperAdventure.asPlain(message, null);
|
|
+ return PaperAdventure.ANSI_SERIALIZER.serialize(GlobalTranslator.render(message, Locale.getDefault()));
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 84ad6aae39b5fe4c4ad5ec08890d4383829cbe50..8dfa0fae4d5129688b7e2897da1fc51683aed6c3 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -148,7 +148,7 @@ import org.slf4j.Logger;
|
|
import com.mojang.serialization.Dynamic;
|
|
import com.mojang.serialization.Lifecycle;
|
|
import java.util.Random;
|
|
-import jline.console.ConsoleReader;
|
|
+// import jline.console.ConsoleReader; // Paper
|
|
import joptsimple.OptionSet;
|
|
import net.minecraft.nbt.NbtException;
|
|
import net.minecraft.nbt.ReportedNbtException;
|
|
@@ -289,7 +289,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public org.bukkit.craftbukkit.CraftServer server;
|
|
public OptionSet options;
|
|
public org.bukkit.command.ConsoleCommandSender console;
|
|
- public ConsoleReader reader;
|
|
public static int currentTick = (int) (System.currentTimeMillis() / 50);
|
|
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
|
|
public int autosavePeriod;
|
|
@@ -377,7 +376,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.options = options;
|
|
this.worldLoader = worldLoader;
|
|
this.vanillaCommandDispatcher = worldstem.dataPackResources().commands; // CraftBukkit
|
|
+ // Paper start - Handled by TerminalConsoleAppender
|
|
// Try to see if we're actually running in a terminal, disable jline if not
|
|
+ /*
|
|
if (System.console() == null && System.getProperty("jline.terminal") == null) {
|
|
System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
|
|
Main.useJline = false;
|
|
@@ -398,6 +399,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
MinecraftServer.LOGGER.warn((String) null, ex);
|
|
}
|
|
}
|
|
+ */
|
|
+ // Paper end
|
|
Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));
|
|
// CraftBukkit end
|
|
this.paperConfigurations = services.paperConfigurations(); // Paper - add paper configuration files
|
|
@@ -1113,7 +1116,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
org.spigotmc.WatchdogThread.doStop(); // Spigot
|
|
// CraftBukkit start - Restore terminal to original settings
|
|
try {
|
|
- this.reader.getTerminal().restore();
|
|
+ net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
|
|
} catch (Exception ignored) {
|
|
}
|
|
// CraftBukkit end
|
|
@@ -1636,7 +1639,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
@Override
|
|
public void sendSystemMessage(Component message) {
|
|
- MinecraftServer.LOGGER.info(message.getString());
|
|
+ MinecraftServer.LOGGER.info(io.papermc.paper.adventure.PaperAdventure.ANSI_SERIALIZER.serialize(io.papermc.paper.adventure.PaperAdventure.asAdventure(message))); // Paper - Log message with colors
|
|
}
|
|
|
|
public KeyPair getKeyPair() {
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 1b5e2e07a7723f61d4c4d4e3141c60b2f63e2b69..9249122da7282929f87613f41984b8085d7b53ec 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -108,6 +108,9 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
if (!org.bukkit.craftbukkit.Main.useConsole) {
|
|
return;
|
|
}
|
|
+ // Paper start - Use TerminalConsoleAppender
|
|
+ new com.destroystokyo.paper.console.PaperConsole(DedicatedServer.this).start();
|
|
+ /*
|
|
jline.console.ConsoleReader bufferedreader = DedicatedServer.this.reader;
|
|
|
|
// MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return
|
|
@@ -139,7 +142,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
continue;
|
|
}
|
|
if (s.trim().length() > 0) { // Trim to filter lines which are just spaces
|
|
- DedicatedServer.this.handleConsoleInput(s, DedicatedServer.this.createCommandSourceStack());
|
|
+ DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
|
|
}
|
|
// CraftBukkit end
|
|
}
|
|
@@ -147,6 +150,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
|
|
}
|
|
|
|
+ */
|
|
+ // Paper end
|
|
}
|
|
};
|
|
|
|
@@ -158,6 +163,9 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
}
|
|
global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
|
|
|
|
+ // Paper start - Not needed with TerminalConsoleAppender
|
|
+ final org.apache.logging.log4j.Logger logger = LogManager.getRootLogger();
|
|
+ /*
|
|
final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
|
|
for (org.apache.logging.log4j.core.Appender appender : logger.getAppenders().values()) {
|
|
if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender) {
|
|
@@ -168,6 +176,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
TerminalConsoleWriterThread writerThread = new TerminalConsoleWriterThread(System.out, this.reader);
|
|
this.reader.setCompletionHandler(new TerminalCompletionHandler(writerThread, this.reader.getCompletionHandler()));
|
|
writerThread.start();
|
|
+ */
|
|
+ // Paper end - Not needed with TerminalConsoleAppender
|
|
|
|
System.setOut(IoBuilder.forLogger(logger).setLevel(Level.INFO).buildPrintStream());
|
|
System.setErr(IoBuilder.forLogger(logger).setLevel(Level.WARN).buildPrintStream());
|
|
diff --git a/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java b/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java
|
|
index 3d92c61f7781221cfdc0324d11bd0088954e4a68..84a2c6c397604279ba821286f5c3c855e6041400 100644
|
|
--- a/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java
|
|
+++ b/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java
|
|
@@ -166,7 +166,7 @@ public class MinecraftServerGui extends JComponent {
|
|
this.finalizers.forEach(Runnable::run);
|
|
}
|
|
|
|
- private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]"); // CraftBukkit
|
|
+ private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\e\\[[\\d;]*[^\\d;]"); // CraftBukkit // Paper
|
|
public void print(JTextArea textArea, JScrollPane scrollPane, String message) {
|
|
if (!SwingUtilities.isEventDispatchThread()) {
|
|
SwingUtilities.invokeLater(() -> {
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 0ff094a90bf471ce57a3054c7701dc3d67742d9d..50f4b77c83854932050cc543c7c2deeae641794f 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -161,8 +161,7 @@ public abstract class PlayerList {
|
|
|
|
public PlayerList(MinecraftServer server, LayeredRegistryAccess<RegistryLayer> registryManager, PlayerDataStorage saveHandler, int maxPlayers) {
|
|
this.cserver = server.server = new CraftServer((DedicatedServer) server, this);
|
|
- server.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance();
|
|
- server.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(server.server));
|
|
+ server.console = new com.destroystokyo.paper.console.TerminalConsoleCommandSender(); // Paper
|
|
// CraftBukkit end
|
|
|
|
this.bans = new UserBanList(PlayerList.USERBANLIST_FILE);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index beff0bfe2502a17fd297524c51f96b33f889db93..749a4f1e8e46e0b072832056186d709a93df4b58 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -43,7 +43,7 @@ import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.stream.Collectors;
|
|
import javax.imageio.ImageIO;
|
|
-import jline.console.ConsoleReader;
|
|
+// import jline.console.ConsoleReader;
|
|
import net.minecraft.advancements.AdvancementHolder;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.commands.Commands;
|
|
@@ -1343,9 +1343,13 @@ public final class CraftServer implements Server {
|
|
return this.logger;
|
|
}
|
|
|
|
+ // Paper start - JLine update
|
|
+ /*
|
|
public ConsoleReader getReader() {
|
|
return this.console.reader;
|
|
}
|
|
+ */
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public PluginCommand getPluginCommand(String name) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
index 73c44f94aac069fa3ea9e82be6b95e77a2421c63..2ef6386ea4b95211e26c8759cae849cbe68e3f40 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
@@ -13,7 +13,6 @@ import java.util.logging.Logger;
|
|
import joptsimple.OptionParser;
|
|
import joptsimple.OptionSet;
|
|
import joptsimple.util.PathConverter;
|
|
-import org.fusesource.jansi.AnsiConsole;
|
|
|
|
public class Main {
|
|
public static boolean useJline = true;
|
|
@@ -207,6 +206,8 @@ public class Main {
|
|
}
|
|
|
|
try {
|
|
+ // Paper start - Handled by TerminalConsoleAppender
|
|
+ /*
|
|
// This trick bypasses Maven Shade's clever rewriting of our getProperty call when using String literals
|
|
String jline_UnsupportedTerminal = new String(new char[]{'j', 'l', 'i', 'n', 'e', '.', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd', 'T', 'e', 'r', 'm', 'i', 'n', 'a', 'l'});
|
|
String jline_terminal = new String(new char[]{'j', 'l', 'i', 'n', 'e', '.', 't', 'e', 'r', 'm', 'i', 'n', 'a', 'l'});
|
|
@@ -224,9 +225,18 @@ public class Main {
|
|
// This ensures the terminal literal will always match the jline implementation
|
|
System.setProperty(jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName());
|
|
}
|
|
+ */
|
|
+
|
|
+ if (options.has("nojline")) {
|
|
+ System.setProperty(net.minecrell.terminalconsole.TerminalConsoleAppender.JLINE_OVERRIDE_PROPERTY, "false");
|
|
+ useJline = false;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
if (options.has("noconsole")) {
|
|
Main.useConsole = false;
|
|
+ useJline = false; // Paper
|
|
+ System.setProperty(net.minecrell.terminalconsole.TerminalConsoleAppender.JLINE_OVERRIDE_PROPERTY, "false"); // Paper
|
|
}
|
|
|
|
if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
|
|
@@ -242,6 +252,7 @@ public class Main {
|
|
}
|
|
}
|
|
|
|
+ System.setProperty("library.jansi.version", "Paper"); // Paper - set meaningless jansi version to prevent git builds from crashing on Windows
|
|
System.out.println("Loading libraries, please wait...");
|
|
net.minecraft.server.Main.main(options);
|
|
} catch (Throwable t) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java b/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java
|
|
index bcf1c36d07b79520a39643d3a01020a67b1c9ef2..217e7e3b9db04c7fc5f6518f39cc9d3488f9128d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java
|
|
@@ -5,15 +5,13 @@ import java.util.EnumMap;
|
|
import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
-import jline.Terminal;
|
|
+//import jline.Terminal;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
-import org.fusesource.jansi.Ansi;
|
|
-import org.fusesource.jansi.Ansi.Attribute;
|
|
|
|
-public class ColouredConsoleSender extends CraftConsoleCommandSender {
|
|
+public class ColouredConsoleSender /*extends CraftConsoleCommandSender */{/* // Paper - disable
|
|
private final Terminal terminal;
|
|
private final Map<ChatColor, String> replacements = new EnumMap<ChatColor, String>(ChatColor.class);
|
|
private final ChatColor[] colors = ChatColor.values();
|
|
@@ -93,5 +91,5 @@ public class ColouredConsoleSender extends CraftConsoleCommandSender {
|
|
} else {
|
|
return new ColouredConsoleSender();
|
|
}
|
|
- }
|
|
+ }*/ // Paper
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java b/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java
|
|
index 0b4c62387c1093652ac15b64a8703249de4cf088..d24acf28f5ed023acc550bcf877e4b9800ec8c9f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java
|
|
@@ -4,50 +4,73 @@ import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.logging.Level;
|
|
-import jline.console.completer.Completer;
|
|
+import net.minecraft.server.dedicated.DedicatedServer;
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
import org.bukkit.craftbukkit.util.Waitable;
|
|
+
|
|
+// Paper start - JLine update
|
|
+import org.jline.reader.Candidate;
|
|
+import org.jline.reader.Completer;
|
|
+import org.jline.reader.LineReader;
|
|
+import org.jline.reader.ParsedLine;
|
|
+// Paper end
|
|
import org.bukkit.event.server.TabCompleteEvent;
|
|
|
|
public class ConsoleCommandCompleter implements Completer {
|
|
- private final CraftServer server;
|
|
+ private final DedicatedServer server; // Paper - CraftServer -> DedicatedServer
|
|
|
|
- public ConsoleCommandCompleter(CraftServer server) {
|
|
+ public ConsoleCommandCompleter(DedicatedServer server) { // Paper - CraftServer -> DedicatedServer
|
|
this.server = server;
|
|
}
|
|
|
|
+ // Paper start - Change method signature for JLine update
|
|
@Override
|
|
- public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
|
+ public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
|
+ final CraftServer server = this.server.server;
|
|
+ final String buffer = line.line();
|
|
+ // Paper end
|
|
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
|
@Override
|
|
protected List<String> evaluate() {
|
|
- List<String> offers = ConsoleCommandCompleter.this.server.getCommandMap().tabComplete(ConsoleCommandCompleter.this.server.getConsoleSender(), buffer);
|
|
+ List<String> offers = server.getCommandMap().tabComplete(server.getConsoleSender(), buffer); // Paper - Remove "this."
|
|
|
|
- TabCompleteEvent tabEvent = new TabCompleteEvent(ConsoleCommandCompleter.this.server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers);
|
|
- ConsoleCommandCompleter.this.server.getPluginManager().callEvent(tabEvent);
|
|
+ TabCompleteEvent tabEvent = new TabCompleteEvent(server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers); // Paper - Remove "this."
|
|
+ server.getPluginManager().callEvent(tabEvent); // Paper - Remove "this."
|
|
|
|
return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
|
|
}
|
|
};
|
|
- this.server.getServer().processQueue.add(waitable);
|
|
+ server.getServer().processQueue.add(waitable); // Paper - Remove "this."
|
|
try {
|
|
List<String> offers = waitable.get();
|
|
if (offers == null) {
|
|
- return cursor;
|
|
+ return; // Paper - Method returns void
|
|
+ }
|
|
+
|
|
+ // Paper start - JLine update
|
|
+ for (String completion : offers) {
|
|
+ if (completion.isEmpty()) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ candidates.add(new Candidate(completion));
|
|
}
|
|
- candidates.addAll(offers);
|
|
+ // Paper end
|
|
|
|
+ // Paper start - JLine handles cursor now
|
|
+ /*
|
|
final int lastSpace = buffer.lastIndexOf(' ');
|
|
if (lastSpace == -1) {
|
|
return cursor - buffer.length();
|
|
} else {
|
|
return cursor - (buffer.length() - lastSpace - 1);
|
|
}
|
|
+ */
|
|
+ // Paper end
|
|
} catch (ExecutionException e) {
|
|
- this.server.getLogger().log(Level.WARNING, "Unhandled exception when tab completing", e);
|
|
+ server.getLogger().log(Level.WARNING, "Unhandled exception when tab completing", e); // Paper - Remove "this."
|
|
} catch (InterruptedException e) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
- return cursor;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
index 8390f5b5b957b5435efece26507a89756d0a7b3c..c6e8441e299f477ddb22c1ce2618710763978f1a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
@@ -16,7 +16,7 @@ public class ServerShutdownThread extends Thread {
|
|
this.server.close();
|
|
} finally {
|
|
try {
|
|
- this.server.reader.getTerminal().restore();
|
|
+ net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
|
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/TerminalCompletionHandler.java b/src/main/java/org/bukkit/craftbukkit/util/TerminalCompletionHandler.java
|
|
index 7d1c0810181c51ffa64f9a23b251e05c789870b0..09804513265e6db0c1f3501355335551100a36a8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/TerminalCompletionHandler.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/TerminalCompletionHandler.java
|
|
@@ -4,14 +4,12 @@ import java.io.IOException;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
-import jline.console.ConsoleReader;
|
|
-import jline.console.completer.CompletionHandler;
|
|
|
|
/**
|
|
* SPIGOT-6705: Make sure we print the display line again on tab completion, so that the user does not get stuck on it
|
|
* e.g. The user needs to press y / n to continue
|
|
*/
|
|
-public class TerminalCompletionHandler implements CompletionHandler {
|
|
+public class TerminalCompletionHandler /* implements CompletionHandler */ { /* Paper - comment out whole class
|
|
|
|
private final TerminalConsoleWriterThread writerThread;
|
|
private final CompletionHandler delegate;
|
|
@@ -50,4 +48,5 @@ public class TerminalCompletionHandler implements CompletionHandler {
|
|
|
|
return result;
|
|
}
|
|
+*/ // Paper end - comment out whole class
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java b/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java
|
|
index 2e5101fca081548bb616bc5eaa0134698719b63a..6e4d50a4863d43a2d6a2d574350c74d0819df402 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleWriterThread.java
|
|
@@ -7,13 +7,9 @@ import java.util.Locale;
|
|
import java.util.ResourceBundle;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
-import jline.console.ConsoleReader;
|
|
-import jline.console.completer.CandidateListCompletionHandler;
|
|
import org.bukkit.craftbukkit.Main;
|
|
-import org.fusesource.jansi.Ansi;
|
|
-import org.fusesource.jansi.Ansi.Erase;
|
|
|
|
-public class TerminalConsoleWriterThread extends Thread {
|
|
+public class TerminalConsoleWriterThread /*extends Thread*/ {/* // Paper - Comment out entire class
|
|
private final ResourceBundle bundle = ResourceBundle.getBundle(CandidateListCompletionHandler.class.getName(), Locale.getDefault());
|
|
private final ConsoleReader reader;
|
|
private final OutputStream output;
|
|
@@ -70,4 +66,5 @@ public class TerminalConsoleWriterThread extends Thread {
|
|
void setCompletion(int completion) {
|
|
this.completion = completion;
|
|
}
|
|
+*/ // Paper - Comment out entire class
|
|
}
|
|
diff --git a/src/main/resources/log4j2.component.properties b/src/main/resources/log4j2.component.properties
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0694b21465fb9e4164e71862ff24b62241b191f2
|
|
--- /dev/null
|
|
+++ b/src/main/resources/log4j2.component.properties
|
|
@@ -0,0 +1 @@
|
|
+log4j.skipJansi=true
|
|
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
|
|
index 0ff3f750fb7f684c12080894cd8660f0455c658b..301874c1fe16c52ffa6228d79e6617d746e9a035 100644
|
|
--- a/src/main/resources/log4j2.xml
|
|
+++ b/src/main/resources/log4j2.xml
|
|
@@ -1,17 +1,14 @@
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<Configuration status="WARN">
|
|
<Appenders>
|
|
- <Console name="SysOut" target="SYSTEM_OUT">
|
|
- <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg{nolookups}%n" />
|
|
- </Console>
|
|
<Queue name="ServerGuiConsole">
|
|
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg{nolookups}%n" />
|
|
</Queue>
|
|
- <Queue name="TerminalConsole">
|
|
- <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg{nolookups}%n" />
|
|
- </Queue>
|
|
+ <TerminalConsole name="TerminalConsole">
|
|
+ <PatternLayout pattern="%highlightError{[%d{HH:mm:ss} %level]: %msg%n%xEx}" />
|
|
+ </TerminalConsole>
|
|
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
|
|
- <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg{nolookups}%n" />
|
|
+ <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %stripAnsi{%msg}%n" />
|
|
<Policies>
|
|
<TimeBasedTriggeringPolicy />
|
|
<OnStartupTriggeringPolicy />
|
|
@@ -24,10 +21,9 @@
|
|
<filters>
|
|
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" />
|
|
</filters>
|
|
- <AppenderRef ref="SysOut" level="info"/>
|
|
<AppenderRef ref="File"/>
|
|
- <AppenderRef ref="ServerGuiConsole" level="info"/>
|
|
<AppenderRef ref="TerminalConsole" level="info"/>
|
|
+ <AppenderRef ref="ServerGuiConsole" level="info"/>
|
|
</Root>
|
|
</Loggers>
|
|
</Configuration>
|