mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Update TerminalConsoleAppender to 1.1.0
Fixes a race condition when using TerminalConsoleAppender that may result in IllegalStateExceptions or duplicate input prompts.
This commit is contained in:
parent
bc063a06e8
commit
9cfd6ff449
3 changed files with 65 additions and 98 deletions
|
@ -5,7 +5,7 @@ Subject: [PATCH] Load version history at server start
|
|||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
index 854455711..39a3d46ff 100644
|
||||
index 18d32ab76..292291592 100644
|
||||
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||
|
|
|
@ -12,7 +12,7 @@ results in a separate line, even though it should not result in
|
|||
a line break. Log4j's implementation handles it correctly.
|
||||
|
||||
diff --git a/pom.xml b/pom.xml
|
||||
index 26775156b..adf79de70 100644
|
||||
index 22b86c74a..acc4bdfa4 100644
|
||||
--- a/pom.xml
|
||||
+++ b/pom.xml
|
||||
@@ -0,0 +0,0 @@
|
||||
|
@ -30,7 +30,7 @@ index 26775156b..adf79de70 100644
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
index b3f1aa999..854455711 100644
|
||||
index 895ea0aad..18d32ab76 100644
|
||||
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||
|
|
|
@ -15,12 +15,11 @@ New features:
|
|||
IntelliJ IDEA
|
||||
|
||||
Other changes:
|
||||
- Update JLine to 3.3.1 (from 2.12.1)
|
||||
- Server starts 1-2 seconds faster thanks to optimizations in Log4j
|
||||
configuration
|
||||
|
||||
diff --git a/pom.xml b/pom.xml
|
||||
index 9d273c6d9..26775156b 100644
|
||||
index 9d273c6d9..13fa95891 100644
|
||||
--- a/pom.xml
|
||||
+++ b/pom.xml
|
||||
@@ -0,0 +0,0 @@
|
||||
|
@ -44,12 +43,12 @@ index 9d273c6d9..26775156b 100644
|
|||
+ <dependency>
|
||||
+ <groupId>net.minecrell</groupId>
|
||||
+ <artifactId>terminalconsoleappender</artifactId>
|
||||
+ <version>1.0.0</version>
|
||||
+ <version>1.1.0</version>
|
||||
+ </dependency>
|
||||
+ <dependency>
|
||||
+ <groupId>net.java.dev.jna</groupId>
|
||||
+ <artifactId>jna</artifactId>
|
||||
+ <version>4.4.0</version>
|
||||
+ <version>4.5.2</version>
|
||||
+ <scope>runtime</scope>
|
||||
+ </dependency>
|
||||
+
|
||||
|
@ -88,6 +87,52 @@ index 9d273c6d9..26775156b 100644
|
|||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
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 000000000..116d1b3bf
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package com.destroystokyo.paper.console;
|
||||
+
|
||||
+import net.minecraft.server.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")
|
||||
+ .completer(new ConsoleCommandCompleter(this.server))
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected boolean isRunning() {
|
||||
+ return !this.server.isStopped() && this.server.isRunning();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected void runCommand(String command) {
|
||||
+ this.server.issueCommand(command, this.server);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected void shutdown() {
|
||||
+ this.server.safeShutdown();
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
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 000000000..685deaa0e
|
||||
|
@ -111,107 +156,29 @@ index 000000000..685deaa0e
|
|||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/console/TerminalHandler.java b/src/main/java/com/destroystokyo/paper/console/TerminalHandler.java
|
||||
new file mode 100644
|
||||
index 000000000..626bfeec8
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/console/TerminalHandler.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package com.destroystokyo.paper.console;
|
||||
+
|
||||
+import net.minecraft.server.DedicatedServer;
|
||||
+import net.minecrell.terminalconsole.TerminalConsoleAppender;
|
||||
+import org.bukkit.craftbukkit.command.ConsoleCommandCompleter;
|
||||
+import org.jline.reader.EndOfFileException;
|
||||
+import org.jline.reader.LineReader;
|
||||
+import org.jline.reader.LineReaderBuilder;
|
||||
+import org.jline.reader.UserInterruptException;
|
||||
+import org.jline.terminal.Terminal;
|
||||
+
|
||||
+public class TerminalHandler {
|
||||
+
|
||||
+ private TerminalHandler() {
|
||||
+ }
|
||||
+
|
||||
+ public static boolean handleCommands(DedicatedServer server) {
|
||||
+ final Terminal terminal = TerminalConsoleAppender.getTerminal();
|
||||
+ if (terminal == null) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ LineReader reader = LineReaderBuilder.builder()
|
||||
+ .appName("Paper")
|
||||
+ .terminal(terminal)
|
||||
+ .completer(new ConsoleCommandCompleter(server))
|
||||
+ .build();
|
||||
+ reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION);
|
||||
+ reader.unsetOpt(LineReader.Option.INSERT_TAB);
|
||||
+
|
||||
+ TerminalConsoleAppender.setReader(reader);
|
||||
+
|
||||
+ try {
|
||||
+ String line;
|
||||
+ while (!server.isStopped() && server.isRunning()) {
|
||||
+ try {
|
||||
+ line = reader.readLine("> ");
|
||||
+ } catch (EndOfFileException ignored) {
|
||||
+ // Continue reading after EOT
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (line == null) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ line = line.trim();
|
||||
+ if (!line.isEmpty()) {
|
||||
+ server.issueCommand(line, server);
|
||||
+ }
|
||||
+ }
|
||||
+ } catch (UserInterruptException e) {
|
||||
+ server.safeShutdown();
|
||||
+ } finally {
|
||||
+ TerminalConsoleAppender.setReader(null);
|
||||
+ }
|
||||
+
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
index 8f2afcc32..b3f1aa999 100644
|
||||
index 8f2afcc32..895ea0aad 100644
|
||||
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||
if (!org.bukkit.craftbukkit.Main.useConsole) {
|
||||
return;
|
||||
}
|
||||
- jline.console.ConsoleReader bufferedreader = reader;
|
||||
+ // Paper start - Use TerminalConsoleAppender implementation
|
||||
+ if (com.destroystokyo.paper.console.TerminalHandler.handleCommands(DedicatedServer.this)) return;
|
||||
+ BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
|
||||
+ // Paper end
|
||||
+ // Paper start - Use TerminalConsoleAppender
|
||||
+ new com.destroystokyo.paper.console.PaperConsole(DedicatedServer.this).start();
|
||||
+ /*
|
||||
jline.console.ConsoleReader bufferedreader = reader;
|
||||
// CraftBukkit end
|
||||
|
||||
String s;
|
||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||
try {
|
||||
// CraftBukkit start - JLine disabling compatibility
|
||||
while (!isStopped() && isRunning()) {
|
||||
+ // Paper start - code is not used for jline
|
||||
+ /*
|
||||
if (org.bukkit.craftbukkit.Main.useJline) {
|
||||
s = bufferedreader.readLine(">", null);
|
||||
} else {
|
||||
s = bufferedreader.readLine();
|
||||
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
|
||||
}
|
||||
|
||||
+ */
|
||||
+ s = bufferedreader.readLine();
|
||||
+ // Paper end
|
||||
+
|
||||
if (s != null && s.trim().length() > 0) { // Trim to filter lines which are just spaces
|
||||
issueCommand(s, DedicatedServer.this);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||
}
|
||||
global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
|
||||
|
|
Loading…
Reference in a new issue